You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Time("J2000") and equivalents should be equal #6638
This is giving absolute differences of 1e-7. This difference may or may not be important depending on the specific application, but in any case are they expected? If yes, should they be documented? If not, what is going wrong?
I'll let @taldcroft and @mhvk give a full answer but just to speculate on what might be happening here: t1.unix and t2.unix are just 64-bit floats, and -1.1920928955078125e-07 is basically the precision of the 64-bit floats:
In [2]: np.spacing(946727935.8160994)
Out[2]: 1.1920928955078125e-07
As such I don't know if the difference is significant. As you can see from:
the times are equal and the residual value for t1.unix - t2.unix is just a product of the inevitable loss in precision when going to 64-bit floats? This could also be related to the fact that in the original scale, the floats are exact (multiples of 0.5) whereas in the unix representation this is not the case?
So perhaps a different algorithm in __eq__ should be used for comparison based on relative differences? Not sure how to do such a thing though, or if it makes sense at all.
I think this could be because internally one of the jd2 is much larger than the other, so then internally the two times have different precision. Actually looking at:
this doesn't seem right because having the two floats isn't improving the precision (they have similar orders of magnitude). @taldcroft - is that normal?
Hmm, the problem seems to be that the times are not being properly normalized to day and fraction upon initialization, and then by adding a number that has a small rounding error when represented as a fraction of a day, one gets a different result.
I think I see the problem: day_frac is not used in the TimeEpochDateString formats.
@mhvk - hopefully I'm not misunderstanding, but it doesn't seem like the post-facto fix on jd1/jd2 will maintain full precision since jd2 is typically in the range of 50000 or 60000 instead of 1. So bits of precision are being permanently lost within the epoch_to_jd function (which is just a reference to the appropriate ERFA function).
Those ERFA functions are actually really trivial, e.g. the J2000 conversion C-code is just:
I think the assumption in erfa is that the epochs are never that high precision. I think this is actually fine; I don't think there is any case where we would pass in a 2-element epoch. The problem with the sum being different for different input is that Time.__add__ assumes that jd1, jd2 are in day, fraction format, when they are not, and therefore the addition gives a slightly different result.
If we wanted, we could give a warning about possible precision loss when val2 is passed to any of the epoch routines...
Activity
astrojuanlu commentedon Oct 1, 2017
Edit: I added the output of
t1.unix - t0.unixto the summary.WIP: Add propagate to date, test failing
astrofrog commentedon Oct 1, 2017
I'll let @taldcroft and @mhvk give a full answer but just to speculate on what might be happening here:
t1.unixandt2.unixare just 64-bit floats, and-1.1920928955078125e-07is basically the precision of the 64-bit floats:As such I don't know if the difference is significant. As you can see from:
the times are equal and the residual value for
t1.unix - t2.unixis just a product of the inevitable loss in precision when going to 64-bit floats? This could also be related to the fact that in the original scale, the floats are exact (multiples of 0.5) whereas in the unix representation this is not the case?astrojuanlu commentedon Oct 1, 2017
Thank you very much @astrofrog, makes total sense. However, this is the issue that originated this report:
So perhaps a different algorithm in
__eq__should be used for comparison based on relative differences? Not sure how to do such a thing though, or if it makes sense at all.astrojuanlu commentedon Oct 1, 2017
It happens even with tiny additions:
astrofrog commentedon Oct 1, 2017
I think this could be because internally one of the
jd2is much larger than the other, so then internally the two times have different precision. Actually looking at:this doesn't seem right because having the two floats isn't improving the precision (they have similar orders of magnitude). @taldcroft - is that normal?
mhvk commentedon Oct 2, 2017
Hmm, the problem seems to be that the times are not being properly normalized to day and fraction upon initialization, and then by adding a number that has a small rounding error when represented as a fraction of a day, one gets a different result.
I think I see the problem:
day_fracis not used in theTimeEpochDateStringformats.(I cannot make a fix right now - teaching in a few hours - but this should be quite trivial... In https://github.com/astropy/astropy/blob/master/astropy/time/formats.py#L1074,
write instead
mhvk commentedon Oct 2, 2017
Checking a bit further, I think the same needs to be done for
TimeDatetime(just not to count on erfa doing it identically the same), andTimeString.pllim commentedon Oct 2, 2017
Since the fix is basically given in #6638 (comment) , I am tagging this for novice. Thanks!
astrojuanlu commentedon Oct 2, 2017
Thanks @pllim, @mhvk. I might fix this myself this week if I have the time.
taldcroft commentedon Oct 2, 2017
@mhvk - hopefully I'm not misunderstanding, but it doesn't seem like the post-facto fix on
jd1/jd2will maintain full precision sincejd2is typically in the range of 50000 or 60000 instead of 1. So bits of precision are being permanently lost within theepoch_to_jdfunction (which is just a reference to the appropriate ERFA function).Those ERFA functions are actually really trivial, e.g. the J2000 conversion C-code is just:
So maybe just rewrite this in Python in a way that guarantees jd1/jd2 are within the day_frac protocol?
mhvk commentedon Oct 2, 2017
I think the assumption in
erfais that the epochs are never that high precision. I think this is actually fine; I don't think there is any case where we would pass in a 2-element epoch. The problem with the sum being different for different input is thatTime.__add__assumes thatjd1,jd2are in day, fraction format, when they are not, and therefore the addition gives a slightly different result.If we wanted, we could give a warning about possible precision loss when
val2is passed to any of the epoch routines...taldcroft commentedon Oct 2, 2017
@mhvk - fair enough. Maybe the easy fix will do the trick.
Accomodate jd1 and jd2, see astropy#6638
WIP: Sum test fails, see astropy#6638
astrojuanlu commentedon Oct 3, 2017
Attempt to fix: #6653
WIP: Add propagate to date, test failing
Mark test as known failure