Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Dec 31, 2024
1 parent ff2bc30 commit 462a062
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 53 deletions.
103 changes: 53 additions & 50 deletions crates/lox-time/src/time_scales/offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ where
DynTimeScale::Tcb => Ok(Tdb.offset(Tcb, dt)),
DynTimeScale::Tcg => Ok(Tdb.offset(Tcg, dt)),
DynTimeScale::Tdb => Ok(TimeDelta::default()),
DynTimeScale::Tt => Ok(Tt.offset(Tai, dt)),
DynTimeScale::Tt => Ok(Tdb.offset(Tt, dt)),
DynTimeScale::Ut1 => Tdb.try_offset(Ut1, dt, provider),
},
DynTimeScale::Tt => match scale {
Expand Down Expand Up @@ -585,13 +585,13 @@ where

#[cfg(test)]
mod tests {
use float_eq::assert_float_eq;
use rstest::rstest;

use crate::{
calendar_dates::Date, deltas::ToDelta, test_helpers::delta_ut1_tai, time_of_day::TimeOfDay,
DynTime,
};
use lox_math::is_close::IsClose;

use super::*;

Expand All @@ -601,50 +601,60 @@ mod tests {
assert_eq!(Tai.offset(Tt, dt), Tt.offset_from(Tai, dt))
}

const DEFAULT_TOL: f64 = 1e-7;
const UT1_TOL: f64 = 1e-2;
const TCB_TOL: f64 = 1e-5;

// Reference values from Orekit
//
// Since we use different algorithms for TCB and UT1 we need to
// adjust the tolerances accordingly.
//
#[rstest]
#[case::tai_tai("TAI", "TAI", 0.0, 0.0)]
#[case::tai_tcb("TAI", "TCB", 55.66851419888016, -55.66851419888016)]
#[case::tai_tcg("TAI", "TCG", 33.239589335894145, -33.239589335894145)]
#[case::tai_tdb("TAI", "TDB", 32.183882324981056, -32.183882324981056)]
#[case::tai_tt("TAI", "TT", 32.184, -32.184)]
#[case::tai_ut1("TAI", "UT1", -36.949521832072996, 36.949521832072996)]
#[case::tcb_tai("TCB", "TAI", -55.668513317090046, 55.668513317090046)]
#[case::tcb_tcb("TCB", "TCB", 0.0, 0.0)]
#[case::tcb_tcg("TCB", "TCG", -22.4289240199929, 22.4289240199929)]
#[case::tcb_tdb("TCB", "TDB", -23.484631010747805, 23.484631010747805)]
#[case::tcb_tt("TCB", "TT", -23.484513317090048, 23.484513317090048)]
#[case::tcb_ut1("TCB", "UT1", -92.61803559995818, 92.61803559995818)]
#[case::tcg_tai("TCG", "TAI", -33.23958931272851, 33.23958931272851)]
#[case::tcg_tcb("TCG", "TCB", 22.428924359636042, -22.428924359636042)]
#[case::tcg_tcg("TCG", "TCG", 0.0, 0.0)]
#[case::tcg_tdb("TCG", "TDB", -1.0557069988766656, 1.0557069988766656)]
#[case::tcg_tt("TCG", "TT", -1.0555893127285145, 1.0555893127285145)]
#[case::tcg_ut1("TCG", "UT1", -70.1891114139689, 70.1891114139689)]
#[case::tdb_tai("TDB", "TAI", -32.18388231420531, 32.18388231420531)]
#[case::tdb_tcb("TDB", "TCB", 23.48463137488165, -23.48463137488165)]
#[case::tdb_tcg("TDB", "TCG", 1.0557069992589518, -1.0557069992589518)]
#[case::tdb_tdb("TDB", "TDB", 0.0, 0.0)]
#[case::tdb_tt("TDB", "TT", 1.176857946845189E-4, -1.176857946845189E-4)]
#[case::tdb_ut1("TDB", "UT1", -69.13340440689674, 69.13340440689674)]
#[case::tt_tai("TT", "TAI", -32.184, 32.184)]
#[case::tt_tcb("TT", "TCB", 23.484513689085105, -23.484513689085105)]
#[case::tt_tcg("TT", "TCG", 1.055589313464182, -1.055589313464182)]
#[case::tt_tdb("TT", "TDB", -1.1768579472004603E-4, 1.1768579472004603E-4)]
#[case::tt_tt("TT", "TT", 0.0, 0.0)]
#[case::tt_ut1("TT", "UT1", -69.13352209269237, 69.13352209269237)]
#[case::ut1_tai("UT1", "TAI", 36.949521532869305, -36.949521532869305)]
#[case::ut1_tcb("UT1", "TCB", 92.61803631703046, -92.61803631703046)]
#[case::ut1_tcg("UT1", "TCG", 70.18911089451464, -70.18911089451464)]
#[case::ut1_tdb("UT1", "TDB", 69.13340387022173, -69.13340387022173)]
#[case::ut1_tt("UT1", "TT", 69.13352153286931, -69.13352153286931)]
#[case::ut1_ut1("UT1", "UT1", 0.0, 0.0)]
#[case::tai_tai("TAI", "TAI", 0.0, None)]
#[case::tai_tcb("TAI", "TCB", 55.66851419888016, Some(TCB_TOL))]
#[case::tai_tcg("TAI", "TCG", 33.239589335894145, None)]
#[case::tai_tdb("TAI", "TDB", 32.183882324981056, None)]
#[case::tai_tt("TAI", "TT", 32.184, None)]
#[case::tai_ut1("TAI", "UT1", -36.949521832072996, Some(UT1_TOL))]
#[case::tcb_tai("TCB", "TAI", -55.668513317090046, Some(TCB_TOL))]
#[case::tcb_tcb("TCB", "TCB", 0.0, Some(TCB_TOL))]
#[case::tcb_tcg("TCB", "TCG", -22.4289240199929, Some(TCB_TOL))]
#[case::tcb_tdb("TCB", "TDB", -23.484631010747805, Some(TCB_TOL))]
#[case::tcb_tt("TCB", "TT", -23.484513317090048, Some(TCB_TOL))]
#[case::tcb_ut1("TCB", "UT1", -92.61803559995818, Some(UT1_TOL))]
#[case::tcg_tai("TCG", "TAI", -33.23958931272851, None)]
#[case::tcg_tcb("TCG", "TCB", 22.428924359636042, Some(TCB_TOL))]
#[case::tcg_tcg("TCG", "TCG", 0.0, None)]
#[case::tcg_tdb("TCG", "TDB", -1.0557069988766656, None)]
#[case::tcg_tt("TCG", "TT", -1.0555893127285145, None)]
#[case::tcg_ut1("TCG", "UT1", -70.1891114139689, Some(UT1_TOL))]
#[case::tdb_tai("TDB", "TAI", -32.18388231420531, None)]
#[case::tdb_tcb("TDB", "TCB", 23.48463137488165, Some(TCB_TOL))]
#[case::tdb_tcg("TDB", "TCG", 1.0557069992589518, None)]
#[case::tdb_tdb("TDB", "TDB", 0.0, None)]
#[case::tdb_tt("TDB", "TT", 1.176857946845189E-4, None)]
#[case::tdb_ut1("TDB", "UT1", -69.13340440689674, Some(UT1_TOL))]
#[case::tt_tai("TT", "TAI", -32.184, None)]
#[case::tt_tcb("TT", "TCB", 23.484513689085105, Some(TCB_TOL))]
#[case::tt_tcg("TT", "TCG", 1.055589313464182, None)]
#[case::tt_tdb("TT", "TDB", -1.1768579472004603E-4, None)]
#[case::tt_tt("TT", "TT", 0.0, None)]
#[case::tt_ut1("TT", "UT1", -69.13352209269237, Some(UT1_TOL))]
#[case::ut1_tai("UT1", "TAI", 36.949521532869305, Some(UT1_TOL))]
#[case::ut1_tcb("UT1", "TCB", 92.61803631703046, Some(UT1_TOL))]
#[case::ut1_tcg("UT1", "TCG", 70.18911089451464, Some(UT1_TOL))]
#[case::ut1_tdb("UT1", "TDB", 69.13340387022173, Some(UT1_TOL))]
#[case::ut1_tt("UT1", "TT", 69.13352153286931, Some(UT1_TOL))]
#[case::ut1_ut1("UT1", "UT1", 0.0, Some(UT1_TOL))]
fn test_dyn_time_scale_offsets(
#[case] scale1: &str,
#[case] scale2: &str,
#[case] exp1: f64,
#[case] exp2: f64,
#[case] exp: f64,
#[case] tol: Option<f64>,
) {
let tolerance = 1e-6;
use lox_math::assert_close;

let provider = Some(delta_ut1_tai());
let scale1: DynTimeScale = scale1.parse().unwrap();
let scale2: DynTimeScale = scale2.parse().unwrap();
Expand All @@ -653,17 +663,10 @@ mod tests {
let dt = DynTime::from_date_and_time(scale1, date, time)
.unwrap()
.to_delta();
let act1 = scale1
let act = scale1
.try_offset(scale2, dt, provider)
.unwrap()
.to_decimal_seconds();
let act2 = scale2
.try_offset(scale1, dt, provider)
.unwrap()
.to_decimal_seconds();
assert_float_eq!(exp1.abs(), exp2.abs(), rel <= tolerance);
assert_float_eq!(act1.abs(), act2.abs(), rel <= tolerance);
assert_float_eq!(act1, exp1, rel <= tolerance);
assert_float_eq!(act2, exp2, rel <= tolerance);
assert_close!(act, exp, 1e-7, tol.unwrap_or(DEFAULT_TOL));
}
}
7 changes: 4 additions & 3 deletions crates/lox-time/src/ut1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ impl DeltaUt1TaiProvider for DeltaUt1Tai {
let (t0, _) = self.0.first();
let (tn, _) = self.0.last();
// Use the UT1 offset as an initial guess even though the table is based on TAI
let mut val = self.0.interpolate(seconds);
let mut val = 0.0;
// Interpolate again with the adjusted offsets
for _ in 0..2 {
val = self.0.interpolate(seconds - val);
for _ in 0..3 {
val = self.0.interpolate(seconds + val);
dbg!(val);
}
if seconds < t0 || seconds > tn {
return Err(ExtrapolatedDeltaUt1Tai::new(t0, tn, seconds, -val));
Expand Down

0 comments on commit 462a062

Please sign in to comment.