Due to how we are generating the representation for astropy.time.Time objects, some numerical inaccuracies accumulate. This results in the time value read from asdf for a astropy.time.Time object slightly differing the value of the original object. The reason for this is that several of the available time formats require a conversion into a format which we write to ASDF (for human readability) and then that format will get converted to the original format, which is a process that generates numerical errors.
A demonstration of this is the need for a atol and the use of isclose instead of == in this test:
https://github.com/WilliamJamieson/asdf-astropy/blob/889005badaea78a6feb59f72574d3b9b299292b9/asdf_astropy/converters/time/tests/test_time.py#L139-L153 (fixing an incorrectly written test as part of #132).
Currently, there are two possible solutions that I see:
astropy.time.Time should be written under a new schema (say http://astropy.org/schemas/astropy/time/time-1.0.0) rather than the one built into ASDF. This schema should instead write the base-representation (using val1 and val2 directly) for the astropy.time.Time object rather than attempting to write the object in a human-readable format. @perrygreenfield suggested that maybe ASDF should support converters including a comment alongside this to make it human readable.
- As proposed by @eslavich, use the
decimal built-in type of python to exactly convert val1 and val2 into their exact representation for the universal time value, and write that value as an exact string. Then forcing the read in decimal followed by a computation in decimal to extract val1 and val2. Maybe include a flag in the existing time schema to indicate this mode should be used.
Other solutions may exist, which should be discussed as part of this issue.
Due to how we are generating the representation for
astropy.time.Timeobjects, some numerical inaccuracies accumulate. This results in the time value read from asdf for aastropy.time.Timeobject slightly differing the value of the original object. The reason for this is that several of the available timeformatsrequire a conversion into a format which we write to ASDF (for human readability) and then thatformatwill get converted to the original format, which is a process that generates numerical errors.A demonstration of this is the need for a
atoland the use ofiscloseinstead of==in this test:https://github.com/WilliamJamieson/asdf-astropy/blob/889005badaea78a6feb59f72574d3b9b299292b9/asdf_astropy/converters/time/tests/test_time.py#L139-L153 (fixing an incorrectly written test as part of #132).
Currently, there are two possible solutions that I see:
astropy.time.Timeshould be written under a new schema (sayhttp://astropy.org/schemas/astropy/time/time-1.0.0) rather than the one built into ASDF. This schema should instead write the base-representation (usingval1andval2directly) for theastropy.time.Timeobject rather than attempting to write the object in a human-readable format. @perrygreenfield suggested that maybe ASDF should support converters including a comment alongside this to make it human readable.decimalbuilt-in type ofpythonto exactly convertval1andval2into their exact representation for the universal time value, and write that value as an exact string. Then forcing the read indecimalfollowed by a computation indecimalto extractval1andval2. Maybe include a flag in the existingtimeschema to indicate this mode should be used.Other solutions may exist, which should be discussed as part of this issue.