Skip to content

Commit a28d790

Browse files
Merge pull request #321 from nyx-space/320-support-spk-type-3-chebyshev-position-and-velocity
Support SPK Type 3 chebyshev position and velocity
2 parents 4fbd5b5 + 91bdc93 commit a28d790

File tree

11 files changed

+497
-48
lines changed

11 files changed

+497
-48
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
wget -O data/de430.bsp http://public-data.nyxspace.com/anise/de430.bsp
4444
wget -O data/de440s.bsp http://public-data.nyxspace.com/anise/de440s.bsp
4545
wget -O data/de440.bsp http://public-data.nyxspace.com/anise/de440.bsp
46+
wget -O data/de440_type3.bsp http://public-data.nyxspace.com/anise/de440_type3.bsp
4647
wget -O data/pck08.pca http://public-data.nyxspace.com/anise/v0.4/pck08.pca
4748
wget -O data/pck11.pca http://public-data.nyxspace.com/anise/v0.4/pck11.pca
4849
wget -O data/moon_fk.epa http://public-data.nyxspace.com/anise/v0.4/moon_fk.epa
@@ -112,6 +113,7 @@ jobs:
112113
wget -O data/de430.bsp http://public-data.nyxspace.com/anise/de430.bsp
113114
wget -O data/de440s.bsp http://public-data.nyxspace.com/anise/de440s.bsp
114115
wget -O data/de440.bsp http://public-data.nyxspace.com/anise/de440.bsp
116+
wget -O data/de440_type3.bsp http://public-data.nyxspace.com/anise/de440_type3.bsp
115117
wget -O data/pck08.pca http://public-data.nyxspace.com/anise/v0.4/pck08.pca
116118
wget -O data/pck11.pca http://public-data.nyxspace.com/anise/v0.4/pck11.pca
117119
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
@@ -182,6 +184,7 @@ jobs:
182184
wget -O data/de430.bsp http://public-data.nyxspace.com/anise/de430.bsp
183185
wget -O data/de440s.bsp http://public-data.nyxspace.com/anise/de440s.bsp
184186
wget -O data/de440.bsp http://public-data.nyxspace.com/anise/de440.bsp
187+
wget -O data/de440_type3.bsp http://public-data.nyxspace.com/anise/de440_type3.bsp
185188
wget -O data/pck08.pca http://public-data.nyxspace.com/anise/v0.4/pck08.pca
186189
wget -O data/pck11.pca http://public-data.nyxspace.com/anise/v0.4/pck11.pca
187190
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
@@ -214,6 +217,7 @@ jobs:
214217
cargo llvm-cov test --no-report validate_bpc_to_iau_rotations -- --nocapture --ignored
215218
cargo llvm-cov test --no-report validate_jplde_de440s_no_aberration --features spkezr_validation -- --nocapture --ignored
216219
cargo llvm-cov test --no-report validate_jplde_de440s_aberration_lt --features spkezr_validation -- --nocapture --ignored
220+
cargo llvm-cov test --no-report validate_jplde_de440_type3_no_aberration --features spkezr_validation -- --nocapture --ignored
217221
cargo llvm-cov test --no-report validate_hermite_type13_from_gmat --features spkezr_validation -- --nocapture --ignored
218222
cargo llvm-cov test --no-report validate_lagrange_type9_with_varying_segment_sizes --features spkezr_validation -- --nocapture --ignored
219223
cargo llvm-cov test --no-report ut_embed --features embed_ephem

anise/src/ephemerides/translate_to_parent.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use crate::ephemerides::EphemInterpolationSnafu;
1717
use crate::hifitime::Epoch;
1818
use crate::math::cartesian::CartesianState;
1919
use crate::math::Vector3;
20-
use crate::naif::daf::datatypes::{HermiteSetType13, LagrangeSetType9, Type2ChebyshevSet};
20+
use crate::naif::daf::datatypes::{
21+
HermiteSetType13, LagrangeSetType9, Type2ChebyshevSet, Type3ChebyshevSet,
22+
};
2123
use crate::naif::daf::{DAFError, DafDataType, NAIFDataSet, NAIFSummaryRecord};
2224
use crate::prelude::Frame;
2325

