nyx_space/od/msr/trackingdata/
python.rs1use super::{Measurement, MeasurementType, TrackingDataArc};
20use crate::io::{ExportCfg, InputOutputError};
21use hifitime::{Duration, Epoch};
22use pyo3::prelude::*;
23use pyo3::types::PyType;
24use std::collections::HashMap;
25use std::ops::Bound::{Excluded, Included, Unbounded};
26
27#[pymethods]
28impl TrackingDataArc {
29 #[new]
30 fn py_new(measurements: Vec<Measurement>) -> Self {
31 let mut trk_data = Self {
32 measurements,
33 source: None,
34 moduli: None,
35 force_reject: false,
36 };
37
38 trk_data.sort();
39
40 trk_data
41 }
42
43 #[classmethod]
49 #[pyo3(name = "from_ccsds_tdm")]
50 fn py_from_ccsds_tdm_file(
51 _cls: Bound<'_, PyType>,
52 path: &str,
53 aliases: Option<HashMap<String, String>>,
54 ) -> Result<Self, InputOutputError> {
55 TrackingDataArc::from_tdm(path, aliases)
56 }
57
58 #[classmethod]
63 #[pyo3(name = "from_parquet")]
64 fn py_from_parquet(_cls: Bound<'_, PyType>, path: &str) -> Result<Self, InputOutputError> {
65 Self::from_parquet(path)
66 }
67
68 #[pyo3(name = "write_ccsds_tdm")]
75 fn py_write_ccsds_tdm(
76 &self,
77 spacecraft_name: String,
78 aliases: Option<HashMap<String, String>>,
79 path: &str,
80 ) -> Result<String, InputOutputError> {
81 Ok(self
82 .clone()
83 .to_tdm_file(spacecraft_name, aliases, path, ExportCfg::default())?
84 .to_str()
85 .unwrap_or("woah_bug_building_path")
86 .to_string())
87 }
88
89 #[pyo3(name = "unique_aliases")]
91 fn py_unique_aliases(&self) -> Vec<String> {
92 self.unique_aliases().iter().cloned().collect()
93 }
94 #[pyo3(name = "unique_types")]
96 fn py_unique_types(&self) -> Vec<MeasurementType> {
97 self.unique_types().iter().cloned().collect()
98 }
99
100 fn __str__(&self) -> String {
101 format!("{self}")
102 }
103
104 fn __repr__(&self) -> String {
105 format!("{self} @ {self:p}")
106 }
107
108 #[getter]
109 fn get_force_reject(&self) -> bool {
110 self.force_reject
111 }
112
113 #[setter]
114 fn set_force_reject(&mut self, reject: bool) {
115 self.force_reject = reject;
116 }
117
118 #[pyo3(name = "filter_by_epoch")]
124 fn py_filter_by_epoch(&self, start: Option<Epoch>, end: Option<Epoch>) -> Self {
125 let start_bound = start.map(Included).unwrap_or(Unbounded);
126 let end_bound = end.map(Excluded).unwrap_or(Unbounded);
127 self.clone().filter_by_epoch((start_bound, end_bound))
128 }
129
130 #[pyo3(name = "filter_by_offset")]
136 fn py_filter_by_offset(&self, start: Option<Duration>, end: Option<Duration>) -> Self {
137 let start_bound = match start {
138 Some(s) => Included(s),
139 None => Unbounded,
140 };
141 let end_bound = match end {
142 Some(e) => Excluded(e),
143 None => Unbounded,
144 };
145 self.clone().filter_by_offset((start_bound, end_bound))
146 }
147
148 #[pyo3(name = "filter_by_tracker")]
153 fn py_filter_by_tracker(&self, tracker: String) -> Self {
154 self.clone().filter_by_tracker(tracker)
155 }
156
157 #[pyo3(name = "filter_by_measurement_type")]
162 fn py_filter_by_measurement_type(&self, msr_type: MeasurementType) -> Self {
163 self.clone().filter_by_measurement_type(msr_type)
164 }
165
166 #[pyo3(name = "exclude_tracker")]
171 fn py_exclude_tracker(&self, tracker: String) -> Self {
172 self.clone().exclude_tracker(tracker)
173 }
174
175 #[pyo3(name = "exclude_by_epoch")]
181 fn py_exclude_by_epoch(&self, start: Option<Epoch>, end: Option<Epoch>) -> Self {
182 let start_bound = match start {
183 Some(s) => Included(s),
184 None => Unbounded,
185 };
186 let end_bound = match end {
187 Some(e) => Excluded(e),
188 None => Unbounded,
189 };
190 self.clone().exclude_by_epoch((start_bound, end_bound))
191 }
192
193 #[pyo3(name = "exclude_measurement_type")]
198 fn py_exclude_measurement_type(&self, msr_type: MeasurementType) -> Self {
199 self.clone().exclude_measurement_type(msr_type)
200 }
201
202 #[pyo3(name = "resid_vs_ref_check")]
204 fn py_resid_vs_ref_check(&self) -> Self {
205 self.clone().resid_vs_ref_check()
206 }
207
208 #[pyo3(name = "to_parquet")]
214 fn py_to_parquet(&self, path: String, cfg: ExportCfg) -> Result<String, InputOutputError> {
215 self.to_parquet(path, cfg)
216 .map(|pathbuf| pathbuf.to_string_lossy().into_owned())
217 }
218}