mwalib 2.0.3

A library to simplify reading Murchison Widefield Array (MWA) raw visibilities, voltages and metadata.
Documentation
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use num_derive::FromPrimitive;
use std::fmt;

#[cfg(test)]
mod test;

#[cfg(feature = "python-stubgen")]
use pyo3_stub_gen_derive::gen_stub_pyclass_enum;

/// Enum for all of the known variants of file format based on Correlator version
///
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
pub enum MWAVersion {
    /// MWA correlator (v1.0), having data files without any batch numbers.
    CorrOldLegacy = 1,
    /// MWA correlator (v1.0), having data files with "gpubox" and batch numbers in their names.
    CorrLegacy = 2,
    /// MWAX correlator (v2.0)
    CorrMWAXv2 = 3,
    /// Legacy VCS Recombined
    VCSLegacyRecombined = 4,
    /// MWAX VCS
    VCSMWAXv2 = 5,
    /// MWAX Beamformer
    BeamformerMWAXv2 = 6,
    /// MWAX Corr+Beamformer
    CorrBeamformerMWAXv2 = 7,
}

/// Implements fmt::Display for MWAVersion enum
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for MWAVersion {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                MWAVersion::CorrOldLegacy => "Correlator v1 old Legacy (no file indices)",
                MWAVersion::CorrLegacy => "Correlator v1 Legacy",
                MWAVersion::CorrMWAXv2 => "Correlator v2 MWAX",
                MWAVersion::VCSLegacyRecombined => "VCS Legacy Recombined",
                MWAVersion::VCSMWAXv2 => "VCS MWAX v2",
                MWAVersion::CorrBeamformerMWAXv2 => "Correlator and Beamformer v2 MWAX",
                MWAVersion::BeamformerMWAXv2 => "Beamformer MWAX v2",
            }
        )
    }
}

/// Visibility polarisations
///
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
pub enum VisPol {
    XX = 1,
    XY = 2,
    YX = 3,
    YY = 4,
}
/// Implements fmt::Display for VisPol enum
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for VisPol {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                VisPol::XX => "XX",
                VisPol::XY => "XY",
                VisPol::YX => "YX",
                VisPol::YY => "YY",
            }
        )
    }
}

/// The type of geometric delays applied to the data
///
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
pub enum GeometricDelaysApplied {
    No = 0,
    Zenith = 1,
    TilePointing = 2,
    AzElTracking = 3,
}

/// Implements fmt::Display for GeometricDelaysApplied enum
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for GeometricDelaysApplied {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                GeometricDelaysApplied::No => "No",
                GeometricDelaysApplied::Zenith => "Zenith",
                GeometricDelaysApplied::TilePointing => "Tile Pointing",
                GeometricDelaysApplied::AzElTracking => "Az/El Tracking",
            }
        )
    }
}

/// Implements str::FromStr for GeometricDelaysApplied enum
///
/// # Arguments
///
/// * `input` - A &str which we want to convert to an enum
///
///
/// # Returns
///
/// * `Result<GeometricDelaysApplied, Err>` - Result of this method
///
///
impl std::str::FromStr for GeometricDelaysApplied {
    type Err = ();

    fn from_str(input: &str) -> Result<GeometricDelaysApplied, Self::Err> {
        match input {
            "No" => Ok(GeometricDelaysApplied::No),
            "Zenith" => Ok(GeometricDelaysApplied::Zenith),
            "Tile Pointing" => Ok(GeometricDelaysApplied::TilePointing),
            "Az/El Tracking" => Ok(GeometricDelaysApplied::AzElTracking),
            _ => Err(()),
        }
    }
}

/// The type of cable delays applied to the data
///
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
pub enum CableDelaysApplied {
    NoCableDelaysApplied = 0,
    CableAndRecClock = 1,
    CableAndRecClockAndBeamformerDipoleDelays = 2,
}

/// Implements fmt::Display for CableDelaysApplied enum
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for CableDelaysApplied {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                CableDelaysApplied::NoCableDelaysApplied => "No",
                CableDelaysApplied::CableAndRecClock => "Cable and receiver clock cable length",
                CableDelaysApplied::CableAndRecClockAndBeamformerDipoleDelays =>
                    "Cable, receiver clock cable and pointing-dependent beamformer dipole delays",
            }
        )
    }
}

impl std::str::FromStr for CableDelaysApplied {
    type Err = ();

    fn from_str(input: &str) -> Result<CableDelaysApplied, Self::Err> {
        match input {
            "No" => Ok(CableDelaysApplied::NoCableDelaysApplied),
            "Cable and receiver clock cable length" => Ok(CableDelaysApplied::CableAndRecClock),
            "Cable, receiver clock cable and pointing-dependent beamformer dipole delays" => {
                Ok(CableDelaysApplied::CableAndRecClockAndBeamformerDipoleDelays)
            }
            _ => Err(()),
        }
    }
}

