doris_rs/record/
mod.rs

1mod clock;
2mod flag;
3mod formatting;
4mod key;
5mod measurement;
6mod observation;
7mod parsing;
8mod snr;
9
10use itertools::Itertools;
11use std::collections::BTreeMap;
12
13#[cfg(doc)]
14use crate::prelude::GroundStation;
15
16use crate::prelude::{Comments, Epoch, Matcher, Observable};
17
18#[cfg(feature = "serde")]
19use serde::{Deserialize, Serialize};
20
21pub use clock::ClockOffset;
22pub use flag::EpochFlag;
23pub use key::Key;
24pub use measurement::Measurements;
25pub use observation::Observation;
26pub use snr::SNR;
27
28/// [Record] contains all [DORIS] data.
29#[derive(Clone, Debug, Default, PartialEq)]
30#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31pub struct Record {
32    /// Comments found "as is" during record parsing
33    pub comments: Comments,
34
35    /// [GroundStation]s [Measurement]s, in chronolical order.
36    /// Observations vary with the satellite orbit course.
37    pub measurements: BTreeMap<Key, Measurements>,
38}
39
40impl Record {
41    /// Obtain a chronological ([Epoch], and [EpochFlag]) [Iterator]
42    pub fn epochs_iter(&self) -> Box<dyn Iterator<Item = (Epoch, EpochFlag)> + '_> {
43        Box::new(self.measurements.keys().map(|k| (k.epoch, k.flag)).unique())
44    }
45
46    /// Returns the list of [Observable]s for given station
47    pub fn station_observables_iter<'a>(
48        &'a self,
49        matcher: &'a Matcher<'a>,
50    ) -> Box<dyn Iterator<Item = Observable> + '_> {
51        Box::new(
52            self.measurements
53                .iter()
54                .flat_map(move |(k, v)| {
55                    v.observations.keys().filter_map(move |observable| {
56                        if k.station.matches(&matcher) {
57                            Some(*observable)
58                        } else {
59                            None
60                        }
61                    })
62                })
63                .unique(),
64        )
65    }
66}