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
// 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/.

/*!
Structs and helper methods for baseline metadata
*/
use crate::misc;
use std::fmt;

#[cfg(test)]
mod test;
/// This is a struct for our baselines, so callers know the antenna ordering
#[derive(Clone)]
pub struct Baseline {
    /// Index in the mwalibContext.antenna array for antenna1 for this baseline
    pub ant1_index: usize,
    /// Index in the mwalibContext.antenna array for antenna2 for this baseline
    pub ant2_index: usize,
}

impl Baseline {
    /// Creates a new, populated
    ///Baseline struct
    ///
    /// # Arguments
    ///
    /// * `num_ants` - The number of antennas in this observation
    ///
    ///
    /// # Returns
    ///
    /// * A populated Baseline struct
    ///    
    pub(crate) fn populate_baselines(num_ants: usize) -> Vec<Self> {
        let num_baselines = misc::get_baseline_count(num_ants);
        let mut bls: Vec<Baseline> = vec![
            Baseline {
                ant1_index: 0,
                ant2_index: 0
            };
            num_baselines
        ];
        let mut bl_index = 0;

        for a1 in 0..num_ants {
            for a2 in a1..num_ants {
                bls[bl_index].ant1_index = a1;
                bls[bl_index].ant2_index = a2;

                bl_index += 1;
            }
        }

        bls
    }
}
/// Implements fmt::Debug for Baseline struct
///
/// # Arguments
///
/// * `f` - A fmt::Formatter
///
///
/// # Returns
///
/// * `fmt::Result` - Result of this method
///
///
impl fmt::Debug for Baseline {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{},{}", self.ant1_index, self.ant2_index,)
    }
}