Skip to content

Commit

Permalink
Merge pull request #126 from nyx-space/97-allow-boolean-combination-o…
Browse files Browse the repository at this point in the history
…f-events

[WIP] Demo of boolean combination of events and trajectories now in parquet only
  • Loading branch information
ChristopherRabotin authored Mar 21, 2023
2 parents b960811 + 3a3007b commit 07634ab
Show file tree
Hide file tree
Showing 67 changed files with 2,995 additions and 1,881 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "nyx-space"
build = "build.rs"
version = "2.0.0-alpha.0"
version = "2.0.0-alpha.1"
edition = "2021"
authors = ["Christopher Rabotin <[email protected]>"]
description = "A high-fidelity space mission toolkit, with orbit propagation, estimation and some systems engineering"
Expand Down Expand Up @@ -51,13 +51,14 @@ numpy = {version = "0.17", optional = true}
indicatif = {version = "0.17", features = ["rayon"]}
rstats = "1.2.39"
thiserror = "1.0"
parquet = "33.0.0"
arrow = "33.0.0"
parquet = "35.0.0"
arrow = "35.0.0"
shadow-rs = "0.21.0"
serde_yaml = "0.9.17"
whoami = "1.3.0"
either = {version = "1.8.1", features = ["serde"]}
num = "0.4.0"
enum-iterator = "1.4.0"

