Module Ymir_fits.Fits
Values
Headers
HDUs and files
type hduThe type for HDUs: a header and the bytes of its data unit.
read path is the HDUs of the file path, primary first: every header copied, every data unit checked to lie inside the file, no data read. A file's structure fails here alone: a file cut inside a data unit, or inside a header of an HDU that starts XTENSION, is an Error naming that HDU. A file that ends inside its last data unit's padding reads, as do bytes after the last HDU that do not start XTENSION. A gzip stream is an Error naming Lz.Gzip.
val of_bytes :
name:string ->
(int, Nx.int8_unsigned_elt, Nx.host) Nx.t ->
(hdu list, string) Stdlib.resultof_bytes ~name b is the HDUs of the bytes b in C order, as read reads a file. name starts their errors.
get ~ver name hdus is the HDU whose EXTNAME is name and whose EXTVER is ver, an absent EXTVER being 1. Without ver, it is the one HDU named name. Error listing the HDUs' names if there is none, or several.
val data : hdu -> (int, Nx.int8_unsigned_elt, Nx.host) Nx.tdata hdu is hdu's data unit as stored, heap included, padding excluded: for a read HDU, a view of the file, which must not change while the view lives.
digest hdu is blake2b-256:<hex> of every header of hdu's file, each as Header.to_string gives it, in file order; of hdu's header for a constructed one. Headers state each HDU's sizes and, in files this library writes, DATASUM, so they identify the data; two files with equal headers and different data without DATASUM share a digest.
v h b is the HDU of any kind with header h and data unit b, as write writes it after the first HDU: DATASUM and CHECKSUM go, and a primary image becomes an IMAGE extension.
Raises Invalid_argument if h's mandatory keywords do not read, or describe a data unit of another size than b's.
with_header h hdu is hdu with h's records, except the structural ones (write), which stay hdu's: its mandatory records first, each other one where h holds that keyword, or after h's records.
verify hdu reads hdu once and checks its checksums (§4.4.2.7): DATASUM, the ones' complement sum of the data unit as big-endian 32-bit words, and CHECKSUM, which makes the whole HDU sum to −0. It is an Error naming both sums if either is absent or disagrees.
write path hdus writes hdus to a new file beside path, syncs it and renames it over path, with mode 0640 on POSIX systems and writable on Windows, which has no modes. A failed write leaves path as it was. Values read by copy from a replaced file do not change.
Structure is the writer's. The structural keywords are SIMPLE, XTENSION, BITPIX, NAXIS, NAXISn, EXTEND, PCOUNT, GCOUNT, an image's BZERO and BSCALE, a table's TFIELDS, THEAP and column-numbered keywords, the tile-compression keywords, DATASUM and CHECKSUM. A record holding the value write computes stays at its place with its text; others are written at the standard's positions, and differing copies are dropped. The first HDU becomes the primary, and an empty primary is prepended when it is not an image.
Checksums are written on every HDU, in the pass that writes its bytes, with no date, so output is a function of input. An HDU whose DATASUM disagrees with its data is an Error naming Fits.v (Header.remove "DATASUM" (Fits.header hdu)) (Fits.data hdu), the call that accepts the data as it is.
pp formats an HDU's kind, EXTNAME and EXTVER, then Image.pp, or its data size for other kinds.
Units
val unit : hdu -> (Ymir_units.Unit.t option, string) Stdlib.resultunit hdu is BUNIT, parsed with Unit.parse scoped by <digest>#<EXTNAME> (HDU<i> when unnamed), so one file read twice gives equal units and two files give two; None if BUNIT is absent.