Skip to content

TDB/TT: add new test#452

Draft
gwbres wants to merge 1 commit intomasterfrom
tdb_tt
Draft

TDB/TT: add new test#452
gwbres wants to merge 1 commit intomasterfrom
tdb_tt

Conversation

@gwbres
Copy link
Collaborator

@gwbres gwbres commented Jan 19, 2026

Hello,

I'm trying to write one or two more tests for TDB and TT to demonstrate that everything works correctly.

TDB is TT with relativistic corrections, which are very small, so they should be very close but not the same.
I read that |TDB-TT| should be at most 1.6ms at all times.
Also, the expected behavior is that the distance should oscillate around zero, over the course of an entire year.

In the second test test_tdb_tt_mean_is_zero I can see that the gap between both is always zero, which is incorrect to me right ?
That test also "passes", because the mean is then obviously zero.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gwbres, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces two new tests designed to rigorously validate the relativistic corrections applied when converting between Terrestrial Time (TT) and Barycentric Dynamical Time (TDB) within the hifitime library. The primary goal is to ensure that the library accurately models the expected small, oscillating differences between these two time scales, specifically checking the maximum deviation and the annual mean difference. The author has raised a question regarding the unexpected passing of one of the new tests, suggesting a potential area for further investigation or clarification.

Highlights

  • New TDB/TT Tests: Two new tests have been added to tests/epoch.rs to validate the relationship and behavior of Barycentric Dynamical Time (TDB) and Terrestrial Time (TT) time scales.
  • TDB-TT Distance Verification: The test_tdb_tt_distance function verifies that the absolute difference between TDB and TT remains within the expected limit of 1.6 milliseconds, iterating over a century of epochs.
  • TDB-TT Mean Oscillation Check: The test_tdb_tt_mean_is_zero function attempts to confirm that the mean difference between TDB and TT oscillates around zero over the course of an entire year, also iterating through a century of annual periods.
  • TimeSeries Import: The TimeSeries struct has been imported into tests/epoch.rs to facilitate the generation of epoch series for these new tests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.02%. Comparing base (501f3a0) to head (684a220).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #452   +/-   ##
=======================================
  Coverage   83.02%   83.02%           
=======================================
  Files          23       23           
  Lines        3570     3570           
=======================================
  Hits         2964     2964           
  Misses        606      606           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds two tests to verify the relationship between TDB and TT time scales. My review focuses on the correctness of these new tests.

In test_tdb_tt_distance, I found an issue with the assertion logic that checks if the difference is within the 1.6ms bound. I've suggested a more direct and correct way to perform this check.

More importantly, in test_tdb_tt_mean_is_zero, I've identified a critical flaw in the test logic, which you also suspected in the PR description. The test incorrectly calculates the mean of the absolute differences and asserts it to be zero, which can lead to a false positive and hide potential bugs in the time scale conversion. I've proposed a rewrite of this test to correctly verify that the TDB-TT difference oscillates around zero and that its mean is negligible, which will help in identifying if the difference is unexpectedly always zero.

Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
@gwbres gwbres force-pushed the tdb_tt branch 2 times, most recently from 33e7966 to 7873833 Compare January 19, 2026 07:47

// The difference should not be consistently zero, it should oscillate.
assert!(
min < 0.0 && max > 0.0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a dbg!(min) and dbg!(max) here to check what the error is.

@ChristopherRabotin
Copy link
Member

I didn't know that TT and TDB were supposed to be within 1.6 ms of each other. How big of an error are you seeing ? Could you try with the ET time scale since that's a simpler computation of TDB, and maybe it should also be with 1.6 ms ? If the test still fails, would it make sense to increase the granularity of the time series from one sample per year to one sample every 3-4 months? Maybe the oscillation happens at a higher frequency.

@gwbres
Copy link
Collaborator Author

gwbres commented Jan 20, 2026

I didn't know that TT and TDB were supposed to be within 1.6 ms of each other. How big of an error are you seeing ?

That's the thing, I have not been able to observe a time difference between TT and TDB so far

Could you try with the ET time scale since that's a simpler computation of TDB, and maybe it should also be with 1.6 ms ?

I'm not familiar with ET (😅) I will look into it

@gwbres
Copy link
Collaborator Author

gwbres commented Jan 20, 2026

To be exact, 1.6ms is the amplitude of the oscillation of TT around TDB.

As you know TDB is thoughtout at the mass center of the Sun. The variation between both timescales, comes from Earth rotation around the earth, and the "Shapiro" effect, due to variations in the gravitational interaction along the entire rotation.

The definition of TDB (which is correctly implemented by this library) is the following,

$$TDB \approx TT + 0,001658 \times \sin(g)$$

which is actually a convention not the true physical time. The true physical time, is this value + 0.5s per year (drift). By convention, we "cancel" this drift to keep TDB close to TT for practical reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants