nyx_space/od/ground_station/
python.rs1use super::super::msr::MeasurementType;
2use super::super::noise::StochasticNoise;
3use super::GroundStation;
4use anise::astro::Location;
5use hifitime::Duration;
6use indexmap::IndexSet;
7use pyo3::prelude::*;
8use std::collections::HashMap;
9
10#[cfg(feature = "python")]
11#[pymethods]
12impl GroundStation {
13 #[new]
14 #[pyo3(signature = (name, location, stochastic_noises, integration_time=None, light_time_correction=false, timestamp_noise_s=None))]
15 fn py_new(
16 name: String,
17 location: Location,
18 stochastic_noises: HashMap<MeasurementType, StochasticNoise>,
19 integration_time: Option<Duration>,
20 light_time_correction: Option<bool>,
21 timestamp_noise_s: Option<StochasticNoise>,
22 ) -> Self {
23 Self {
24 name,
25 location,
26 measurement_types: IndexSet::from_iter(
27 stochastic_noises
28 .keys()
29 .copied()
30 .collect::<Vec<MeasurementType>>(),
31 ),
32 integration_time,
33 light_time_correction: light_time_correction.unwrap_or(false),
34 timestamp_noise_s,
35 stochastic_noises: Some(stochastic_noises.into_iter().collect()),
36 }
37 }
38
39 #[classmethod]
40 #[pyo3(name = "from_yaml")]
41 fn py_from_yaml(_cls: &Bound<'_, pyo3::types::PyType>, yaml_str: &str) -> PyResult<Self> {
42 serde_yml::from_str(yaml_str)
43 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
44 }
45
46 #[pyo3(name = "to_yaml")]
47 fn py_to_yaml(&self) -> PyResult<String> {
48 serde_yml::to_string(self)
49 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
50 }
51
52 #[classmethod]
53 #[pyo3(name = "load_many_yaml")]
54 fn py_load_many_yaml(_cls: &Bound<'_, pyo3::types::PyType>, path: &str) -> PyResult<Vec<Self>> {
55 use crate::io::ConfigRepr;
56 Self::load_many(path).map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
57 }
58
59 #[classmethod]
60 #[pyo3(name = "loads_many_yaml")]
61 fn py_loads_many_yaml(
62 _cls: &Bound<'_, pyo3::types::PyType>,
63 yaml_str: &str,
64 ) -> PyResult<Vec<Self>> {
65 use crate::io::ConfigRepr;
66 Self::loads_many(yaml_str)
67 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
68 }
69
70 #[classmethod]
71 #[pyo3(name = "dump_many_yaml")]
72 fn py_dump_many_yaml(
73 _cls: &Bound<'_, pyo3::types::PyType>,
74 stations: Vec<Self>,
75 path: &str,
76 ) -> PyResult<()> {
77 let s = serde_yml::to_string(&stations)
78 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?;
79 std::fs::write(path, s).map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))
80 }
81
82 #[classmethod]
83 #[pyo3(name = "dumps_many_yaml")]
84 fn py_dumps_many_yaml(
85 _cls: &Bound<'_, pyo3::types::PyType>,
86 stations: Vec<Self>,
87 ) -> PyResult<String> {
88 serde_yml::to_string(&stations)
89 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
90 }
91
92 fn __str__(&self) -> String {
93 format!("{self}")
94 }
95
96 fn __repr__(&self) -> String {
97 format!("{self:?} @ {self:p}")
98 }
99
100 fn __eq__(&self, other: &Self) -> bool {
101 self == other
102 }
103}