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

Fix transformation when it involved multi-barycenter hops #306

Merged
merged 3 commits into from
Aug 28, 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
1 change: 1 addition & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
wget -O data/variable-seg-size-hermite.bsp http://public-data.nyxspace.com/anise/ci/variable-seg-size-hermite.bsp
wget -O data/earth_latest_high_prec.bpc http://public-data.nyxspace.com/anise/ci/earth_latest_high_prec-2023-09-08.bpc
wget -O data/lro.bsp http://public-data.nyxspace.com/nyx/examples/lrorg_2023349_2024075_v01_LE.bsp

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
wget -O data/variable-seg-size-hermite.bsp http://public-data.nyxspace.com/anise/ci/variable-seg-size-hermite.bsp
wget -O data/earth_latest_high_prec.bpc http://public-data.nyxspace.com/anise/ci/earth_latest_high_prec-2023-09-08.bpc
wget -O data/lro.bsp http://public-data.nyxspace.com/nyx/examples/lrorg_2023349_2024075_v01_LE.bsp

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
Expand Down Expand Up @@ -111,6 +112,7 @@ jobs:
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
wget -O data/variable-seg-size-hermite.bsp http://public-data.nyxspace.com/anise/ci/variable-seg-size-hermite.bsp
wget -O data/earth_latest_high_prec.bpc http://public-data.nyxspace.com/anise/ci/earth_latest_high_prec-2023-09-08.bpc
wget -O data/lro.bsp http://public-data.nyxspace.com/nyx/examples/lrorg_2023349_2024075_v01_LE.bsp

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
Expand Down Expand Up @@ -179,6 +181,7 @@ jobs:
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
wget -O data/variable-seg-size-hermite.bsp http://public-data.nyxspace.com/anise/ci/variable-seg-size-hermite.bsp
wget -O data/earth_latest_high_prec.bpc http://public-data.nyxspace.com/anise/ci/earth_latest_high_prec-2023-09-08.bpc
wget -O data/lro.bsp http://public-data.nyxspace.com/nyx/examples/lrorg_2023349_2024075_v01_LE.bsp

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ cspice.tar.Z
*.epa
anise-gui/dist/
anise-py/notebooks/.ipynb_checkpoints/ANISE Tutorial for querying SPK files-checkpoint.ipynb
data/lro.bsp
6 changes: 5 additions & 1 deletion anise/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ fn main() {

// Create the directory if it doesn't exist
if !data_path.exists() {
fs::create_dir_all(&data_path).expect(&format!("failed to create directory {data_path:?}"));
if let Err(e) = fs::create_dir_all(&data_path) {
eprintln!("EMBEDDED EPHEM UNAVAILABLE: failed to create directory {data_path:?}");
// Try nothing else.
return;
}
}

for (url, dest_path) in embedded_files {
Expand Down
6 changes: 3 additions & 3 deletions anise/src/ephemerides/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ impl Almanac {
return Ok((items, common_path, to_frame.ephemeris_id));
}

common_path[items] = Some(from_obj.unwrap());
items += 1;

if from_obj == to_obj {
// This is where the paths branch meet, so the root is the parent of the current item.
// Recall that the path is _from_ the source to the root of the context, so we're walking them
// backward until we find "where" the paths branched out.
return Ok((items, common_path, to_obj.unwrap()));
} else {
common_path[items] = Some(from_obj.unwrap());
items += 1;
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions anise/src/ephemerides/translations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Almanac {

match ab_corr {
None => {
let (node_count, path, common_node) =
let (node_count, _path, common_node) =
self.common_ephemeris_path(observer_frame, target_frame, epoch)?;

// The fwrd variables are the states from the `from frame` to the common node
Expand All @@ -85,7 +85,7 @@ impl Almanac {
self.translation_parts_to_parent(target_frame, epoch)?
};

for cur_node_id in path.iter().take(node_count) {
for _ in 0..node_count {
if !frame_fwrd.ephem_origin_id_match(common_node) {
let (cur_pos_fwrd, cur_vel_fwrd, cur_frame_fwrd) =
self.translation_parts_to_parent(frame_fwrd, epoch)?;
Expand All @@ -103,11 +103,6 @@ impl Almanac {
vel_bwrd += cur_vel_bwrd;
frame_bwrd = cur_frame_bwrd;
}

// We know this exist, so we can safely unwrap it
if cur_node_id.unwrap() == common_node {
break;
}
}

Ok(CartesianState {
Expand Down
53 changes: 52 additions & 1 deletion anise/tests/ephemerides/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Documentation: https://nyxspace.com/
*/

use anise::constants::frames::{EARTH_ITRF93, IAU_MOON_FRAME, MOON_J2000, VENUS_J2000};
use anise::constants::frames::{EARTH_ITRF93, IAU_MOON_FRAME, MOON_J2000, SUN_J2000, VENUS_J2000};
use anise::math::Vector3;
use anise::prelude::*;

Expand Down Expand Up @@ -192,3 +192,54 @@ fn spice_verif_iau_moon() {
assert!(rss_pos_km < 0.004);
assert!(rss_vel_km_s < 1e-5);
}

#[test]
fn gh_283_multi_barycenter() {
let almanac = MetaAlmanac::default()
.process(true)
.unwrap()
.load("../data/lro.bsp")
.unwrap();

const LRO_ID: i32 = -85;
let lro_frame = Frame::from_ephem_j2000(LRO_ID);

let epoch = Epoch::from_gregorian_utc_at_midnight(2024, 1, 1);

// First, let's test that the common ephemeris path is correct
let (node_count, path, common_node) = almanac
.common_ephemeris_path(lro_frame, SUN_J2000, epoch)
.unwrap();

assert_eq!(common_node, 0, "common node should be the SSB");
assert_eq!(node_count, 3, "node count should be Moon, EMB, SSB");
assert_eq!(
path,
[Some(301), Some(3), Some(0), None, None, None, None, None,],
"node count should be Moon, EMB, SSB"
);

let spice_lro_state = Orbit::new(
-25181236.12671419,
133176946.34310651,
57755823.14607649,
-31.33683951,
-4.57447104,
-1.6316696,
epoch,
SUN_J2000,
);

let anise_lro_state = almanac
.transform(lro_frame, SUN_J2000, epoch, None)
.unwrap();

println!("ANISE\n{anise_lro_state}\nSPICE\n{spice_lro_state}");
let rss_pos_km = anise_lro_state.rss_radius_km(&spice_lro_state).unwrap();
let rss_vel_km_s = anise_lro_state.rss_velocity_km_s(&spice_lro_state).unwrap();

dbg!(rss_pos_km, rss_vel_km_s);

assert!(rss_pos_km < f64::EPSILON);
assert!(rss_vel_km_s < 1e-8);
}
Loading