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, measurement_types, integration_time=None, light_time_correction=false, timestamp_noise_s=None, stochastic_noises=None))]
15 fn py_new(
16 name: String,
17 location: Location,
18 measurement_types: Vec<MeasurementType>,
19 integration_time: Option<Duration>,
20 light_time_correction: Option<bool>,
21 timestamp_noise_s: Option<StochasticNoise>,
22 stochastic_noises: Option<HashMap<MeasurementType, StochasticNoise>>,
23 ) -> Self {
24 Self {
25 name,
26 location,
27 measurement_types: IndexSet::from_iter(measurement_types),
28 integration_time,
29 light_time_correction: light_time_correction.unwrap_or(false),
30 timestamp_noise_s,
31 stochastic_noises: stochastic_noises.map(|sn| sn.into_iter().collect()),
32 }
33 }
34
35 #[classmethod]
36 #[pyo3(name = "from_yaml")]
37 fn py_from_yaml(_cls: &Bound<'_, pyo3::types::PyType>, yaml_str: &str) -> PyResult<Self> {
38 serde_yml::from_str(yaml_str)
39 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
40 }
41
42 #[pyo3(name = "to_yaml")]
43 fn py_to_yaml(&self) -> PyResult<String> {
44 serde_yml::to_string(self)
45 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
46 }
47
48 #[classmethod]
49 #[pyo3(name = "load_many_yaml")]
50 fn py_load_many_yaml(_cls: &Bound<'_, pyo3::types::PyType>, path: &str) -> PyResult<Vec<Self>> {
51 use crate::io::ConfigRepr;
52 Self::load_many(path).map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
53 }
54
55 #[classmethod]
56 #[pyo3(name = "loads_many_yaml")]
57 fn py_loads_many_yaml(
58 _cls: &Bound<'_, pyo3::types::PyType>,
59 yaml_str: &str,
60 ) -> PyResult<Vec<Self>> {
61 use crate::io::ConfigRepr;
62 Self::loads_many(yaml_str)
63 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
64 }
65
66 #[classmethod]
67 #[pyo3(name = "dump_many_yaml")]
68 fn py_dump_many_yaml(
69 _cls: &Bound<'_, pyo3::types::PyType>,
70 stations: Vec<Self>,
71 path: &str,
72 ) -> PyResult<()> {
73 let s = serde_yml::to_string(&stations)
74 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?;
75 std::fs::write(path, s).map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))
76 }
77
78 #[classmethod]
79 #[pyo3(name = "dumps_many_yaml")]
80 fn py_dumps_many_yaml(
81 _cls: &Bound<'_, pyo3::types::PyType>,
82 stations: Vec<Self>,
83 ) -> PyResult<String> {
84 serde_yml::to_string(&stations)
85 .map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
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 fn __eq__(&self, other: &Self) -> bool {
97 self == other
98 }
99}