Skip to content

Parse MPC Epoch & Tp values as TT instead of UTC#110

Merged
dahlend merged 4 commits into
dahlend:mainfrom
dschlekat:fix/mpc-tt-epochs
May 29, 2026
Merged

Parse MPC Epoch & Tp values as TT instead of UTC#110
dahlend merged 4 commits into
dahlend:mainfrom
dschlekat:fix/mpc-tt-epochs

Conversation

@dschlekat
Copy link
Copy Markdown
Contributor

Fixes #109 .

This PR updates MPC asteroid/comet orbit parsing so that epoch and Tp is interpreted as TT, matching the MPC orbit-element specifications.

Previously these fields were parsed as UTC, which shifted epoch and peri_time later by TT−UTC before conversion to kete's internal JD time representation. For current MPCORB rows this is about 69.184 seconds.

Changes:

  • Parse MPC asteroid Epoch and Tp as TT, as documented in the MPCORB manual.
  • Apply the same correction to comet orbit parsing, which required adding scaling to the Time.from_ymd method, to ensure backwards compatibility for previous UTC-only functionality.
  • Add a regression test confirming that MPC JD-TT epochs are preserved.
  • Updated the leap_second.dat file (only changes are the number/date of the IERS Bulletin and the file expiration date).

All tests pass with the command

pytest --cov-report term-missing --cov=kete

Comment thread src/kete/rust/time.rs Outdated
/// The Month as an integer, 0 = January etc.
/// day:
/// The day as an integer or float.
/// scaling:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Unless you have a strong argument for adding this, this a major footgun for users.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't, it was to maintain the Time.from_ymd() method used in the mpc.py file. I agree with your comment about it being a major footgun.

Upon reflection it would be easier (and far less invasive) to parse the YMD data from the MPC comet file to JD, then create a Time object from that with "TT" scaling.

…etch_known_comet_orbit_data to utilize this to enable proper parsing of tt-scaled peri & epoch times
@dschlekat
Copy link
Copy Markdown
Contributor Author

Pushed a new version of the fix, addressing your concerns to do with changes to Time.from_ymd(). Adds _ymd_to_jd()helper to mpc.py. Normally I'd look to place this in a utils.py file, but as one didn't exist I just left it in the normal file. This helper is then called within fetch_known_comet_orbit_data.py to create Time objects with TT scaling.

Also, I want to make it clear it is totally fine with me if you choose to go a completely different route for the fix or not use my changes! Just wanted to try and help if I could.

Comment thread src/kete/mpc.py Outdated
peri_arg=comet["Peri"],
peri_time=Time.from_ymd(*peri_time).jd,
epoch=Time.from_ymd(*epoch_time).jd,
peri_time=Time(_ymd_to_jd(peri_time), scaling="tt").jd,
Copy link
Copy Markdown
Owner

@dahlend dahlend May 29, 2026

Choose a reason for hiding this comment

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

I hate to do this, but do this instead (and please remove the helper function that was added).

        obj = dict(
            desig=name,
            group_name=f"Comet {comet['Orbit_type']}",
            peri_dist=comet["Perihelion_dist"],
            ecc=comet["e"],
            incl=comet["i"],
            lon_node=comet["Node"],
            peri_arg=comet["Peri"],
            # MPC comet files store YMD as TT time.
            # Support for this will not be added into kete, so here is a workaround.
            peri_time=Time.from_jd(Time.from_ymd(*peri_time).utc_jd, scaling="tt").jd,
            epoch=Time.from_jd(Time.from_ymd(*epoch_time).utc_jd, scaling="tt").jd,
        )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Still significantly cleaner than the helper function.
I pushed, only change was I used Time() not Time.from_jd() (default Time new function takes in jd).

Copy link
Copy Markdown
Owner

@dahlend dahlend left a comment

Choose a reason for hiding this comment

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

Thanks!

@dahlend dahlend merged commit 14e9c33 into dahlend:main May 29, 2026
2 checks passed
@dschlekat dschlekat deleted the fix/mpc-tt-epochs branch May 29, 2026 18:04
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.

MPC extended files use TT time not UTC

2 participants