IAU-ADES / ADES-Master

ADES implementation based on a master XML file
26 stars 7 forks source link

fix obsTime conversion; make sexDateToISO and isoToSexDate more flexible #62

Closed stevenstetzler closed 2 months ago

stevenstetzler commented 3 months ago

Tracks #59

This PR updates sexVals.sexDateToISO to handle MPC obsTime rounding rules: by default all obsTime are reported with millisecond precision. This is enabled with a keyword argument to sexDateToISO: mpc_rounding=True which is the default value.

Additionally, sexVals.sexDateToISO and sexVals.isoToSexDate are re-written to use Python's datetime module for handling dates and timedeltas and are made more flexible to handle higher precision observations.

Here is an example:

>>> import sexVals
# default behavior
>>> sexVals.sexDateToISO("2020 08 18.123456") 
('2020-08-18T02:57:46.598Z', 1, '.123456') # obsTime, precTime, fractional days

# write obsTime with microsecond precision
>>> sexVals.sexDateToISO("2020 08 18.123456", mpc_rounding=False)
('2020-08-18T02:57:46.598400Z', 1, '.123456')

# write obsTime with integer second precision
>>> sexVals.sexDateToISO("2020 08 18.123456", intsec=True, mpc_rounding=False)
('2020-08-18T02:57:46Z', 1, '.123456')

# handle conversions for higher precision times
>>> sexVals.sexDateToISO("2020 08 18.1234567891", mpc_rounding=True)
('2020-08-18T02:57:46.667Z', 0.0001, '.1234567891')
>>> sexVals.sexDateToISO("2020 08 18.1234567891", mpc_rounding=False)
('2020-08-18T02:57:46.666578Z', 0.0001, '.1234567891')

# observe default output for the different expected input precisions
>>> sexVals.sexDateToISO("2020 08 18.1")
('2020-08-18T02:24:00.000Z', 100000, '.1')
>>> sexVals.sexDateToISO("2020 08 18.12")
('2020-08-18T02:52:48.000Z', 10000, '.12')
>>> sexVals.sexDateToISO("2020 08 18.123")
('2020-08-18T02:57:07.200Z', 1000, '.123')
>>> sexVals.sexDateToISO("2020 08 18.1234")
('2020-08-18T02:57:41.760Z', 100, '.1234')
>>> sexVals.sexDateToISO("2020 08 18.12345")
('2020-08-18T02:57:46.080Z', 10, '.12345')
>>> sexVals.sexDateToISO("2020 08 18.123456")
('2020-08-18T02:57:46.598Z', 1, '.123456')

In all of the cases above precTime corresponds to the precision of the input sexagesimal date (in millionths of a day), regardless of the precision of the obsTime returned.

How does this look @stevechesley?