/// The MODE the system was in for this observation
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
pub enum MWAMode {
    No_Capture = 0,
    Burst_Vsib = 1,
    Sw_Cor_Vsib = 2,
    Hw_Cor_Pkts = 3,
    Rts_32t = 4,
    Hw_Lfiles = 5,
    Hw_Lfiles_Nomentok = 6,
    Sw_Cor_Vsib_Nomentok = 7,
    Burst_Vsib_Synced = 8,
    Burst_Vsib_Raw = 9,
    Lfiles_Client = 16,
    No_Capture_Burst = 17,
    Enter_Burst = 18,
    Enter_Channel = 19,
    Voltage_Raw = 20,
    Corr_Mode_Change = 21,
    Voltage_Start = 22,
    Voltage_Stop = 23,
    Voltage_Buffer = 24,
    Mwax_Correlator = 30,
    Mwax_Vcs = 31,
    Mwax_Buffer = 32,
    Mwax_Beamformer = 33,
    Mwax_Corr_Bf = 34,
}

/// Implements fmt::Display for MWAMode enum
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for MWAMode {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                MWAMode::No_Capture => "NO_CAPTURE",
                MWAMode::Burst_Vsib => "BURST_VSIB",
                MWAMode::Sw_Cor_Vsib => "SW_COR_VSIB",
                MWAMode::Hw_Cor_Pkts => "HW_COR_PKTS",
                MWAMode::Rts_32t => "RTS_32T",
                MWAMode::Hw_Lfiles => "HW_LFILES",
                MWAMode::Hw_Lfiles_Nomentok => "HW_LFILES_NOMENTOK",
                MWAMode::Sw_Cor_Vsib_Nomentok => "SW_COR_VSIB_NOMENTOK",
                MWAMode::Burst_Vsib_Synced => "BURST_VSIB_SYNCED",
                MWAMode::Burst_Vsib_Raw => "BURST_VSIB_RAW",
                MWAMode::Lfiles_Client => "LFILES_CLIENT",
                MWAMode::No_Capture_Burst => "NO_CAPTURE_BURST",
                MWAMode::Enter_Burst => "ENTER_BURST",
                MWAMode::Enter_Channel => "ENTER_CHANNEL",
                MWAMode::Voltage_Raw => "VOLTAGE_RAW",
                MWAMode::Corr_Mode_Change => "CORR_MODE_CHANGE",
                MWAMode::Voltage_Start => "VOLTAGE_START",
                MWAMode::Voltage_Stop => "VOLTAGE_STOP",
                MWAMode::Voltage_Buffer => "VOLTAGE_BUFFER",
                MWAMode::Mwax_Correlator => "MWAX_CORRELATOR",
                MWAMode::Mwax_Vcs => "MWAX_VCS",
                MWAMode::Mwax_Buffer => "MWAX_BUFFER",
                MWAMode::Mwax_Beamformer => "MWAX_BEAMFORMER",
                MWAMode::Mwax_Corr_Bf => "MWAX_CORR_BF",
            }
        )
    }
}

impl std::str::FromStr for MWAMode {
    type Err = ();

    fn from_str(input: &str) -> Result<MWAMode, Self::Err> {
        match input {
            "NO_CAPTURE" => Ok(MWAMode::No_Capture),
            "BURST_VSIB" => Ok(MWAMode::Burst_Vsib),
            "SW_COR_VSIB" => Ok(MWAMode::Sw_Cor_Vsib),
            "HW_COR_PKTS" => Ok(MWAMode::Hw_Cor_Pkts),
            "RTS_32T" => Ok(MWAMode::Rts_32t),
            "HW_LFILES" => Ok(MWAMode::Hw_Lfiles),
            "HW_LFILES_NOMENTOK" => Ok(MWAMode::Hw_Lfiles_Nomentok),
            "SW_COR_VSIB_NOMENTOK" => Ok(MWAMode::Sw_Cor_Vsib_Nomentok),
            "BURST_VSIB_SYNCED" => Ok(MWAMode::Burst_Vsib_Synced),
            "BURST_VSIB_RAW" => Ok(MWAMode::Burst_Vsib_Raw),
            "LFILES_CLIENT" => Ok(MWAMode::Lfiles_Client),
            "NO_CAPTURE_BURST" => Ok(MWAMode::No_Capture_Burst),
            "ENTER_BURST" => Ok(MWAMode::Enter_Burst),
            "ENTER_CHANNEL" => Ok(MWAMode::Enter_Channel),
            "VOLTAGE_RAW" => Ok(MWAMode::Voltage_Raw),
            "CORR_MODE_CHANGE" => Ok(MWAMode::Corr_Mode_Change),
            "VOLTAGE_START" => Ok(MWAMode::Voltage_Start),
            "VOLTAGE_STOP" => Ok(MWAMode::Voltage_Stop),
            "VOLTAGE_BUFFER" => Ok(MWAMode::Voltage_Buffer),
            "MWAX_CORRELATOR" => Ok(MWAMode::Mwax_Correlator),
            "MWAX_VCS" => Ok(MWAMode::Mwax_Vcs),
            "MWAX_BUFFER" => Ok(MWAMode::Mwax_Buffer),
            "MWAX_BEAMFORMER" => Ok(MWAMode::Mwax_Beamformer),
            "MWAX_CORR_BF" => Ok(MWAMode::Mwax_Corr_Bf),
            _ => Err(()),
        }
    }
}

