Skip to content

Time construction with format='mjd' inaccurate by >600 ns #9327

@aarchiba

Description

@aarchiba

If I construct an astropy.time.Time object with format='mjd' and scale='tai', for certain (future) values I lose >600 ns of accuracy. The same does not occur if I construct directly with format='jd' that I constructed using day_frac. Example in the form of a test case:

def test_mjd_initialization_precise():
    i, f = 65536, 3.637978807091714e-12  # Found using hypothesis
    t = Time(val=i, val2=f, format="mjd", scale="tai")
    jd1, jd2 = day_frac(i + erfa.DJM0, f)
    jd1_t, jd2_t = day_frac(t.jd1, t.jd2)
    assert (abs((jd1-jd1_t) + (jd2-jd2_t))*u.day).to(u.ns) < 1*u.ns

and the output:

___________________________________________ test_mjd_initialization_precise ___________________________________________

    def test_mjd_initialization_precise():
        i, f = 65536, 3.637978807091714e-12  # Found using hypothesis
        t = Time(val=i, val2=f, format="mjd", scale="tai")
        jd1, jd2 = day_frac(i + erfa.DJM0, f)
        jd1_t, jd2_t = day_frac(t.jd1, t.jd2)
>       assert (abs((jd1-jd1_t) + (jd2-jd2_t))*u.day).to(u.ns) < 1*u.ns
E       assert <Quantity 628.64273787 ns> < (1 * Unit("ns"))
E        +  where <Quantity 628.64273787 ns> = <bound method Quantity.to of <Quantity 7.27595761e-12 d>>(Unit("ns"))
E        +    where <bound method Quantity.to of <Quantity 7.27595761e-12 d>> = (7.275957614183426e-12 * Unit("d")).to
E        +      where 7.275957614183426e-12 = abs(((2465537.0 - 2465537.0) + (-0.499999999996362 - -0.49999999998908606)))
E        +      and   Unit("d") = u.day
E        +    and   Unit("ns") = u.ns
E        +  and   Unit("ns") = u.ns

astropy/time/tests/test_precision.py:146: AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions