Skip to content

Introduce the TDB scale#13

Merged
rhannequin merged 3 commits into
mainfrom
tdb-scale
Jul 22, 2026
Merged

Introduce the TDB scale#13
rhannequin merged 3 commits into
mainfrom
tdb-scale

Conversation

@rhannequin

Copy link
Copy Markdown
Owner

This adds Barycentric Dynamical Time, the scale the planetary ephemerides are written in. It is the third Astronoby-critical scale, after TAI and TT, and the first one that comes from a model rather than a constant offset.

instant = Horologium::Instant.from_julian_date(2_460_796.5, scale: :tt)

instant.to(:tdb).as(:julian_date)
# => 2460796.5000000168

TDB keeps almost the rate of TT, apart from periodic relativistic terms worth at most about two milliseconds, from the Earth's motion through the Sun's gravity. Scales::TDB reads TAI in TT first, a fixed 32.184 seconds, then adds the TDB - TT difference Data::BarycentricModel gives.

Data::BarycentricModel is the full Fairhead & Bretagnon (1990) series that ERFA and astropy use, ported from ERFA's dtdb.c. The value is geocentric: the part of the model that depends on where on the Earth the observer stands is a few microseconds, and is left out. It agrees with pyerfa to about a nanosecond.

The difference is a floating-point model, so unlike TAI and TT this edge is not exact, even at :exact. The model reads the date as a Float; at :exact its result is stored faithfully as a Rational, but the model itself stays a float computation. :exact keeps the arithmetic that follows it, not the model.

UTC and the civil representations come next.

This adds Barycentric Dynamical Time, the scale the planetary ephemerides
are written in. It is the third Astronoby-critical scale, after TAI and TT,
and the first one that comes from a model rather than a constant offset.

```rb
instant = Horologium::Instant.from_julian_date(2_460_796.5, scale: :tt)

instant.to(:tdb).as(:julian_date)
# => 2460796.5000000168
```

TDB keeps almost the rate of TT, apart from periodic relativistic terms
worth at most about two milliseconds, from the Earth's motion through the
Sun's gravity. `Scales::TDB` reads TAI in TT first, a fixed 32.184 seconds,
then adds the TDB - TT difference `Data::BarycentricModel` gives.

`Data::BarycentricModel` is the full Fairhead & Bretagnon (1990) series that
ERFA and astropy use, ported from ERFA's `dtdb.c`. The value is geocentric:
the part of the model that depends on where on the Earth the observer stands
is a few microseconds, and is left out. It agrees with pyerfa to about a
nanosecond.

The difference is a floating-point model, so unlike TAI and TT this edge is
not exact, even at `:exact`. The model reads the date as a `Float`; at
`:exact` its result is stored faithfully as a `Rational`, but the model
itself stays a float computation. `:exact` keeps the arithmetic that follows
it, not the model.

UTC and the civil representations come next.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for the TDB (Barycentric Dynamical Time) time scale to Horologium, including a port of the Fairhead & Bretagnon (1990) TDB−TT series (as used by ERFA/astropy) and wiring it into the scale registry so instants can be converted to/from :tdb.

Changes:

  • Add Horologium::Data::BarycentricModel implementing the Fairhead & Bretagnon series for TDB - TT.
  • Add Horologium::Scales::TDB and register it as a built-in scale, including top-level requires.
  • Add test coverage and RBS signatures for the new model and scale.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/test_configuration.rb Updates expectations for registered scale lists to include :tdb.
test/scales/test_tdb.rb Adds scale-level tests for registration, conversion behavior, and precision handling.
test/data/test_barycentric_model.rb Adds model-level tests comparing tdb_minus_tt against reference values and bounds.
sig/horologium/scales/tdb.rbs Adds RBS for the new Scales::TDB API surface.
sig/horologium/data/barycentric_model.rbs Adds RBS for the new barycentric model module and helpers/constants.
lib/horologium/scales/tdb.rb Implements the TDB scale conversion via TT plus model correction.
lib/horologium/data/barycentric_model.rb Implements the full Fairhead & Bretagnon (1990) series ported from ERFA.
lib/horologium/configuration.rb Registers :tdb as a built-in scale.
lib/horologium.rb Requires the new model and scale files for library initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/horologium/scales/tdb.rb Outdated
@rhannequin
rhannequin merged commit 2557778 into main Jul 22, 2026
44 checks passed
@rhannequin
rhannequin deleted the tdb-scale branch July 22, 2026 19:37
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