/// Instrument polarisation.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
pub enum Pol {
    X,
    Y,
}

/// Implements fmt::Display for Pol
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for Pol {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Pol::X => "X",
                Pol::Y => "Y",
            }
        )
    }
}

/// ReceiverType enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
#[allow(clippy::upper_case_acronyms)]
pub enum ReceiverType {
    Unknown,
    RRI,
    NI,
    Pseudo,
    SHAO,
    EDA2,
}

/// Implements fmt::Display for ReceiverType
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for ReceiverType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                ReceiverType::Unknown => "Unknown",
                ReceiverType::RRI => "RRI",
                ReceiverType::NI => "NI",
                ReceiverType::Pseudo => "Pseudo",
                ReceiverType::SHAO => "SHAO",
                ReceiverType::EDA2 => "EDA2",
            }
        )
    }
}

/// Implements str::FromStr for ReceiverType enum.
/// Non uppercase values are coverted to uppercase for comparision.
///
/// # Arguments
///
/// * `input` - A &str which we want to convert to an enum
///
///
/// # Returns
///
/// * `Result<ReceiverType, Err>` - Result of this method
///
///
impl std::str::FromStr for ReceiverType {
    type Err = ();

    fn from_str(input: &str) -> Result<ReceiverType, Self::Err> {
        match input.to_uppercase().as_str() {
            "RRI" => Ok(ReceiverType::RRI),
            "NI" => Ok(ReceiverType::NI),
            "PSEUDO" => Ok(ReceiverType::Pseudo),
            "SHAO" => Ok(ReceiverType::SHAO),
            "EDA2" => Ok(ReceiverType::EDA2),
            _ => Ok(ReceiverType::Unknown),
        }
    }
}

/// DataFileType enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive)]
#[repr(C)]
#[cfg_attr(
    any(feature = "python", feature = "python-stubgen"),
    pyo3::pyclass(eq, eq_int, from_py_object)
)]
#[cfg_attr(feature = "python-stubgen", gen_stub_pyclass_enum)]
#[allow(clippy::upper_case_acronyms)]
pub enum DataFileType {
    UnknownType = 0,        // Unknown file type
    RawVsib = 1,            // Raw VSIB burst mode
    AvgVsib = 2,            // Averaged VSIB burst mode
    InstCfgTxt = 3,         // Instrument configuration text file
    HdrTxt = 4,             // header.txt file for uvfits converter
    InstCfgHdr = 5,         // Instrument configration text header
    Lacspc = 6,             // Averaged autocorrelation spectra (lacspc)
    Lccspc = 7,             // Averaged crosscorrelation spectra (lccspc)
    HwLfilesFits = 8,       // Raw Correlator Products
    AntCfg = 9,             // Antenna configuration header
    Flag = 10,              // MWA Flag File
    RawVolt = 11,           // Raw Voltage
    RawVoltRecombined = 12, // Raw Voltage Recombined
    Uvfits = 13,            // UVFITS File
    Ppd = 14,               // MWA PPD File
    Ics = 15,               // Voltage ICS
    Tar = 16,               // Voltage Recombined Archive
    Subfile = 17,           // MWAX voltages
    MwaxFits = 18,          // MWAX visibilities
    Vdif = 19,              // VDIF
    Filterbank = 20,        // Filterbank
}

/// Implements fmt::Display for DataFileType
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Display for DataFileType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                DataFileType::UnknownType => "Unknown",
                DataFileType::RawVsib => "RawVsib",
                DataFileType::AvgVsib => "AvgVsib",
                DataFileType::InstCfgTxt => "InstCfgTxt",
                DataFileType::HdrTxt => "HdrTxt",
                DataFileType::InstCfgHdr => "InstCfgHdr",
                DataFileType::Lacspc => "Lacspc",
                DataFileType::Lccspc => "Lccspc",
                DataFileType::HwLfilesFits => "HwLfilesFits",
                DataFileType::AntCfg => "AntCfg",
                DataFileType::Flag => "Flag",
                DataFileType::RawVolt => "RawVolt",
                DataFileType::RawVoltRecombined => "RawVoltRecombined",
                DataFileType::Uvfits => "Uvfits",
                DataFileType::Ppd => "Ppd",
                DataFileType::Ics => "Ics",
                DataFileType::Tar => "Tar",
                DataFileType::Subfile => "Subfile",
                DataFileType::MwaxFits => "MwaxFits",
                DataFileType::Vdif => "VDIF",
                DataFileType::Filterbank => "Filterbank",
            }
        )
    }
}