From 4232f1777df8c92d06e3eb9d7983de6f0c71499f Mon Sep 17 00:00:00 2001 From: Christopher Rabotin Date: Fri, 29 Dec 2023 01:10:50 -0700 Subject: [PATCH] [rust] [python] Fix signature of try_from_altlatlong to try_from_latlongalt The parameters did not match the function name! --- anise-py/tests/test_almanac.py | 17 ++++++++ anise/src/astro/orbit.rs | 17 ++++++++ anise/src/astro/orbit_geodetic.rs | 72 ++++++++++++++++++++++++++++--- anise/tests/astro/orbit.rs | 6 +-- 4 files changed, 104 insertions(+), 8 deletions(-) diff --git a/anise-py/tests/test_almanac.py b/anise-py/tests/test_almanac.py index 45e46b8a..2c703d57 100644 --- a/anise-py/tests/test_almanac.py +++ b/anise-py/tests/test_almanac.py @@ -62,6 +62,23 @@ def test_state_transformation(): assert orig_state == from_state_itrf93_to_eme2k + # Demo creation of a ground station + mean_earth_angular_velocity_deg_s = 0.004178079012116429 + # Grab the loaded frame info + itrf93 = ctx.frame_info(Frames.EARTH_ITRF93) + paris = Orbit.from_latlongalt( + 48.8566, + 2.3522, + 0.4, + mean_earth_angular_velocity_deg_s, + epoch, + itrf93, + ) + + assert abs(paris.geodetic_latitude_deg() - 48.8566) < 1e-3 + assert abs(paris.geodetic_longitude_deg() - 2.3522) < 1e-3 + assert abs(paris.geodetic_height_km() - 0.4) < 1e-3 + if __name__ == "__main__": test_state_transformation() diff --git a/anise/src/astro/orbit.rs b/anise/src/astro/orbit.rs index f6bd1513..2d4c9404 100644 --- a/anise/src/astro/orbit.rs +++ b/anise/src/astro/orbit.rs @@ -300,6 +300,23 @@ impl CartesianState { Self::try_keplerian(sma, ecc, inc, raan, aop, ta, epoch, frame) } + /// Attempts to create a new Orbit from the provided radii of apoapsis and periapsis, in kilometers + #[cfg(feature = "python")] + #[classmethod] + pub fn from_keplerian_apsis_radii( + _cls: &PyType, + r_a: f64, + r_p: f64, + inc: f64, + raan: f64, + aop: f64, + ta: f64, + epoch: Epoch, + frame: Frame, + ) -> PhysicsResult { + Self::try_keplerian_apsis_radii(r_a, r_p, inc, raan, aop, ta, epoch, frame) + } + /// Returns the orbital momentum value on the X axis pub fn hx(&self) -> PhysicsResult { Ok(self.hvec()?[0]) diff --git a/anise/src/astro/orbit_geodetic.rs b/anise/src/astro/orbit_geodetic.rs index f0cc928d..3fa5c00a 100644 --- a/anise/src/astro/orbit_geodetic.rs +++ b/anise/src/astro/orbit_geodetic.rs @@ -22,6 +22,8 @@ use log::error; #[cfg(feature = "python")] use pyo3::prelude::*; +#[cfg(feature = "python")] +use pyo3::types::PyType; impl CartesianState { /// Creates a new Orbit from the provided semi-major axis altitude in kilometers @@ -51,8 +53,8 @@ impl CartesianState { /// Creates a new Orbit from the provided altitudes of apoapsis and periapsis, in kilometers #[allow(clippy::too_many_arguments)] pub fn try_keplerian_apsis_altitude( - a_a: f64, - a_p: f64, + apo_alt: f64, + peri_alt: f64, inc: f64, raan: f64, aop: f64, @@ -61,8 +63,8 @@ impl CartesianState { frame: Frame, ) -> PhysicsResult { Self::try_keplerian_apsis_radii( - a_a + frame.mean_equatorial_radius_km()?, - a_p + frame.mean_equatorial_radius_km()?, + apo_alt + frame.mean_equatorial_radius_km()?, + peri_alt + frame.mean_equatorial_radius_km()?, inc, raan, aop, @@ -77,7 +79,7 @@ impl CartesianState { /// **Units:** degrees, degrees, km, rad/s /// NOTE: This computation differs from the spherical coordinates because we consider the flattening of body. /// Reference: G. Xu and Y. Xu, "GPS", DOI 10.1007/978-3-662-50367-6_2, 2016 - pub fn from_altlatlong( + pub fn try_from_latlongalt( latitude_deg: f64, longitude_deg: f64, height_km: f64, @@ -112,6 +114,66 @@ impl CartesianState { #[cfg_attr(feature = "python", pymethods)] impl CartesianState { + /// Creates a new Orbit from the provided semi-major axis altitude in kilometers + #[cfg(feature = "python")] + #[classmethod] + pub fn from_keplerian_altitude( + _cls: &PyType, + sma_altitude: f64, + ecc: f64, + inc: f64, + raan: f64, + aop: f64, + ta: f64, + epoch: Epoch, + frame: Frame, + ) -> PhysicsResult { + Self::try_keplerian_altitude(sma_altitude, ecc, inc, raan, aop, ta, epoch, frame) + } + + /// Creates a new Orbit from the provided altitudes of apoapsis and periapsis, in kilometers + #[cfg(feature = "python")] + #[classmethod] + pub fn from_keplerian_apsis_altitude( + _cls: &PyType, + apo_alt: f64, + peri_alt: f64, + inc: f64, + raan: f64, + aop: f64, + ta: f64, + epoch: Epoch, + frame: Frame, + ) -> PhysicsResult { + Self::try_keplerian_apsis_altitude(apo_alt, peri_alt, inc, raan, aop, ta, epoch, frame) + } + + /// Creates a new Orbit from the latitude (φ), longitude (λ) and height (in km) with respect to the frame's ellipsoid given the angular velocity. + /// + /// **Units:** degrees, degrees, km, rad/s + /// NOTE: This computation differs from the spherical coordinates because we consider the flattening of body. + /// Reference: G. Xu and Y. Xu, "GPS", DOI 10.1007/978-3-662-50367-6_2, 2016 + #[cfg(feature = "python")] + #[classmethod] + pub fn from_latlongalt( + _cls: &PyType, + latitude_deg: f64, + longitude_deg: f64, + height_km: f64, + angular_velocity: f64, + epoch: Epoch, + frame: Frame, + ) -> PhysicsResult { + Self::try_from_latlongalt( + latitude_deg, + longitude_deg, + height_km, + angular_velocity, + epoch, + frame, + ) + } + /// Returns the SMA altitude in km pub fn sma_altitude_km(&self) -> PhysicsResult { Ok(self.sma_km()? - self.frame.mean_equatorial_radius_km()?) diff --git a/anise/tests/astro/orbit.rs b/anise/tests/astro/orbit.rs index 253801bf..2621a0a0 100644 --- a/anise/tests/astro/orbit.rs +++ b/anise/tests/astro/orbit.rs @@ -462,7 +462,7 @@ fn verif_geodetic_vallado(almanac: Almanac) { f64_eq!(r.geodetic_longitude_deg(), long, "longitude (λ)"); f64_eq!(r.geodetic_height_km().unwrap(), height, "height"); let mean_earth_angular_velocity_deg_s = 0.004178079012116429; - let r = Orbit::from_altlatlong( + let r = Orbit::try_from_latlongalt( lat, long, height, @@ -484,7 +484,7 @@ fn verif_geodetic_vallado(almanac: Almanac) { let ri = 6_119.403_233_271_109; let rj = -1_571.480_316_600_378_3; let rk = -871.560_226_712_024_7; - let r = Orbit::from_altlatlong( + let r = Orbit::try_from_latlongalt( lat, long, height, @@ -502,7 +502,7 @@ fn verif_geodetic_vallado(almanac: Almanac) { f64_eq!(r.geodetic_height_km().unwrap(), height_val, "height"); // Check reciprocity near poles - let r = Orbit::from_altlatlong( + let r = Orbit::try_from_latlongalt( 0.1, long, height_val,