Skip to content

Commit

Permalink
Relax tracking sim from Python
Browse files Browse the repository at this point in the history
Python ground tracking arc sim now supports both orbit and spacecraft trajectories
  • Loading branch information
ChristopherRabotin committed Aug 30, 2023
1 parent c000659 commit 28aea9e
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/python/orbit_determination/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use std::collections::HashMap;

use crate::cosmic::Cosm;
use crate::io::trajectory_data::TrajectoryLoader;
use crate::io::ExportCfg;
use crate::md::prelude::Traj;
use crate::od::msr::RangeDoppler;
use crate::od::simulator::TrackingArcSim;
pub use crate::od::simulator::TrkConfig;
pub use crate::{io::ConfigError, od::prelude::GroundStation};
use crate::{NyxError, Spacecraft};
use crate::{NyxError, Orbit, Spacecraft};
use either::Either;
use pyo3::prelude::*;
use std::collections::HashMap;

#[derive(Clone)]
#[pyclass]
pub struct GroundTrackingArcSim {
inner: TrackingArcSim<Spacecraft, RangeDoppler, GroundStation>,
inner: Either<
TrackingArcSim<Spacecraft, RangeDoppler, GroundStation>,
TrackingArcSim<Orbit, RangeDoppler, GroundStation>,
>,
}

#[pymethods]
Expand All @@ -44,13 +48,20 @@ impl GroundTrackingArcSim {
configs: HashMap<String, TrkConfig>,
seed: u64,
) -> Result<Self, NyxError> {
// Try to convert the dynamic trajectory into an Orbit trajectory
let traj = trajectory
.to_traj()
.map_err(|e| NyxError::CustomError(e.to_string()))?;

let inner = TrackingArcSim::with_seed(devices, traj, configs, seed)
.map_err(NyxError::ConfigError)?;
// Try to convert the dynamic trajectory into a trajectory
let inner = if let Ok(sc_traj) = trajectory.to_traj::<Spacecraft>() {
Either::Left(
TrackingArcSim::with_seed(devices, sc_traj, configs, seed)
.map_err(NyxError::ConfigError)?,
)
} else if let Ok(traj) = trajectory.to_traj::<Orbit>() {
Either::Right(
TrackingArcSim::with_seed(devices, traj, configs, seed)
.map_err(NyxError::ConfigError)?,
)
} else {
return Err(NyxError::CustomError("Provided trajectory could neither be parsed as an orbit trajectory or a spacecraft trajectory".to_string()));
};

Ok(Self { inner })
}
Expand All @@ -64,7 +75,10 @@ impl GroundTrackingArcSim {
export_cfg: ExportCfg,
) -> Result<String, NyxError> {
let cosm = Cosm::de438();
let arc = self.inner.generate_measurements(cosm)?;
let arc = match &mut self.inner {
Either::Left(arc_sim) => arc_sim.generate_measurements(cosm)?,
Either::Right(arc_sim) => arc_sim.generate_measurements(cosm)?,
};

// Save the tracking arc
let maybe = arc.to_parquet(path, export_cfg);
Expand Down

0 comments on commit 28aea9e

Please sign in to comment.