Skip to content

Commit

Permalink
feat(lox-orbits): implement frame and origin change for coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Nov 12, 2024
1 parent cee25d4 commit 08d826a
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 243 deletions.
48 changes: 46 additions & 2 deletions crates/lox-orbits/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::propagators::semi_analytical::{Vallado, ValladoError};
use crate::propagators::sgp4::{Sgp4, Sgp4Error};
use crate::propagators::Propagator;
use crate::states::ToCartesian;
use crate::trajectories::TrajectoryTransformationError;
use crate::{
frames::FrameTransformationProvider,
states::State,
Expand All @@ -49,6 +50,13 @@ use crate::{

mod generated;

impl From<TrajectoryTransformationError> for PyErr {
fn from(err: TrajectoryTransformationError) -> Self {
// FIXME: wrong error type
PyValueError::new_err(err.to_string())
}

Check warning on line 57 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L54-L57

Added lines #L54 - L57 were not covered by tests
}

impl From<FindEventError> for PyErr {
fn from(err: FindEventError) -> Self {
// FIXME: wrong error type
Expand Down Expand Up @@ -382,9 +390,19 @@ impl PyState {
}

fn to_origin(&self, target: &Bound<'_, PyAny>, ephemeris: &Bound<'_, PySpk>) -> PyResult<Self> {
if self.0.reference_frame() != PyFrame::Icrf {
return Err(PyValueError::new_err(
"only inertial frames are supported for conversion to Keplerian elements",
));
}
let target = PyBody::try_from(target)?;
let spk = ephemeris.borrow();
todo!()
let spk = &ephemeris.borrow().0;
let s1 = self
.0
.with_frame(Icrf)
.to_origin(target, spk)?
.with_frame(PyFrame::Icrf);
Ok(Self(s1))
}

Check warning on line 406 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L392-L406

Added lines #L392 - L406 were not covered by tests

fn to_keplerian(&self) -> PyResult<PyKeplerian> {
Expand Down Expand Up @@ -620,6 +638,32 @@ impl PyTrajectory {
}
Err(PyValueError::new_err("invalid time argument"))
}

#[pyo3(signature = (frame, provider=None))]
fn to_frame(
&self,
frame: PyFrame,
provider: Option<&Bound<'_, PyUt1Provider>>,
) -> PyResult<Self> {
let mut states: Vec<State<PyTime, PyBody, PyFrame>> =
Vec::with_capacity(self.0.states().len());
for s in self.0.states() {
states.push(PyState(s).to_frame(frame.clone(), provider)?.0);

Check warning on line 651 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L643-L651

Added lines #L643 - L651 were not covered by tests
}
Ok(PyTrajectory(Trajectory::new(&states)?))
}

Check warning on line 654 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L653-L654

Added lines #L653 - L654 were not covered by tests

fn to_origin(&self, target: &Bound<'_, PyAny>, ephemeris: &Bound<'_, PySpk>) -> PyResult<Self> {
let target = PyBody::try_from(target)?;
let spk = &ephemeris.borrow().0;
let s1 = self
.0
.clone()
.with_frame(Icrf)
.to_origin(target, spk)?
.with_frame(PyFrame::Icrf);
Ok(Self(s1))
}

Check warning on line 666 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L656-L666

Added lines #L656 - L666 were not covered by tests
}

#[pyclass(name = "Event", module = "lox_space", frozen)]
Expand Down
Loading

0 comments on commit 08d826a

Please sign in to comment.