Skip to content

Commit

Permalink
Fix smoothing arc in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Sep 2, 2023
1 parent 074df45 commit e1f8f5b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
68 changes: 25 additions & 43 deletions src/od/process/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use pyo3::prelude::*;

/// Defines the stopping condition for the smoother
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "python", pyclass)]
pub enum SmoothingArc {
/// Stop smoothing when the gap between estimate is the provided floating point number in seconds
TimeGap(Duration),
Expand All @@ -39,43 +38,6 @@ pub enum SmoothingArc {
All,
}

#[cfg(feature = "python")]
#[pymethods]
impl SmoothingArc {
#[new]
fn py_new(
strategy: Option<Epoch>,
duration: Option<Duration>,
epoch: Option<Epoch>,
) -> Result<Self, NyxError> {
if let Some(strategy) = strategy {
match strategy.to_lowercase().trim() {
"all" => Ok(Self::All),
"prediction" => Ok(Self::Prediction),
_ => Err(NyxError::CustomError(format!(
"strategy should be `all` or `prediction`"
))),
}
} else if Some(duration) = duration {
Ok(Self::TimeGap(duration))
} else if Some(epoch) = epoch {
Ok(Self::Epoch(epoch))
} else {
Err(NyxError::CustomError(
"Smoothing arc strategy not specified",
))
}
}

fn __repr__(&self) -> String {
format!("{self}")
}

fn __str__(&self) -> String {
format!("Smoothing {self}")
}
}

impl fmt::Display for SmoothingArc {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Expand Down Expand Up @@ -121,21 +83,41 @@ impl IterationConf {
impl IterationConf {
#[new]
fn py_new(
smoother: SmoothingArc,
strategy: Option<String>,
duration: Option<Duration>,
epoch: Option<Epoch>,
absolute_tol: Option<f64>,
relative_tol: Option<f64>,
max_iterations: Option<usize>,
max_divergences: Option<usize>,
force_failure: Option<bool>,
) -> Self {
) -> Result<Self, NyxError> {
let mut me = Self::default();
me.smoother = smoother;
me.smoother = if let Some(strategy) = strategy {
match strategy.to_lowercase().trim() {
"all" => SmoothingArc::All,
"prediction" => SmoothingArc::Prediction,
_ => {
return Err(NyxError::CustomError(format!(
"strategy should be `all` or `prediction`"
)))
}
}
} else if let Some(duration) = duration {
SmoothingArc::TimeGap(duration)
} else if let Some(epoch) = epoch {
SmoothingArc::Epoch(epoch)
} else {
return Err(NyxError::CustomError(
"Smoothing arc strategy not specified".to_string(),
));
};
if let Some(abs_tol) = absolute_tol {
me.absolute_tol = abs_tol;
}

if let Some(rel_tol) = relative_tol {
me.relative_tol = rel_toll
me.relative_tol = rel_tol;
}

if let Some(max_it) = max_iterations {
Expand All @@ -150,7 +132,7 @@ impl IterationConf {
me.force_failure = force_failure;
}

me
Ok(me)
}

fn __repr__(&self) -> String {
Expand Down
3 changes: 1 addition & 2 deletions src/python/orbit_determination/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::io::tracking_data::DynamicTrackingArc;
use crate::io::ExportCfg;
use crate::od::noise::GaussMarkov;
use crate::od::process::{FltResid, IterationConf, SmoothingArc};
use crate::od::process::{FltResid, IterationConf};
pub use crate::od::simulator::TrkConfig;
pub use crate::{io::ConfigError, od::prelude::GroundStation};
use pyo3::{prelude::*, py_run};
Expand All @@ -43,7 +43,6 @@ pub(crate) fn register_od(py: Python<'_>, parent_module: &PyModule) -> PyResult<
sm.add_class::<GaussMarkov>()?;
sm.add_class::<FltResid>()?;
sm.add_class::<IterationConf>()?;
sm.add_class::<SmoothingArc>()?;
sm.add_class::<ExportCfg>()?;
sm.add_function(wrap_pyfunction!(process_tracking_arc, sm)?)?;
sm.add_function(wrap_pyfunction!(predictor, sm)?)?;
Expand Down

0 comments on commit e1f8f5b

Please sign in to comment.