@@ -64,6 +66,16 @@ impl Almanac {
6466
data.evaluate(epoch, summary)
6567
.context(EphemInterpolationSnafu)?
6668
}
69+
DafDataType::Type3ChebyshevSextuplet => {
70+
let data =
71+
spk_data
72+
.nth_data::<Type3ChebyshevSet>(idx_in_spk)
73+
.context(SPKSnafu {
74+
action: "fetching data for interpolation",
75+
})?;
76+
data.evaluate(epoch, summary)
77+
.context(EphemInterpolationSnafu)?
78+
}
6779
DafDataType::Type9LagrangeUnequalStep => {
6880
let data = spk_data
6981
.nth_data::<LagrangeSetType9>(idx_in_spk)

anise/src/math/interpolation/chebyshev.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,33 @@ pub fn chebyshev_eval(
5757
let deriv = (w[0] + normalized_time * dw[0] - dw[1]) / spline_radius_s;
5858
Ok((val, deriv))
5959
}
60+
61+
/// Attempts to evaluate a Chebyshev polynomial given the coefficients, returning only the value
62+
///
63+
/// # Notes
64+
/// 1. At this point, the splines are expected to be in Chebyshev format and no verification is done.
65+
pub fn chebyshev_eval_poly(
66+
normalized_time: f64,
67+
spline_coeffs: &[f64],
68+
eval_epoch: Epoch,
69+
degree: usize,
70+
) -> Result<f64, InterpolationError> {
71+
// Workspace array
72+
let mut w = [0.0_f64; 3];
73+
74+
for j in (2..=degree + 1).rev() {
75+
w[2] = w[1];
76+
w[1] = w[0];
77+
w[0] = (spline_coeffs
78+
.get(j - 1)
79+
.ok_or(InterpolationError::MissingInterpolationData { epoch: eval_epoch })?)
80+
+ (2.0 * normalized_time * w[1] - w[2]);
81+
}
82+
83+
let val = (spline_coeffs
84+
.first()
85+
.ok_or(InterpolationError::MissingInterpolationData { epoch: eval_epoch })?)
86+
+ (normalized_time * w[0]);
87+
88+
Ok(val)
89+
}

anise/src/math/interpolation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod chebyshev;
1212
mod hermite;
1313
mod lagrange;
1414

15-
pub use chebyshev::chebyshev_eval;
15+
pub use chebyshev::{chebyshev_eval, chebyshev_eval_poly};
1616
pub use hermite::hermite_eval;
1717
use hifitime::Epoch;
1818
pub use lagrange::lagrange_eval;

anise/src/naif/daf/datatypes/chebyshev.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -271,51 +271,6 @@ impl<'a> NAIFDataRecord<'a> for Type2ChebyshevRecord<'a> {
271271
}
272272
}
273273

274-
#[derive(PartialEq)]
275-
pub struct Type3ChebyshevRecord<'a> {
276-
pub midpoint: Epoch,
277-
pub radius: Duration,
278-
pub x_coeffs: &'a [f64],
279-
pub y_coeffs: &'a [f64],
280-
pub z_coeffs: &'a [f64],
281-
pub vx_coeffs: &'a [f64],
282-
pub vy_coeffs: &'a [f64],
283-
pub vz_coeffs: &'a [f64],
284-
}
285-
286-
impl<'a> fmt::Display for Type3ChebyshevRecord<'a> {
287-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
288-
write!(
289-
f,
290-
"start: {}\tend: {}\nx: {:?}\ny: {:?}\nz: {:?}\nvx: {:?}\nvy: {:?}\nvz: {:?}",
291-
self.midpoint - self.radius,
292-
self.midpoint + self.radius,
293-
self.x_coeffs,
294-
self.y_coeffs,
295-
self.z_coeffs,
296-
self.vx_coeffs,
297-
self.vy_coeffs,
298-
self.vz_coeffs
299-
)
300-
}
301-
}
302-
303-
impl<'a> NAIFDataRecord<'a> for Type3ChebyshevRecord<'a> {
304-
fn from_slice_f64(slice: &'a [f64]) -> Self {
305-
let num_coeffs = (slice.len() - 2) / 6;
306-
Self {
307-
midpoint: Epoch::from_et_seconds(slice[0]),
308-
radius: slice[1].seconds(),
309-
x_coeffs: &slice[2..num_coeffs],
310-
y_coeffs: &slice[2 + num_coeffs..num_coeffs * 2],
311-
z_coeffs: &slice[2 + num_coeffs * 2..num_coeffs * 3],
312-
vx_coeffs: &slice[2 + num_coeffs * 3..num_coeffs * 4],
313-
vy_coeffs: &slice[2 + num_coeffs * 4..num_coeffs * 5],
314-
vz_coeffs: &slice[2 + num_coeffs * 5..],
315-
}
316-
}
317-
}
318-
319274
#[cfg(test)]
320275
mod chebyshev_ut {
321276
use crate::{

0 commit comments

Comments
 (0)