pyref_core/
enums.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/// Represents different types of experiments.
pub enum ExperimentType {
    Xrr,
    Xrs,
    Other,
}

impl ExperimentType {
    /// Creates an `ExperimentType` from a string.
    pub fn from_str(exp_type: &str) -> Result<Self, crate::errors::FitsLoaderError> {
        match exp_type.to_lowercase().as_str() {
            "xrr" => Ok(ExperimentType::Xrr),
            "xrs" => Ok(ExperimentType::Xrs),
            "other" => Ok(ExperimentType::Other),
            _ => Err(crate::errors::FitsLoaderError::InvalidExperimentType(
                exp_type.to_string(),
            )),
        }
    }

    /// Retrieves the relevant header keys for the experiment type.
    pub fn get_keys(&self) -> Vec<HeaderValue> {
        match self {
            ExperimentType::Xrr => vec![
                HeaderValue::SampleTheta,
                HeaderValue::CCDTheta,
                HeaderValue::BeamlineEnergy,
                HeaderValue::BeamCurrent,
                HeaderValue::EPUPolarization,
                HeaderValue::HorizontalExitSlitSize,
                HeaderValue::HigherOrderSuppressor,
                HeaderValue::Exposure,
            ],
            ExperimentType::Xrs => vec![HeaderValue::BeamlineEnergy],
            ExperimentType::Other => vec![],
        }
    }

    /// Retrieves the header names for display purposes.
    pub fn names(&self) -> Vec<&str> {
        match self {
            ExperimentType::Xrr => vec![
                "Sample Theta",
                "CCD Theta",
                "Beamline Energy",
                "Beam Current",
                "EPU Polarization",
                "Horizontal Exit Slit Size",
                "Higher Order Suppressor",
                "EXPOSURE",
            ],
            ExperimentType::Xrs => vec!["Beamline Energy"],
            ExperimentType::Other => vec![],
        }
    }
}

/// Represents different header values.
pub enum HeaderValue {
    SampleTheta,
    CCDTheta,
    BeamlineEnergy,
    EPUPolarization,
    BeamCurrent,
    HorizontalExitSlitSize,
    HigherOrderSuppressor,
    Exposure,
}

impl HeaderValue {
    /// Returns the unit associated with the header value.
    pub fn unit(&self) -> &str {
        match self {
            HeaderValue::SampleTheta => "[deg]",
            HeaderValue::CCDTheta => "[deg]",
            HeaderValue::BeamlineEnergy => "[eV]",
            HeaderValue::BeamCurrent => "[mA]",
            HeaderValue::EPUPolarization => "[deg]",
            HeaderValue::HorizontalExitSlitSize => "[um]",
            HeaderValue::HigherOrderSuppressor => "[mm]",
            HeaderValue::Exposure => "[s]",
        }
    }

    /// Returns the HDU key associated with the header value.
    pub fn hdu(&self) -> &str {
        match self {
            HeaderValue::SampleTheta => "Sample Theta",
            HeaderValue::CCDTheta => "CCD Theta",
            HeaderValue::BeamlineEnergy => "Beamline Energy",
            HeaderValue::BeamCurrent => "Beam Current",
            HeaderValue::EPUPolarization => "EPU Polarization",
            HeaderValue::HorizontalExitSlitSize => "Horizontal Exit Slit Size",
            HeaderValue::HigherOrderSuppressor => "Higher Order Suppressor",
            HeaderValue::Exposure => "EXPOSURE",
        }
    }

    /// Returns the full name with units for display.
    pub fn name(&self) -> &str {
        match self {
            HeaderValue::SampleTheta => "Sample Theta [deg]",
            HeaderValue::CCDTheta => "CCD Theta [deg]",
            HeaderValue::BeamlineEnergy => "Beamline Energy [eV]",
            HeaderValue::BeamCurrent => "Beam Current [mA]",
            HeaderValue::EPUPolarization => "EPU Polarization [deg]",
            HeaderValue::HorizontalExitSlitSize => "Horizontal Exit Slit Size [um]",
            HeaderValue::HigherOrderSuppressor => "Higher Order Suppressor [mm]",
            HeaderValue::Exposure => "EXPOSURE [s]",
        }
    }
}