[build-dependencies]
shadow-rs = "0.21.0"
Expand Down
60 changes: 30 additions & 30 deletions src/cosmic/cosm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ impl Cosm {
// It will take less than three iterations to converge
for _ in 0..3 {
// Compute the light time
let lt = (tgt - obs).rmag() / SPEED_OF_LIGHT_KMS;
let lt = (tgt - obs).rmag_km() / SPEED_OF_LIGHT_KMS;
// Compute the new target state
let lt_dt = datetime - lt * Unit::Second;
tgt =
Expand All @@ -805,7 +805,7 @@ impl Cosm {

// Incluee the range-rate term in the velocity computation as explained in
// https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/abcorr.html#Reception%20case
let state_acc = state.velocity() / state.rmag();
let state_acc = state.velocity() / state.rmag_km();
let dltdt = state.radius().dot(&state_acc) / SPEED_OF_LIGHT_KMS;

state.vx_km_s = tgt.vx_km_s * (1.0 - dltdt) - obs.vx_km_s;
Expand Down Expand Up @@ -952,7 +952,7 @@ impl Cosm {
let state_ephem_path = state.frame.ephem_path();

// This doesn't make sense, but somehow the following algorithm only works when converting spacecraft states
let mut new_state = if state.rmag() > 0.0 {
let mut new_state = if state.rmag_km() > 0.0 {
*state
} else if state_ephem_path.is_empty() {
// SSB, let's invert this
Expand All @@ -967,7 +967,7 @@ impl Cosm {
let e_common_path = self.find_common_root(&new_ephem_path, &state_ephem_path);

// This doesn't make sense, but somehow the following algorithm only works when converting spacecraft states
new_state = if state.rmag() > 0.0 {
new_state = if state.rmag_km() > 0.0 {
// Walk backward from current state up to common node
for i in (e_common_path.len()..state_ephem_path.len()).rev() {
let next_state =
Expand Down Expand Up @@ -1242,8 +1242,8 @@ mod tests {
let sun2ear_state = cosm.celestial_state(&sun2k.ephem_path(), jde, eme2k, c);
let ear2sun_state = cosm.celestial_state(&eme2k.ephem_path(), jde, sun2k, c);
let state_sum = ear2sun_state + sun2ear_state;
assert!(state_sum.rmag() < 1e-8);
assert!(state_sum.vmag() < 1e-11);
assert!(state_sum.rmag_km() < 1e-8);
assert!(state_sum.vmag_km_s() < 1e-11);
}

#[test]
Expand Down Expand Up @@ -1281,12 +1281,12 @@ mod tests {
println!("{}", lro_wrt_moon);
let lro_moon_earth_delta = lro_jpl - lro_wrt_moon;
// Note that the passing conditions are large. JPL uses de431MX, but nyx uses de438s.
assert!(lro_moon_earth_delta.rmag() < 1e-2);
assert!(lro_moon_earth_delta.vmag() < 1e-5);
assert!(lro_moon_earth_delta.rmag_km() < 1e-2);
assert!(lro_moon_earth_delta.vmag_km_s() < 1e-5);
// And the converse
let lro_wrt_earth = cosm.frame_chg(&lro_wrt_moon, eme2k);
assert!((lro_wrt_earth - lro).rmag() < std::f64::EPSILON);
assert!((lro_wrt_earth - lro).vmag() < std::f64::EPSILON);
assert!((lro_wrt_earth - lro).rmag_km() < std::f64::EPSILON);
assert!((lro_wrt_earth - lro).vmag_km_s() < std::f64::EPSILON);
}

#[test]
Expand Down Expand Up @@ -1324,12 +1324,12 @@ mod tests {
println!("{}", lro_wrt_moon);
let lro_moon_earth_delta = lro_jpl - lro_wrt_moon;
// Note that the passing conditions are very large. JPL uses de431MX, but nyx uses de438s.
assert!(lro_moon_earth_delta.rmag() < 0.3);
assert!(lro_moon_earth_delta.vmag() < 1e-5);
assert!(lro_moon_earth_delta.rmag_km() < 0.3);
assert!(lro_moon_earth_delta.vmag_km_s() < 1e-5);
// And the converse
let lro_wrt_venus = cosm.frame_chg(&lro_wrt_moon, venus);
assert!((lro_wrt_venus - lro).rmag() < std::f64::EPSILON);
assert!((lro_wrt_venus - lro).vmag() < std::f64::EPSILON);
assert!((lro_wrt_venus - lro).rmag_km() < std::f64::EPSILON);
assert!((lro_wrt_venus - lro).vmag_km_s() < std::f64::EPSILON);
}

#[test]
Expand Down Expand Up @@ -1367,12 +1367,12 @@ mod tests {
println!("{}", lro_wrt_moon);
let lro_moon_earth_delta = lro_jpl - lro_wrt_moon;
// Note that the passing conditions are very large. JPL uses de431MX, but nyx uses de438s.
assert!(dbg!(lro_moon_earth_delta.rmag()) < 0.25);
assert!(dbg!(lro_moon_earth_delta.vmag()) < 1e-5);
assert!(dbg!(lro_moon_earth_delta.rmag_km()) < 0.25);
assert!(dbg!(lro_moon_earth_delta.vmag_km_s()) < 1e-5);
// And the converse
let lro_wrt_ssb = cosm.frame_chg(&lro_wrt_moon, ssb);
assert!((lro_wrt_ssb - lro).rmag() < std::f64::EPSILON);
assert!((lro_wrt_ssb - lro).vmag() < std::f64::EPSILON);
assert!((lro_wrt_ssb - lro).rmag_km() < std::f64::EPSILON);
assert!((lro_wrt_ssb - lro).vmag_km_s() < std::f64::EPSILON);
}

#[test]
Expand Down Expand Up @@ -1442,11 +1442,11 @@ mod tests {

// BUG: Temporarily allow for large error in rotation, will be fixed with #86.
assert!(
dbg!(ear_sun_2k.rmag() - ear_sun_iau.rmag()).abs() <= 1e-7,
dbg!(ear_sun_2k.rmag_km() - ear_sun_iau.rmag_km()).abs() <= 1e-7,
"a single rotation changes rmag"
);
assert!(
(ear_sun_2k_prime - ear_sun_2k).rmag() <= 1e-7,
(ear_sun_2k_prime - ear_sun_2k).rmag_km() <= 1e-7,
"reverse rotation does not match initial state"
);

Expand Down Expand Up @@ -1487,11 +1487,11 @@ mod tests {
println!("{}", delta_state);

assert!(
delta_state.rmag().abs() < 1e-11,
delta_state.rmag_km().abs() < 1e-11,
"Inverse rotation is broken"
);
assert!(
delta_state.vmag().abs() < 1e-11,
delta_state.vmag_km_s().abs() < 1e-11,
"Inverse rotation is broken"
);

Expand Down Expand Up @@ -1974,19 +1974,19 @@ mod tests {

println!(
"err: {} \t {}\nWas: {}\nIs: {}",
(moon_into_eme2k - sp_state_in_eme2k).rmag(),
(moon_into_eme2k - sp_state_in_eme2k).vmag(),
(moon_into_eme2k - sp_state_in_eme2k).rmag_km(),
(moon_into_eme2k - sp_state_in_eme2k).vmag_km_s(),
moon_state,
moon_into_eme2k
);
// SPICE only returns data down to the meter level, so we can't check less than that
assert!(
(moon_into_eme2k - sp_state_in_eme2k).rmag() < 1e-3,
(moon_into_eme2k - sp_state_in_eme2k).rmag_km() < 1e-3,
"error greater than expected"
);
// SPICE only returns data down to the millimeter per second level, so we can't check less than that
assert!(
(moon_into_eme2k - sp_state_in_eme2k).vmag() < 1e-6,
(moon_into_eme2k - sp_state_in_eme2k).vmag_km_s() < 1e-6,
"error greater than expected"
);

Expand Down Expand Up @@ -2021,20 +2021,20 @@ mod tests {

println!(
"err: {} \t {}\nWas: {}\nIs: {}",
(moon_into_eme2k - sp_state_in_eme2k).rmag(),
(moon_into_eme2k - sp_state_in_eme2k).vmag(),
(moon_into_eme2k - sp_state_in_eme2k).rmag_km(),
(moon_into_eme2k - sp_state_in_eme2k).vmag_km_s(),
moon_state,
moon_into_eme2k
);

// SPICE only returns data down to the meter level, so we can't check less than that
assert!(
(moon_into_eme2k - sp_state_in_eme2k).rmag() < 1e-3,
(moon_into_eme2k - sp_state_in_eme2k).rmag_km() < 1e-3,
"error greater than expected"
);
// SPICE only returns data down to the millimeter per second level, so we can't check less than that
assert!(
(moon_into_eme2k - sp_state_in_eme2k).vmag() < 1e-6,
(moon_into_eme2k - sp_state_in_eme2k).vmag_km_s() < 1e-6,
"error greater than expected"
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/cosmic/eclipse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ impl EventEvaluator<Orbit> for UmbraEvent {
fn value_precision(&self) -> f64 {
0.02
}

fn eval_string(&self, state: &Orbit) -> String {
format!("{}", self.e_loc.compute(state))
}
}

impl EventEvaluator<Spacecraft> for UmbraEvent {
Expand All @@ -209,6 +213,9 @@ impl EventEvaluator<Spacecraft> for UmbraEvent {
fn value_precision(&self) -> f64 {
0.02
}
fn eval_string(&self, state: &Spacecraft) -> String {
format!("{}", self.e_loc.compute(&state.orbit))
}
}

/// An event to find the start of a penumbra
Expand Down Expand Up @@ -239,6 +246,10 @@ impl EventEvaluator<Orbit> for PenumbraEvent {
fn value_precision(&self) -> f64 {
0.02
}

fn eval_string(&self, state: &Orbit) -> String {
format!("{}", self.e_loc.compute(state))
}
}

impl EventEvaluator<Spacecraft> for PenumbraEvent {
Expand All @@ -258,6 +269,10 @@ impl EventEvaluator<Spacecraft> for PenumbraEvent {
fn value_precision(&self) -> f64 {
0.02
}

fn eval_string(&self, state: &Spacecraft) -> String {
format!("{}", self.e_loc.compute(&state.orbit))
}
}

/// Computes the umbra/visibilis/penumbra state between between two states accounting for eclipsing of the providing geoid.
Expand Down
4 changes: 2 additions & 2 deletions src/cosmic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ where
}

/// Return the value of the parameter, returns an error by default
fn value(&self, _param: &StateParameter) -> Result<f64, NyxError> {
fn value(&self, _param: StateParameter) -> Result<f64, NyxError> {
Err(NyxError::StateParameterUnavailable)
}

/// Allows setting the value of the given parameter.
/// NOTE: Most parameters where the `value` is available CANNOT be also set for that parameter (it's a much harder problem!)
fn set_value(&mut self, _param: &StateParameter, _val: f64) -> Result<(), NyxError> {
fn set_value(&mut self, _param: StateParameter, _val: f64) -> Result<(), NyxError> {
Err(NyxError::StateParameterUnavailable)
}
}
Expand Down
Loading

0 comments on commit 07634ab

Please sign in to comment.