github ↗
docs menu

Module Ymir_fits.Fits

Values

#module Value : sig ... end

Value fields.

Headers

#module Header : sig ... end

Headers.

HDUs and files

#type hdu

The type for HDUs: a header and the bytes of its data unit.

#val read : string -> (hdu list, string) Stdlib.result

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.result

of_bytes ~name b is the HDUs of the bytes b in C order, as read reads a file. name starts their errors.

#val get : ?ver:int -> string -> hdu list -> (hdu, string) Stdlib.result

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 header : hdu -> Header.t

header hdu is hdu's header.

#val data : hdu -> (int, Nx.int8_unsigned_elt, Nx.host) Nx.t

data 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.

#val name : hdu -> string

name hdu is the path given to read, of_bytes's name, or "" for a constructed HDU.

#val digest : hdu -> string

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.

#val with_header : Header.t -> hdu -> hdu

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.

#val verify : hdu -> (unit, string) Stdlib.result

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.

#val write : string -> hdu list -> (unit, string) Stdlib.result

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.

#val pp : Stdlib.Format.formatter -> hdu -> unit

pp formats an HDU's kind, EXTNAME and EXTVER, then Image.pp, or its data size for other kinds.

Units

#module Unit : sig ... end

FITS unit strings (FITS 4.0 §4.3).

#val unit : hdu -> (Ymir_units.Unit.t option, string) Stdlib.result

unit 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.

Images

#module Image : sig ... end

Images.

Tables

#module Table : sig ... end

Binary and ASCII tables.