Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final changes for Nyx #263

Merged
merged 6 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion anise-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod utils;
fn anise(m: &Bound<'_, PyModule>) -> PyResult<()> {
pyo3_log::init();
register_time_module(m)?;
astro::register_astro(&m)?;
astro::register_astro(m)?;
utils::register_utils(m)?;
m.add_class::<Almanac>()?;
m.add_class::<Aberration>()?;
Expand Down
4 changes: 2 additions & 2 deletions anise/src/almanac/aer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ impl Almanac {
if tx.epoch != rx.epoch {
return Err(AlmanacError::Ephemeris {
action: "",
source: EphemerisError::EphemerisPhysics {
source: Box::new(EphemerisError::EphemerisPhysics {
action: "computing AER",
source: PhysicsError::EpochMismatch {
action: "computing AER",
epoch1: tx.epoch,
epoch2: rx.epoch,
},
},
}),
});
}

Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/metaalmanac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl Default for MetaAlmanac {
},
MetaFile {
uri: nyx_cloud_stor.join("v0.4/pck11.pca").unwrap().to_string(),
crc32: Some(0x62a4f3ad),
crc32: Some(0x8213b6e9),
},
MetaFile {
uri: nyx_cloud_stor.join("v0.4/moon_fk.epa").unwrap().to_string(),
Expand Down
17 changes: 9 additions & 8 deletions anise/src/almanac/metaload/metafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct MetaFile {
}

impl MetaFile {
/// Processes this MetaFile by downloading it if it's a URL.
/// Processes this MetaFile by downloading it if it's a URL and sets this structure's `uri` field to the local path
///
/// This function modified `self` and changes the URI to be the path to the downloaded file.
#[cfg(not(feature = "python"))]
Expand Down Expand Up @@ -119,15 +119,16 @@ impl MetaFile {
// Open the file and check the CRC32
let dest_path_c = dest_path.clone(); // macro token issue
if let Ok(bytes) = file2heap!(dest_path_c) {
if crc32fast::hash(&bytes) == crc32 {
let computed_crc32 = crc32fast::hash(&bytes);
let dest_path_s =
dest_path.to_str().unwrap().to_string();
if computed_crc32 == crc32 {
// No need to redownload this, let's just update the uri path
self.uri =
dest_path.to_str().unwrap().to_string();
info!(
"Using cached {} (CRC32 matched)",
self.uri
);
info!("Using cached {dest_path_s}",);
self.uri = dest_path_s;
return Ok(());
} else {
info!("Discarding cached {dest_path_s} - CRC32 differ (got {computed_crc32}, config expected {crc32})");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod meta_test {
[ { crc32 = Some 1921414410
, uri = "http://public-data.nyxspace.com/anise/de440s.bsp"
}
, { crc32 = Some 1654977453
, { crc32 = Some 2182330089
, uri = "http://public-data.nyxspace.com/anise/v0.4/pck11.pca"
}
, { crc32 = Some 292928914
Expand Down
30 changes: 0 additions & 30 deletions anise/src/almanac/planetary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,6 @@ impl Almanac {
}
}

/*
ui.heading("Name");
});
header.col(|ui| {
ui.heading("ID");
});
header.col(|ui| {
ui.heading("Gravity param (km^3/s^2)");
});

header.col(|ui| {
ui.heading("Major axis (km)");
});
header.col(|ui| {
ui.heading("Minor axis (km)");
});
header.col(|ui| {
ui.heading("Polar axis (km)");
});

header.col(|ui| {
ui.heading("Pole right asc.");
});
header.col(|ui| {
ui.heading("Pole declination");
});
header.col(|ui| {
ui.heading("Prime meridian");
*/

#[derive(Tabled, Default)]
struct PlanetaryRow {
#[tabled(rename = "Name")]
Expand Down
4 changes: 2 additions & 2 deletions anise/src/astro/aberration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
errors::{AberrationSnafu, VelocitySnafu},
math::{rotate_vector, Vector3},
};
use core::f64::EPSILON;

use core::fmt;

#[cfg(feature = "python")]
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn stellar_aberration(
// Correct for stellar aberration
let mut app_target_pos_km = target_pos_km;
let sin_phi = h.norm();
if sin_phi > EPSILON {
if sin_phi > f64::EPSILON {
let phi = sin_phi.asin();
app_target_pos_km = rotate_vector(&target_pos_km, &h, phi);
}
Expand Down
18 changes: 9 additions & 9 deletions anise/src/astro/orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
NaifId,
};
use core::f64::consts::PI;
use core::f64::EPSILON;

use core::fmt;
use hifitime::{Duration, Epoch, TimeUnits, Unit};
use log::{error, info, warn};
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Orbit {
frame: Frame,
) -> PhysicsResult<Self> {
let mu_km3_s2 = frame.mu_km3_s2()?;
if mu_km3_s2.abs() < EPSILON {
if mu_km3_s2.abs() < f64::EPSILON {
warn!("GM is near zero ({mu_km3_s2} km^3/s^2): expect rounding errors!",);
}
// Algorithm from GMAT's StateConversionUtil::KeplerianToCartesian
Expand Down Expand Up @@ -115,7 +115,7 @@ impl Orbit {
let ta = ta.to_radians();
let p = sma * (1.0 - ecc.powi(2));

ensure!(p.abs() >= EPSILON, ParabolicSemiParamSnafu { p });
ensure!(p.abs() >= f64::EPSILON, ParabolicSemiParamSnafu { p });

// NOTE: At this point GMAT computes 1+ecc**2 and checks whether it's very small.
// It then reports that the radius may be too large. We've effectively already done
Expand Down Expand Up @@ -159,13 +159,13 @@ impl Orbit {
frame: Frame,
) -> PhysicsResult<Self> {
ensure!(
r_a > EPSILON,
r_a > f64::EPSILON,
RadiusSnafu {
action: "radius of apoapsis is negative"
}
);
ensure!(
r_p > EPSILON,
r_p > f64::EPSILON,
RadiusSnafu {
action: "radius of periapsis is negative"
}
Expand Down Expand Up @@ -280,13 +280,13 @@ impl Orbit {
/// Returns the orbital momentum vector
pub fn hvec(&self) -> PhysicsResult<Vector3> {
ensure!(
self.rmag_km() > EPSILON,
self.rmag_km() > f64::EPSILON,
RadiusSnafu {
action: "cannot compute orbital momentum vector with zero radius"
}
);
ensure!(
self.vmag_km_s() > EPSILON,
self.vmag_km_s() > f64::EPSILON,
VelocitySnafu {
action: "cannot compute orbital momentum vector with zero velocity"
}
Expand All @@ -298,7 +298,7 @@ impl Orbit {
pub fn evec(&self) -> Result<Vector3, PhysicsError> {
let r = self.radius_km;
ensure!(
self.rmag_km() > EPSILON,
self.rmag_km() > f64::EPSILON,
RadiusSnafu {
action: "cannot compute eccentricity vector with zero radial state"
}
Expand Down Expand Up @@ -556,7 +556,7 @@ impl Orbit {
/// Returns the specific mechanical energy in km^2/s^2
pub fn energy_km2_s2(&self) -> PhysicsResult<f64> {
ensure!(
self.rmag_km() > EPSILON,
self.rmag_km() > f64::EPSILON,
RadiusSnafu {
action: "cannot compute energy with zero radial state"
}
Expand Down
2 changes: 1 addition & 1 deletion anise/src/astro/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::errors::{MathError, PhysicsError};

use super::PhysicsResult;

/// Mean anomaly epsilon
/// Mean anomaly f64::EPSILON
pub const MA_EPSILON: f64 = 1e-16;

/// Computes the true anomaly from the given mean anomaly for an orbit.
Expand Down
8 changes: 5 additions & 3 deletions anise/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ pub enum AlmanacError {
#[snafu(display("{action} encountered an error with ephemeris computation {source}"))]
Ephemeris {
action: &'static str,
source: EphemerisError,
#[snafu(source(from(EphemerisError, Box::new)))]
source: Box<EphemerisError>,
},
#[snafu(display("{action} encountered an error with orientation computation {source}"))]
Orientation {
action: &'static str,
source: OrientationError,
#[snafu(source(from(OrientationError, Box::new)))]
source: Box<OrientationError>,
},
#[snafu(display("{source} encountered when loading {path}"))]
Loading {
Expand Down Expand Up @@ -71,7 +73,7 @@ pub enum InputOutputError {
IOUnknownError,
}

#[derive(Debug, Snafu, PartialEq)]
#[derive(Copy, Clone, Debug, Snafu, PartialEq)]
#[snafu(visibility(pub(crate)))]
pub enum DecodingError {
#[snafu(display(
Expand Down
3 changes: 1 addition & 2 deletions anise/src/math/cartesian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ impl fmt::LowerExp for CartesianState {

#[cfg(test)]
mod cartesian_state_ut {
use std::f64::EPSILON;

use hifitime::{Duration, Epoch, TimeUnits};

Expand Down Expand Up @@ -465,7 +464,7 @@ mod cartesian_state_ut {
let s1 = CartesianState::new(10.0, 20.0, 30.0, 1.0, 2.0, 2.0, e, frame);
let s2 = CartesianState::new(10.0, 20.0, 30.0, 1.0, 2.0, 2.0, e, frame);

assert!(s1.distance_to_km(&s2).unwrap().abs() < EPSILON);
assert!(s1.distance_to_km(&s2).unwrap().abs() < f64::EPSILON);

let as_vec6 = Vector6::new(10.0, 20.0, 30.0, 1.0, 2.0, 2.0);
assert_eq!(s1.to_cartesian_pos_vel(), as_vec6);
Expand Down
2 changes: 1 addition & 1 deletion anise/src/math/cartesian_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl CartesianState {
#[allow(clippy::too_many_arguments)]
#[classmethod]
pub fn from_cartesian(
_cls: &PyType,
_cls: &Bound<'_, PyType>,
x_km: f64,
y_km: f64,
z_km: f64,
Expand Down
4 changes: 2 additions & 2 deletions anise/src/math/interpolation/chebyshev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

use crate::errors::MathError;
use core::f64::EPSILON;

use hifitime::Epoch;

use super::InterpolationError;
Expand All @@ -25,7 +25,7 @@ pub fn chebyshev_eval(
eval_epoch: Epoch,
degree: usize,
) -> Result<(f64, f64), InterpolationError> {
if spline_radius_s.abs() < EPSILON {
if spline_radius_s.abs() < f64::EPSILON {
return Err(InterpolationError::InterpMath {
source: MathError::DivisionByZero {
action: "spline radius in Chebyshev eval is zero",
Expand Down
15 changes: 6 additions & 9 deletions anise/src/math/interpolation/hermite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@

/* - SPICELIB Version 1.0.0, 01-MAR-2000 (NJB) */

use core::f64::EPSILON;

use crate::errors::MathError;
use log::error;

Expand Down Expand Up @@ -121,7 +119,7 @@ pub fn hermite_eval(
let c1 = xs[i] - x_eval;
let c2 = x_eval - xs[i - 1];
let denom = xs[i] - xs[i - 1];
if denom.abs() < EPSILON {
if denom.abs() < f64::EPSILON {
return Err(InterpolationError::InterpMath {
source: MathError::DivisionByZero {
action:
Expand Down Expand Up @@ -181,7 +179,7 @@ pub fn hermite_eval(
let c1 = xs[xij - 1] - x_eval;
let c2 = x_eval - xs[xi - 1];
let denom = xs[xij - 1] - xs[xi - 1];
if denom.abs() < EPSILON {
if denom.abs() < f64::EPSILON {
return Err(InterpolationError::InterpMath {
source:MathError::DivisionByZero {
action:
Expand Down Expand Up @@ -221,7 +219,6 @@ pub fn hermite_eval(

#[test]
fn hermite_spice_docs_example() {
use core::f64::EPSILON;
let ts = [-1.0, 0.0, 3.0, 5.0];
let yvals = [6.0, 5.0, 2210.0, 78180.0];
let ydotvals = [3.0, 0.0, 5115.0, 109395.0];
Expand All @@ -230,15 +227,15 @@ fn hermite_spice_docs_example() {
for (i, t) in ts.iter().enumerate() {
let (eval, deriv) = hermite_eval(&ts, &yvals, &ydotvals, *t).unwrap();
let eval_err = (eval - yvals[i]).abs();
assert!(eval_err < EPSILON, "f(x) error is {eval_err:e}");
assert!(eval_err < f64::EPSILON, "f(x) error is {eval_err:e}");

let deriv_err = (deriv - ydotvals[i]).abs();
assert!(deriv_err < EPSILON, "f'(x) error is {deriv_err:e}");
assert!(deriv_err < f64::EPSILON, "f'(x) error is {deriv_err:e}");
}

// Check the interpolation from the SPICE documentation
let (x, vx) = hermite_eval(&ts, &yvals, &ydotvals, 2.0).unwrap();

assert!((x - 141.0).abs() < EPSILON, "X error");
assert!((vx - 456.0).abs() < EPSILON, "VX error");
assert!((x - 141.0).abs() < f64::EPSILON, "X error");
assert!((vx - 456.0).abs() < f64::EPSILON, "VX error");
}
2 changes: 1 addition & 1 deletion anise/src/math/interpolation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::errors::{DecodingError, MathError};
/// Until https://github.com/rust-lang/rust/issues/60551 , we cannot do operations on const generic, so we need some hack around it.
pub(crate) const MAX_SAMPLES: usize = 32;

#[derive(Debug, Snafu, PartialEq)]
#[derive(Copy, Clone, Debug, Snafu, PartialEq)]
#[snafu(visibility(pub(crate)))]
pub enum InterpolationError {
#[snafu(display("decoding error during interpolation: {source}"))]
Expand Down
Loading
Loading