Skip to main content

mwalib/types/
mod.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5use num_derive::FromPrimitive;
6use std::fmt;
7
8#[cfg(test)]
9mod test;
10
11#[cfg(feature = "python-stubgen")]
12use pyo3_stub_gen_derive::gen_stub_pyclass_enum;
13
14/// Enum for all of the known variants of file format based on Correlator version
15///
16#[repr(C)]
17#[derive(Debug, PartialEq, Eq, Clone, Copy)]
18#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
19#[cfg_attr(
20    any(feature = "python", feature = "python-stubgen"),
21    pyo3::pyclass(eq, eq_int, from_py_object)
22)]
23pub enum MWAVersion {
24    /// MWA correlator (v1.0), having data files without any batch numbers.
25    CorrOldLegacy = 1,
26    /// MWA correlator (v1.0), having data files with "gpubox" and batch numbers in their names.
27    CorrLegacy = 2,
28    /// MWAX correlator (v2.0)
29    CorrMWAXv2 = 3,
30    /// Legacy VCS Recombined
31    VCSLegacyRecombined = 4,
32    /// MWAX VCS
33    VCSMWAXv2 = 5,
34    /// MWAX Beamformer
35    BeamformerMWAXv2 = 6,
36    /// MWAX Corr+Beamformer
37    CorrBeamformerMWAXv2 = 7,
38}
39
40/// Implements fmt::Display for MWAVersion enum
41///
42/// # Arguments
43///
44/// * `f` - A fmt::Formatter
45///
46///
47/// # Returns
48///
49/// * `fmt::Result` - Result of this method
50///
51///
52impl fmt::Display for MWAVersion {
53    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54        write!(
55            f,
56            "{}",
57            match self {
58                MWAVersion::CorrOldLegacy => "Correlator v1 old Legacy (no file indices)",
59                MWAVersion::CorrLegacy => "Correlator v1 Legacy",
60                MWAVersion::CorrMWAXv2 => "Correlator v2 MWAX",
61                MWAVersion::VCSLegacyRecombined => "VCS Legacy Recombined",
62                MWAVersion::VCSMWAXv2 => "VCS MWAX v2",
63                MWAVersion::CorrBeamformerMWAXv2 => "Correlator and Beamformer v2 MWAX",
64                MWAVersion::BeamformerMWAXv2 => "Beamformer MWAX v2",
65            }
66        )
67    }
68}
69
70/// Visibility polarisations
71///
72#[repr(C)]
73#[derive(Debug, Clone, Copy, PartialEq)]
74#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
75#[cfg_attr(
76    any(feature = "python", feature = "python-stubgen"),
77    pyo3::pyclass(eq, eq_int, from_py_object)
78)]
79pub enum VisPol {
80    XX = 1,
81    XY = 2,
82    YX = 3,
83    YY = 4,
84}
85/// Implements fmt::Display for VisPol enum
86///
87/// # Arguments
88///
89/// * `f` - A fmt::Formatter
90///
91///
92/// # Returns
93///
94/// * `fmt::Result` - Result of this method
95///
96///
97impl fmt::Display for VisPol {
98    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
99        write!(
100            f,
101            "{}",
102            match self {
103                VisPol::XX => "XX",
104                VisPol::XY => "XY",
105                VisPol::YX => "YX",
106                VisPol::YY => "YY",
107            }
108        )
109    }
110}
111
112/// The type of geometric delays applied to the data
113///
114#[repr(C)]
115#[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive)]
116#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
117#[cfg_attr(
118    any(feature = "python", feature = "python-stubgen"),
119    pyo3::pyclass(eq, eq_int, from_py_object)
120)]
121pub enum GeometricDelaysApplied {
122    No = 0,
123    Zenith = 1,
124    TilePointing = 2,
125    AzElTracking = 3,
126}
127
128/// Implements fmt::Display for GeometricDelaysApplied enum
129///
130/// # Arguments
131///
132/// * `f` - A fmt::Formatter
133///
134///
135/// # Returns
136///
137/// * `fmt::Result` - Result of this method
138///
139///
140impl fmt::Display for GeometricDelaysApplied {
141    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142        write!(
143            f,
144            "{}",
145            match self {
146                GeometricDelaysApplied::No => "No",
147                GeometricDelaysApplied::Zenith => "Zenith",
148                GeometricDelaysApplied::TilePointing => "Tile Pointing",
149                GeometricDelaysApplied::AzElTracking => "Az/El Tracking",
150            }
151        )
152    }
153}
154
155/// Implements str::FromStr for GeometricDelaysApplied enum
156///
157/// # Arguments
158///
159/// * `input` - A &str which we want to convert to an enum
160///
161///
162/// # Returns
163///
164/// * `Result<GeometricDelaysApplied, Err>` - Result of this method
165///
166///
167impl std::str::FromStr for GeometricDelaysApplied {
168    type Err = ();
169
170    fn from_str(input: &str) -> Result<GeometricDelaysApplied, Self::Err> {
171        match input {
172            "No" => Ok(GeometricDelaysApplied::No),
173            "Zenith" => Ok(GeometricDelaysApplied::Zenith),
174            "Tile Pointing" => Ok(GeometricDelaysApplied::TilePointing),
175            "Az/El Tracking" => Ok(GeometricDelaysApplied::AzElTracking),
176            _ => Err(()),
177        }
178    }
179}
180
181/// The type of cable delays applied to the data
182///
183#[repr(C)]
184#[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive)]
185#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
186#[cfg_attr(
187    any(feature = "python", feature = "python-stubgen"),
188    pyo3::pyclass(eq, eq_int, from_py_object)
189)]
190pub enum CableDelaysApplied {
191    NoCableDelaysApplied = 0,
192    CableAndRecClock = 1,
193    CableAndRecClockAndBeamformerDipoleDelays = 2,
194}
195
196/// Implements fmt::Display for CableDelaysApplied enum
197///
198/// # Arguments
199///
200/// * `f` - A fmt::Formatter
201///
202///
203/// # Returns
204///
205/// * `fmt::Result` - Result of this method
206///
207///
208impl fmt::Display for CableDelaysApplied {
209    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
210        write!(
211            f,
212            "{}",
213            match self {
214                CableDelaysApplied::NoCableDelaysApplied => "No",
215                CableDelaysApplied::CableAndRecClock => "Cable and receiver clock cable length",
216                CableDelaysApplied::CableAndRecClockAndBeamformerDipoleDelays =>
217                    "Cable, receiver clock cable and pointing-dependent beamformer dipole delays",
218            }
219        )
220    }
221}
222
223impl std::str::FromStr for CableDelaysApplied {
224    type Err = ();
225
226    fn from_str(input: &str) -> Result<CableDelaysApplied, Self::Err> {
227        match input {
228            "No" => Ok(CableDelaysApplied::NoCableDelaysApplied),
229            "Cable and receiver clock cable length" => Ok(CableDelaysApplied::CableAndRecClock),
230            "Cable, receiver clock cable and pointing-dependent beamformer dipole delays" => {
231                Ok(CableDelaysApplied::CableAndRecClockAndBeamformerDipoleDelays)
232            }
233            _ => Err(()),
234        }
235    }
236}
237
238/// The MODE the system was in for this observation
239#[repr(C)]
240#[derive(Debug, PartialEq, Eq, Clone, Copy)]
241#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
242#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
243#[cfg_attr(
244    any(feature = "python", feature = "python-stubgen"),
245    pyo3::pyclass(eq, eq_int, from_py_object)
246)]
247pub enum MWAMode {
248    No_Capture = 0,
249    Burst_Vsib = 1,
250    Sw_Cor_Vsib = 2,
251    Hw_Cor_Pkts = 3,
252    Rts_32t = 4,
253    Hw_Lfiles = 5,
254    Hw_Lfiles_Nomentok = 6,
255    Sw_Cor_Vsib_Nomentok = 7,
256    Burst_Vsib_Synced = 8,
257    Burst_Vsib_Raw = 9,
258    Lfiles_Client = 16,
259    No_Capture_Burst = 17,
260    Enter_Burst = 18,
261    Enter_Channel = 19,
262    Voltage_Raw = 20,
263    Corr_Mode_Change = 21,
264    Voltage_Start = 22,
265    Voltage_Stop = 23,
266    Voltage_Buffer = 24,
267    Mwax_Correlator = 30,
268    Mwax_Vcs = 31,
269    Mwax_Buffer = 32,
270    Mwax_Beamformer = 33,
271    Mwax_Corr_Bf = 34,
272}
273
274/// Implements fmt::Display for MWAMode enum
275///
276/// # Arguments
277///
278/// * `f` - A fmt::Formatter
279///
280///
281/// # Returns
282///
283/// * `fmt::Result` - Result of this method
284///
285///
286impl fmt::Display for MWAMode {
287    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
288        write!(
289            f,
290            "{}",
291            match self {
292                MWAMode::No_Capture => "NO_CAPTURE",
293                MWAMode::Burst_Vsib => "BURST_VSIB",
294                MWAMode::Sw_Cor_Vsib => "SW_COR_VSIB",
295                MWAMode::Hw_Cor_Pkts => "HW_COR_PKTS",
296                MWAMode::Rts_32t => "RTS_32T",
297                MWAMode::Hw_Lfiles => "HW_LFILES",
298                MWAMode::Hw_Lfiles_Nomentok => "HW_LFILES_NOMENTOK",
299                MWAMode::Sw_Cor_Vsib_Nomentok => "SW_COR_VSIB_NOMENTOK",
300                MWAMode::Burst_Vsib_Synced => "BURST_VSIB_SYNCED",
301                MWAMode::Burst_Vsib_Raw => "BURST_VSIB_RAW",
302                MWAMode::Lfiles_Client => "LFILES_CLIENT",
303                MWAMode::No_Capture_Burst => "NO_CAPTURE_BURST",
304                MWAMode::Enter_Burst => "ENTER_BURST",
305                MWAMode::Enter_Channel => "ENTER_CHANNEL",
306                MWAMode::Voltage_Raw => "VOLTAGE_RAW",
307                MWAMode::Corr_Mode_Change => "CORR_MODE_CHANGE",
308                MWAMode::Voltage_Start => "VOLTAGE_START",
309                MWAMode::Voltage_Stop => "VOLTAGE_STOP",
310                MWAMode::Voltage_Buffer => "VOLTAGE_BUFFER",
311                MWAMode::Mwax_Correlator => "MWAX_CORRELATOR",
312                MWAMode::Mwax_Vcs => "MWAX_VCS",
313                MWAMode::Mwax_Buffer => "MWAX_BUFFER",
314                MWAMode::Mwax_Beamformer => "MWAX_BEAMFORMER",
315                MWAMode::Mwax_Corr_Bf => "MWAX_CORR_BF",
316            }
317        )
318    }
319}
320
321impl std::str::FromStr for MWAMode {
322    type Err = ();
323
324    fn from_str(input: &str) -> Result<MWAMode, Self::Err> {
325        match input {
326            "NO_CAPTURE" => Ok(MWAMode::No_Capture),
327            "BURST_VSIB" => Ok(MWAMode::Burst_Vsib),
328            "SW_COR_VSIB" => Ok(MWAMode::Sw_Cor_Vsib),
329            "HW_COR_PKTS" => Ok(MWAMode::Hw_Cor_Pkts),
330            "RTS_32T" => Ok(MWAMode::Rts_32t),
331            "HW_LFILES" => Ok(MWAMode::Hw_Lfiles),
332            "HW_LFILES_NOMENTOK" => Ok(MWAMode::Hw_Lfiles_Nomentok),
333            "SW_COR_VSIB_NOMENTOK" => Ok(MWAMode::Sw_Cor_Vsib_Nomentok),
334            "BURST_VSIB_SYNCED" => Ok(MWAMode::Burst_Vsib_Synced),
335            "BURST_VSIB_RAW" => Ok(MWAMode::Burst_Vsib_Raw),
336            "LFILES_CLIENT" => Ok(MWAMode::Lfiles_Client),
337            "NO_CAPTURE_BURST" => Ok(MWAMode::No_Capture_Burst),
338            "ENTER_BURST" => Ok(MWAMode::Enter_Burst),
339            "ENTER_CHANNEL" => Ok(MWAMode::Enter_Channel),
340            "VOLTAGE_RAW" => Ok(MWAMode::Voltage_Raw),
341            "CORR_MODE_CHANGE" => Ok(MWAMode::Corr_Mode_Change),
342            "VOLTAGE_START" => Ok(MWAMode::Voltage_Start),
343            "VOLTAGE_STOP" => Ok(MWAMode::Voltage_Stop),
344            "VOLTAGE_BUFFER" => Ok(MWAMode::Voltage_Buffer),
345            "MWAX_CORRELATOR" => Ok(MWAMode::Mwax_Correlator),
346            "MWAX_VCS" => Ok(MWAMode::Mwax_Vcs),
347            "MWAX_BUFFER" => Ok(MWAMode::Mwax_Buffer),
348            "MWAX_BEAMFORMER" => Ok(MWAMode::Mwax_Beamformer),
349            "MWAX_CORR_BF" => Ok(MWAMode::Mwax_Corr_Bf),
350            _ => Err(()),
351        }
352    }
353}
354
355/// Instrument polarisation.
356#[derive(Debug, Clone, Copy, PartialEq, Eq)]
357#[cfg_attr(
358    any(feature = "python", feature = "python-stubgen"),
359    pyo3::pyclass(eq, eq_int, from_py_object)
360)]
361#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
362pub enum Pol {
363    X,
364    Y,
365}
366
367/// Implements fmt::Display for Pol
368///
369/// # Arguments
370///
371/// * `f` - A fmt::Formatter
372///
373///
374/// # Returns
375///
376/// * `fmt::Result` - Result of this method
377///
378///
379impl fmt::Display for Pol {
380    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
381        write!(
382            f,
383            "{}",
384            match self {
385                Pol::X => "X",
386                Pol::Y => "Y",
387            }
388        )
389    }
390}
391
392/// ReceiverType enum.
393#[derive(Debug, Clone, Copy, PartialEq, Eq)]
394#[repr(C)]
395#[cfg_attr(
396    any(feature = "python", feature = "python-stubgen"),
397    pyo3::pyclass(eq, eq_int, from_py_object)
398)]
399#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
400#[allow(clippy::upper_case_acronyms)]
401pub enum ReceiverType {
402    Unknown,
403    RRI,
404    NI,
405    Pseudo,
406    SHAO,
407    EDA2,
408}
409
410/// Implements fmt::Display for ReceiverType
411///
412/// # Arguments
413///
414/// * `f` - A fmt::Formatter
415///
416///
417/// # Returns
418///
419/// * `fmt::Result` - Result of this method
420///
421///
422impl fmt::Display for ReceiverType {
423    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
424        write!(
425            f,
426            "{}",
427            match self {
428                ReceiverType::Unknown => "Unknown",
429                ReceiverType::RRI => "RRI",
430                ReceiverType::NI => "NI",
431                ReceiverType::Pseudo => "Pseudo",
432                ReceiverType::SHAO => "SHAO",
433                ReceiverType::EDA2 => "EDA2",
434            }
435        )
436    }
437}
438
439/// Implements str::FromStr for ReceiverType enum.
440/// Non uppercase values are coverted to uppercase for comparision.
441///
442/// # Arguments
443///
444/// * `input` - A &str which we want to convert to an enum
445///
446///
447/// # Returns
448///
449/// * `Result<ReceiverType, Err>` - Result of this method
450///
451///
452impl std::str::FromStr for ReceiverType {
453    type Err = ();
454
455    fn from_str(input: &str) -> Result<ReceiverType, Self::Err> {
456        match input.to_uppercase().as_str() {
457            "RRI" => Ok(ReceiverType::RRI),
458            "NI" => Ok(ReceiverType::NI),
459            "PSEUDO" => Ok(ReceiverType::Pseudo),
460            "SHAO" => Ok(ReceiverType::SHAO),
461            "EDA2" => Ok(ReceiverType::EDA2),
462            _ => Ok(ReceiverType::Unknown),
463        }
464    }
465}
466
467/// DataFileType enum.
468#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive)]
469#[repr(C)]
470#[cfg_attr(
471    any(feature = "python", feature = "python-stubgen"),
472    pyo3::pyclass(eq, eq_int, from_py_object)
473)]
474#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
475#[allow(clippy::upper_case_acronyms)]
476pub enum DataFileType {
477    UnknownType = 0,        // Unknown file type
478    RawVsib = 1,            // Raw VSIB burst mode
479    AvgVsib = 2,            // Averaged VSIB burst mode
480    InstCfgTxt = 3,         // Instrument configuration text file
481    HdrTxt = 4,             // header.txt file for uvfits converter
482    InstCfgHdr = 5,         // Instrument configration text header
483    Lacspc = 6,             // Averaged autocorrelation spectra (lacspc)
484    Lccspc = 7,             // Averaged crosscorrelation spectra (lccspc)
485    HwLfilesFits = 8,       // Raw Correlator Products
486    AntCfg = 9,             // Antenna configuration header
487    Flag = 10,              // MWA Flag File
488    RawVolt = 11,           // Raw Voltage
489    RawVoltRecombined = 12, // Raw Voltage Recombined
490    Uvfits = 13,            // UVFITS File
491    Ppd = 14,               // MWA PPD File
492    Ics = 15,               // Voltage ICS
493    Tar = 16,               // Voltage Recombined Archive
494    Subfile = 17,           // MWAX voltages
495    MwaxFits = 18,          // MWAX visibilities
496    Vdif = 19,              // VDIF
497    Filterbank = 20,        // Filterbank
498}
499
500/// Implements fmt::Display for DataFileType
501///
502/// # Arguments
503///
504/// * `f` - A fmt::Formatter
505///
506///
507/// # Returns
508///
509/// * `fmt::Result` - Result of this method
510///
511///
512impl fmt::Display for DataFileType {
513    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
514        write!(
515            f,
516            "{}",
517            match self {
518                DataFileType::UnknownType => "Unknown",
519                DataFileType::RawVsib => "RawVsib",
520                DataFileType::AvgVsib => "AvgVsib",
521                DataFileType::InstCfgTxt => "InstCfgTxt",
522                DataFileType::HdrTxt => "HdrTxt",
523                DataFileType::InstCfgHdr => "InstCfgHdr",
524                DataFileType::Lacspc => "Lacspc",
525                DataFileType::Lccspc => "Lccspc",
526                DataFileType::HwLfilesFits => "HwLfilesFits",
527                DataFileType::AntCfg => "AntCfg",
528                DataFileType::Flag => "Flag",
529                DataFileType::RawVolt => "RawVolt",
530                DataFileType::RawVoltRecombined => "RawVoltRecombined",
531                DataFileType::Uvfits => "Uvfits",
532                DataFileType::Ppd => "Ppd",
533                DataFileType::Ics => "Ics",
534                DataFileType::Tar => "Tar",
535                DataFileType::Subfile => "Subfile",
536                DataFileType::MwaxFits => "MwaxFits",
537                DataFileType::Vdif => "VDIF",
538                DataFileType::Filterbank => "Filterbank",
539            }
540        )
541    }
542}