Skip to main content

fits_io/header/
image_type.rs

1use std::fmt::{Display, Formatter};
2
3/// What an exposure was for, from the IMAGETYP card.
4#[derive(Debug, Clone, Eq, PartialEq)]
5pub enum ImageType {
6    /// A frame of the sky itself.
7    Light,
8    /// A zero-length frame, to measure the sensor's readout offset.
9    Bias,
10    /// A frame taken with the shutter closed, to measure sensor noise.
11    Dark,
12    /// An evenly lit frame, to measure the optics' response across the field.
13    Flat,
14    /// A bias frame combined from many.
15    MasterBias,
16    /// A dark frame combined from many.
17    MasterDark,
18    /// A flat frame combined from many.
19    MasterFlat,
20    /// Anything else the card said.
21    Unknown(String),
22}
23
24impl From<&String> for ImageType {
25    fn from(value: &String) -> Self {
26        Self::from(value.as_str())
27    }
28}
29
30impl From<String> for ImageType {
31    fn from(value: String) -> Self {
32        Self::from(value.as_str())
33    }
34}
35
36impl From<&str> for ImageType {
37    fn from(value: &str) -> Self {
38        match value.to_lowercase().as_str() {
39            "light" => Self::Light,
40            "bias" => Self::Bias,
41            "dark" => Self::Dark,
42            "flat" => Self::Flat,
43            "masterbias" => Self::MasterBias,
44            "masterdark" => Self::MasterDark,
45            "masterflat" => Self::MasterFlat,
46            _ => Self::Unknown(value.to_string()),
47        }
48    }
49}
50
51impl Display for ImageType {
52    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
53        match self {
54            ImageType::Light => write!(f, "Light"),
55            ImageType::Bias => write!(f, "Bias"),
56            ImageType::Dark => write!(f, "Dark"),
57            ImageType::Flat => write!(f, "Flat"),
58            ImageType::MasterBias => write!(f, "MasterBias"),
59            ImageType::MasterDark => write!(f, "MasterDark"),
60            ImageType::MasterFlat => write!(f, "MasterFlat"),
61            ImageType::Unknown(v) => write!(f, "{}", v),
62        }
63    }
64}