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]
59 #[pyo3(name = "from_parquet")]
60 fn py_from_parquet(_cls: Bound<'_, PyType>, path: &str) -> Result<Self, InputOutputError> {
61 Self::from_parquet(path)
62 }
63
64 #[pyo3(name = "write_ccsds_tdm")]
65 fn py_write_ccsds_tdm(
66 &self,
67 spacecraft_name: String,
68 aliases: Option<HashMap<String, String>>,
69 path: &str,
70 ) -> Result<String, InputOutputError> {
71 Ok(self
72 .clone()
73 .to_tdm_file(spacecraft_name, aliases, path, ExportCfg::default())?
74 .to_str()
75 .unwrap_or("woah_bug_building_path")
76 .to_string())
77 }
78
79 #[pyo3(name = "unique_aliases")]
80 fn py_unique_aliases(&self) -> Vec<String> {
81 self.unique_aliases().iter().cloned().collect()
82 }
83 #[pyo3(name = "unique_types")]
84 fn py_unique_types(&self) -> Vec<MeasurementType> {
85 self.unique_types().iter().cloned().collect()
86 }
87
88 fn __str__(&self) -> String {
89 format!("{self}")
90 }
91
92 fn __repr__(&self) -> String {
93 format!("{self} @ {self:p}")
94 }
95
96 #[getter]
97 fn get_force_reject(&self) -> bool {
98 self.force_reject
99 }
100
101 #[setter]
102 fn set_force_reject(&mut self, reject: bool) {
103 self.force_reject = reject;
104 }
105
106 #[pyo3(name = "filter_by_epoch")]
107 fn py_filter_by_epoch(&self, start: Option<Epoch>, end: Option<Epoch>) -> Self {
108 let start_bound = start.map(Included).unwrap_or(Unbounded);
109 let end_bound = end.map(Excluded).unwrap_or(Unbounded);
110 self.clone().filter_by_epoch((start_bound, end_bound))
111 }
112
113 #[pyo3(name = "filter_by_offset")]
114 fn py_filter_by_offset(&self, start: Option<Duration>, end: Option<Duration>) -> Self {
115 let start_bound = match start {
116 Some(s) => Included(s),
117 None => Unbounded,
118 };
119 let end_bound = match end {
120 Some(e) => Excluded(e),
121 None => Unbounded,
122 };
123 self.clone().filter_by_offset((start_bound, end_bound))
124 }
125
126 #[pyo3(name = "filter_by_tracker")]
127 fn py_filter_by_tracker(&self, tracker: String) -> Self {
128 self.clone().filter_by_tracker(tracker)
129 }
130
131 #[pyo3(name = "filter_by_measurement_type")]
132 fn py_filter_by_measurement_type(&self, msr_type: MeasurementType) -> Self {
133 self.clone().filter_by_measurement_type(msr_type)
134 }
135
136 #[pyo3(name = "exclude_tracker")]
137 fn py_exclude_tracker(&self, tracker: String) -> Self {
138 self.clone().exclude_tracker(tracker)
139 }
140
141 #[pyo3(name = "exclude_by_epoch")]
142 fn py_exclude_by_epoch(&self, start: Option<Epoch>, end: Option<Epoch>) -> Self {
143 let start_bound = match start {
144 Some(s) => Included(s),
145 None => Unbounded,
146 };
147 let end_bound = match end {
148 Some(e) => Excluded(e),
149 None => Unbounded,
150 };
151 self.clone().exclude_by_epoch((start_bound, end_bound))
152 }
153
154 #[pyo3(name = "exclude_measurement_type")]
155 fn py_exclude_measurement_type(&self, msr_type: MeasurementType) -> Self {
156 self.clone().exclude_measurement_type(msr_type)
157 }
158
159 #[pyo3(name = "resid_vs_ref_check")]
160 fn py_resid_vs_ref_check(&self) -> Self {
161 self.clone().resid_vs_ref_check()
162 }
163
164 #[pyo3(name = "to_parquet")]
165 fn py_to_parquet(&self, path: String, cfg: ExportCfg) -> Result<String, InputOutputError> {
166 self.to_parquet(path, cfg)
167 .map(|pathbuf| pathbuf.to_string_lossy().into_owned())
168 }
169}