pub struct Header { /* private fields */ }Expand description
A FITS header: the cards that describe an HDU and its data.
Implementations§
Source§impl Header
impl Header
The AUTHOR card: who prepared the data.
Sourcepub fn bitpix(&self) -> Option<Bitpix>
pub fn bitpix(&self) -> Option<Bitpix>
The BITPIX card: the type of the values in the data section.
BITPIX is mandatory, and a header lacking it is rejected when the file is
opened, so this returns Some for any header read from a file. It is
None only for a header built by hand and left incomplete.
Sourcepub fn blank(&self) -> Option<i64>
pub fn blank(&self) -> Option<i64>
The BLANK card: the raw value that stands for an undefined pixel.
The standard defines it only for the integer BITPIX types; a floating point array says the same thing with a NaN.
Sourcepub fn blocked(&self) -> Option<bool>
pub fn blocked(&self) -> Option<bool>
The BLOCKED card, a deprecated hint about the file’s block size.
Sourcepub fn bscale(&self) -> Option<f64>
pub fn bscale(&self) -> Option<f64>
The BSCALE card: the factor a raw array value is multiplied by.
See Header::bscale_or_default for the standard’s default of 1.
Sourcepub fn bscale_or_default(&self) -> f64
pub fn bscale_or_default(&self) -> f64
BSCALE, defaulting to 1.0 when the card is absent.
BSCALE is optional; the FITS standard defines its default as 1.0, so a missing card means unscaled data rather than unknown data.
Sourcepub fn bunit(&self) -> Option<&str>
pub fn bunit(&self) -> Option<&str>
The BUNIT card: the physical unit the array’s values are in.
Sourcepub fn bzero(&self) -> Option<f64>
pub fn bzero(&self) -> Option<f64>
The BZERO card: the offset added to a scaled array value.
See Header::bzero_or_default for the standard’s default of 0.
Sourcepub fn bzero_or_default(&self) -> f64
pub fn bzero_or_default(&self) -> f64
BZERO, defaulting to 0.0 when the card is absent.
BZERO is optional; the FITS standard defines its default as 0.0, so a missing card means unshifted data rather than unknown data.
Sourcepub fn data_max(&self) -> Option<f64>
pub fn data_max(&self) -> Option<f64>
The DATAMAX card: the largest physical value in the array.
Sourcepub fn data_min(&self) -> Option<f64>
pub fn data_min(&self) -> Option<f64>
The DATAMIN card: the smallest physical value in the array.
Sourcepub fn date_observed(&self) -> Option<&DateTime<Utc>>
pub fn date_observed(&self) -> Option<&DateTime<Utc>>
The DATE-OBS card: when the observation was made.
Sourcepub fn equinox(&self) -> Option<f64>
pub fn equinox(&self) -> Option<f64>
The EQUINOX card: the epoch of the coordinate system, in years.
Sourcepub fn extend(&self) -> Option<bool>
pub fn extend(&self) -> Option<bool>
The EXTEND card: whether extensions may follow the primary HDU.
Sourcepub fn extension_level(&self) -> Option<i64>
pub fn extension_level(&self) -> Option<i64>
The EXTLEVEL card: this extension’s level in a hierarchy of them.
Sourcepub fn extension_name(&self) -> Option<&str>
pub fn extension_name(&self) -> Option<&str>
The EXTNAME card: this extension’s name.
Sourcepub fn extension_version(&self) -> Option<i64>
pub fn extension_version(&self) -> Option<i64>
The EXTVER card: this extension’s version.
Sourcepub fn group_count(&self) -> Option<i64>
pub fn group_count(&self) -> Option<i64>
The GCOUNT card: how many groups the data section holds.
One for everything but a random-groups HDU.
Sourcepub fn groups(&self) -> Option<bool>
pub fn groups(&self) -> Option<bool>
The GROUPS card: whether this HDU uses the random-groups convention.
See Header::is_random_groups, which also checks the axis that marks it.
Sourcepub fn instrument(&self) -> Option<&str>
pub fn instrument(&self) -> Option<&str>
The INSTRUME card: the instrument the data came from.
Sourcepub fn naxis(&self) -> Option<i64>
pub fn naxis(&self) -> Option<i64>
The NAXIS card: how many axes the data section has.
NAXIS is mandatory, and a header lacking it is rejected when the file is
opened, so this returns Some for any header read from a file. It is
None only for a header built by hand and left incomplete.
Sourcepub fn pcount(&self) -> Option<i64>
pub fn pcount(&self) -> Option<i64>
The PCOUNT card: how many extra values follow the array.
This is a binary table’s heap, or the parameters of a random-groups HDU.
Sourcepub fn simple(&self) -> Option<bool>
pub fn simple(&self) -> Option<bool>
The SIMPLE card: whether the file conforms to the FITS standard.
Only a primary header carries it.
Sourcepub fn table_fields(&self) -> Option<i64>
pub fn table_fields(&self) -> Option<i64>
The TFIELDS card: how many columns the table has.
Sourcepub fn table_heap(&self) -> Option<i64>
pub fn table_heap(&self) -> Option<i64>
The THEAP card: where a binary table’s heap starts, as a byte offset into the data section.
Sourcepub fn extension(&self) -> Option<ExtensionType>
pub fn extension(&self) -> Option<ExtensionType>
The XTENSION card: which kind of extension this is.
None for a primary header, which is not an extension.
Sourcepub fn focal_length(&self) -> Option<f64>
pub fn focal_length(&self) -> Option<f64>
The FOCALLEN card: the telescope’s focal length.
A widespread convention among astrophotography software rather than part of the standard, as are the other camera keywords near it.
Sourcepub fn exposure_time(&self) -> Option<Duration>
pub fn exposure_time(&self) -> Option<Duration>
The EXPTIME card: how long the exposure lasted.
Sourcepub fn ccd_temperature(&self) -> Option<f64>
pub fn ccd_temperature(&self) -> Option<f64>
The CCD-TEMP card: the sensor’s temperature, in degrees Celsius.
Sourcepub fn bayer_pattern(&self) -> Option<BayerPattern>
pub fn bayer_pattern(&self) -> Option<BayerPattern>
The BAYERPAT card: the colour filter layout over the sensor.
None for a monochrome sensor, or one that did not record the pattern.
Sourcepub fn subframe_x_position_in_binned_pixels(&self) -> Option<i64>
pub fn subframe_x_position_in_binned_pixels(&self) -> Option<i64>
The XORGSUBF card: where a subframe starts on the sensor, horizontally.
Sourcepub fn subframe_y_position_in_binned_pixels(&self) -> Option<i64>
pub fn subframe_y_position_in_binned_pixels(&self) -> Option<i64>
The YORGSUBF card: where a subframe starts on the sensor, vertically.
Sourcepub fn binned_pixels_x(&self) -> Option<i64>
pub fn binned_pixels_x(&self) -> Option<i64>
The XBINNING card: how many sensor pixels were binned into one, horizontally.
Sourcepub fn binned_pixels_y(&self) -> Option<i64>
pub fn binned_pixels_y(&self) -> Option<i64>
The YBINNING card: how many sensor pixels were binned into one, vertically.
Sourcepub fn ccd_binned_pixels_x(&self) -> Option<i64>
pub fn ccd_binned_pixels_x(&self) -> Option<i64>
The CCDXBIN card, another spelling of XBINNING.
Sourcepub fn ccd_binned_pixels_y(&self) -> Option<i64>
pub fn ccd_binned_pixels_y(&self) -> Option<i64>
The CCDYBIN card, another spelling of YBINNING.
Sourcepub fn pixel_size_x_with_binning_in_microns(&self) -> Option<f64>
pub fn pixel_size_x_with_binning_in_microns(&self) -> Option<f64>
The XPIXSZ card: the width of a pixel in microns, binning included.
Sourcepub fn pixel_size_y_with_binning_in_microns(&self) -> Option<f64>
pub fn pixel_size_y_with_binning_in_microns(&self) -> Option<f64>
The YPIXSZ card: the height of a pixel in microns, binning included.
Sourcepub fn image_type(&self) -> Option<&ImageType>
pub fn image_type(&self) -> Option<&ImageType>
The IMAGETYP card: whether this is a light, dark, flat or bias frame.
Sourcepub fn focus_position(&self) -> Option<i64>
pub fn focus_position(&self) -> Option<i64>
The FOCUSPOS card: where the focuser was.
Sourcepub fn site_longitude(&self) -> Option<f64>
pub fn site_longitude(&self) -> Option<f64>
The SITELONG card: the observing site’s longitude.
Sourcepub fn site_latitude(&self) -> Option<f64>
pub fn site_latitude(&self) -> Option<f64>
The SITELAT card: the observing site’s latitude.
Sourcepub fn image_width(&self) -> Option<i64>
pub fn image_width(&self) -> Option<i64>
The IMAGEW card: the image’s width, as the writing software recorded it.
Sourcepub fn image_height(&self) -> Option<i64>
pub fn image_height(&self) -> Option<i64>
The IMAGEH card: the image’s height, as the writing software recorded it.
Sourcepub fn coordinate_delta(&self, index: usize) -> Option<f64>
pub fn coordinate_delta(&self, index: usize) -> Option<f64>
The CDELTn card for axis index: how far the world coordinate moves
per pixel.
Sourcepub fn coordinate_rotation(&self, index: usize) -> Option<f64>
pub fn coordinate_rotation(&self, index: usize) -> Option<f64>
The CROTAn card for axis index: the rotation between the pixel and
world axes, in degrees.
Sourcepub fn coordinate_reference_pixel(&self, index: usize) -> Option<f64>
pub fn coordinate_reference_pixel(&self, index: usize) -> Option<f64>
The CRPIXn card for axis index: the pixel that the reference value
sits at, counting from 1.
Sourcepub fn coordinate_value_at_pixel(&self, index: usize) -> Option<f64>
pub fn coordinate_value_at_pixel(&self, index: usize) -> Option<f64>
The CRVALn card for axis index: the world coordinate at the
reference pixel.
Sourcepub fn coordinate_transform(&self, row: usize, column: usize) -> Option<f64>
pub fn coordinate_transform(&self, row: usize, column: usize) -> Option<f64>
The CDi_j card: one element of the matrix taking pixel offsets to intermediate world coordinates.
row and column count from 0, so CD1_1 is coordinate_transform(0, 0).
This matrix carries the scale as well as the rotation, which is why a
header using it has no CDELTn cards.
Sourcepub fn coordinate_rotation_matrix(
&self,
row: usize,
column: usize,
) -> Option<f64>
pub fn coordinate_rotation_matrix( &self, row: usize, column: usize, ) -> Option<f64>
The PCi_j card: one element of the dimensionless matrix that rotates and skews pixel offsets, before CDELTn scales them.
row and column count from 0, so PC1_1 is
coordinate_rotation_matrix(0, 0).
Sourcepub fn coordinate_axis_name(&self, index: usize) -> Option<&str>
pub fn coordinate_axis_name(&self, index: usize) -> Option<&str>
The CTYPEn card for axis index: what the axis measures, and the
projection it uses.
Sourcepub fn naxis_n(&self, index: usize) -> Option<i64>
pub fn naxis_n(&self, index: usize) -> Option<i64>
The NAXISn card for axis index: how long that axis is.
index counts from 0, so NAXIS1 is naxis_n(0).
Sourcepub fn parameter_scaling_factor(&self, index: usize) -> Option<f64>
pub fn parameter_scaling_factor(&self, index: usize) -> Option<f64>
The PSCALn card for group parameter index.
Sourcepub fn parameter_type(&self, index: usize) -> Option<&str>
pub fn parameter_type(&self, index: usize) -> Option<&str>
The PTYPEn card for group parameter index: what it measures.
Sourcepub fn parameter_scaling_zero_point(&self, index: usize) -> Option<f64>
pub fn parameter_scaling_zero_point(&self, index: usize) -> Option<f64>
The PZEROn card for group parameter index.
Sourcepub fn table_column(&self, index: usize) -> Option<i64>
pub fn table_column(&self, index: usize) -> Option<i64>
The TBCOLn card for column index: where the column starts within an
ASCII table’s row, counting from 1.
Sourcepub fn table_dimensions(&self, index: usize) -> Option<&str>
pub fn table_dimensions(&self, index: usize) -> Option<&str>
The TDIMn card for column index: the shape of a multidimensional
column, as written.
Sourcepub fn table_display_format(&self, index: usize) -> Option<&str>
pub fn table_display_format(&self, index: usize) -> Option<&str>
The TDISPn card for column index: how the column is best displayed.
Sourcepub fn table_null_value(&self, index: usize) -> Option<&TableNullValue>
pub fn table_null_value(&self, index: usize) -> Option<&TableNullValue>
The TNULLn card for column index: the value that marks an undefined
entry in that column.
Sourcepub fn table_scaling_factor(&self, index: usize) -> Option<f64>
pub fn table_scaling_factor(&self, index: usize) -> Option<f64>
The TSCALn card for column index: the factor a stored entry is
multiplied by.
Sourcepub fn table_column_type(&self, index: usize) -> Option<&str>
pub fn table_column_type(&self, index: usize) -> Option<&str>
The TTYPEn card for column index: the column’s name.
Sourcepub fn table_format(&self, index: usize) -> Option<&str>
pub fn table_format(&self, index: usize) -> Option<&str>
The TFORMn card for column index, exactly as written.
Sourcepub fn table_column_format(&self, index: usize) -> Option<TableColumnFormat>
pub fn table_column_format(&self, index: usize) -> Option<TableColumnFormat>
The TFORMn card for column index, read as a binary table format.
None when the card is absent or does not name a binary table format,
which is the case for every ASCII table; use
Header::ascii_column_format for those.
Sourcepub fn ascii_column_format(&self, index: usize) -> Option<AsciiColumnFormat>
pub fn ascii_column_format(&self, index: usize) -> Option<AsciiColumnFormat>
The TFORMn card for column index, read as an ASCII table format.
None when the card is absent or does not name an ASCII table format.
Sourcepub fn table_unit(&self, index: usize) -> Option<&str>
pub fn table_unit(&self, index: usize) -> Option<&str>
The TUNITn card for column index: the column’s physical unit.
Sourcepub fn table_scaling_zero_point(&self, index: usize) -> Option<f64>
pub fn table_scaling_zero_point(&self, index: usize) -> Option<f64>
The TZEROn card for column index: the offset added after scaling.
Sourcepub fn is_compressed_image(&self) -> bool
pub fn is_compressed_image(&self) -> bool
Whether this HDU is an image stored compressed inside a table.
The tiled image convention keeps a compressed image in a binary table,
one tile per row, and describes the image it stands for with keywords
beginning Z. Such an HDU reads as a table unless it is decompressed;
see BinTableHDU::read_compressed_image.
Sourcepub fn compressed_bitpix(&self) -> Option<Bitpix>
pub fn compressed_bitpix(&self) -> Option<Bitpix>
The ZBITPIX card: the type of the values in the image once decompressed.
Sourcepub fn compressed_naxis(&self) -> Option<i64>
pub fn compressed_naxis(&self) -> Option<i64>
The ZNAXIS card: how many axes the decompressed image has.
Sourcepub fn compressed_naxis_n(&self, index: usize) -> Option<i64>
pub fn compressed_naxis_n(&self, index: usize) -> Option<i64>
The ZNAXISn card for axis index: the decompressed image’s length along
it. index counts from 0.
Sourcepub fn compressed_tile_size(&self, index: usize) -> i64
pub fn compressed_tile_size(&self, index: usize) -> i64
The ZTILEn card for axis index: how far a tile reaches along it.
The convention’s default is a tile one row of the image wide, which is what a header that leaves the card out means.
Sourcepub fn compression_type(&self) -> Option<&str>
pub fn compression_type(&self) -> Option<&str>
The ZCMPTYPE card: which algorithm the tiles were compressed with.
Sourcepub fn compression_parameter(&self, name: &str) -> Option<i64>
pub fn compression_parameter(&self, name: &str) -> Option<i64>
A compression parameter, looked up by the name a ZNAMEn card gives it.
The algorithms take their settings as name and value pairs rather than as
keywords of their own, so Rice’s block size arrives as ZNAME1 = 'BLOCKSIZE' with the value in ZVAL1.
Sourcepub fn quantization_method(&self) -> Option<&str>
pub fn quantization_method(&self) -> Option<&str>
The ZQUANTIZ card: how a floating point image’s values were turned into the integers the compressor works on.
NO_DITHER quantises plainly; the two SUBTRACTIVE_DITHER methods add a
known pseudo-random number to each value before rounding it and take the
same number off again on the way back, which keeps quantisation from
laying a pattern over a smooth background.
Sourcepub fn dither_seed(&self) -> Option<i64>
pub fn dither_seed(&self) -> Option<i64>
The ZDITHER0 card: which entry of the dithering sequence the first tile starts at.
Sourcepub fn compressed_blank(&self) -> Option<i64>
pub fn compressed_blank(&self) -> Option<i64>
The ZBLANK card: the quantised value that stands for a pixel the image does not define.
A tile may carry its own ZBLANK column instead, which takes precedence over this for that tile.
Sourcepub fn uncompressed(&self) -> Self
pub fn uncompressed(&self) -> Self
The header the decompressed image would have.
Every card that describes the table rather than the image is dropped, and
BITPIX and the NAXISn cards are taken from their Z counterparts, so
that the result describes the image the HDU stands for. Anything else the
header carried — WCS keywords especially — comes across untouched.
Sourcepub fn is_random_groups(&self) -> bool
pub fn is_random_groups(&self) -> bool
Whether this HDU uses the random-groups convention.
Such an HDU’s data section is not an image but GCOUNT groups, each one a
run of PCOUNT parameters followed by an array. The convention is marked
by GROUPS = T, and by a first axis of length zero standing in for the
axis the groups occupy.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Renders this header as the bytes it occupies in a file.
The result is always a whole number of 2880-byte blocks, padded with spaces, and always ends with an END card — a header without one is not a header a reader can find the end of.
Sourcepub fn set_naxis_n(
&mut self,
index: usize,
length: i64,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_naxis_n( &mut self, index: usize, length: i64, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sets the NAXISn card for axis index, which counts from 0.
§Errors
Returns an error for a negative length, which no axis can have.
Sourcepub fn raw_card(&self, key: &str) -> Vec<Value>
pub fn raw_card(&self, key: &str) -> Vec<Value>
Every card with the keyword key, as raw values.
Most keywords appear once, but COMMENT and HISTORY may repeat, and an unrecognised keyword can appear as often as the writer liked.
Sourcepub fn card(&self, key: &str) -> Option<Value>
pub fn card(&self, key: &str) -> Option<Value>
The value of the card with the keyword key, if there is one.
Where a keyword repeats — COMMENT and HISTORY do, and an unrecognised one
may — this is the first of them; Header::raw_card returns them all.
let mut header = Header::default();
header.set_card("OBJECT", "M31")?;
assert_eq!(header.card("OBJECT").map(|v| v.value_to_string()), Some("M31".into()));
assert!(header.card("MISSING").is_none());Sourcepub fn contains_card(&self, key: &str) -> bool
pub fn contains_card(&self, key: &str) -> bool
Whether this header carries a card with the keyword key.
Sourcepub fn card_keys(&self) -> impl Iterator<Item = String> + '_
pub fn card_keys(&self) -> impl Iterator<Item = String> + '_
Every keyword this header holds, in the order the cards are in.
A repeated keyword appears once per card, and the blank keyword of a COMMENT-style card with no keyword appears as an empty string.
Sourcepub fn set_card(
&mut self,
key: &str,
value: impl Into<Value>,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_card( &mut self, key: &str, value: impl Into<Value>, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sets the card with the keyword key to value, adding it if the header
does not already have one.
The value may be any of the types a FITS card can hold — an integer, a
float, a bool, a string, or None for a keyword written with no value —
and Value::with_comment puts a comment beside it.
A keyword of up to eight characters drawn from A–Z, 0–9, - and
_ is written as an ordinary card, upper-cased on the way in. A longer
or otherwise unconventional keyword is written with the HIERARCH
convention, which keeps its case. Setting a keyword this crate reads
through one of its typed accessors — OBJECT, DATE-OBS, BUNIT and
the rest — leaves that accessor returning the new value.
§Errors
Returns an error for a keyword that is empty, holds characters a card
cannot carry, or is one of the repeatable and structural keywords that
have setters of their own: use Header::add_comment,
Header::add_history and Header::set_naxis_n for those. Also
returns an error when the value is too long for the one card it has to
fit on — a long string is written across CONTINUE cards instead and is
never too long.
let mut header = Header::default();
header.set_card("OBJECT", "NGC 7000")?;
header.set_card("EXPTIME", Value::from(120.0).with_comment("seconds"))?;
header.set_card("MOONLIT", true)?;
// A keyword too long for the eight columns a card gives it becomes a
// HIERARCH card.
header.set_card("ESO INS FILT1 NAME", "Halpha")?;
assert_eq!(header.object(), Some("NGC 7000"));Sourcepub fn remove_card(&mut self, key: &str) -> usize
pub fn remove_card(&mut self, key: &str) -> usize
Removes every card with the keyword key, and says how many went.
A mandatory card removed this way comes back when the header is written: SIMPLE, BITPIX, NAXIS and the rest are filled in from the data whatever the cards say.
Sourcepub fn add_comment(&mut self, text: impl AsRef<str>)
pub fn add_comment(&mut self, text: impl AsRef<str>)
Adds a COMMENT card carrying text.
COMMENT cards repeat, so this always adds one rather than replacing what is there. Text too long for a card is split across as many as it needs.
Sourcepub fn add_history(&mut self, text: impl AsRef<str>)
pub fn add_history(&mut self, text: impl AsRef<str>)
Adds a HISTORY card carrying text.
As with Header::add_comment, this adds rather than replaces, and text
too long for one card is split across several.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnsafeUnpin for Header
impl UnwindSafe for Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more