diff --git a/edosl0util/timecode.py b/edosl0util/timecode.py index 048e6ae176eabf3a3d1786a1b07e09f843a31f69..1e32b90309123d6a874d4b9ffa2ce444c75246ac 100644 --- a/edosl0util/timecode.py +++ b/edosl0util/timecode.py @@ -1,31 +1,30 @@ # encoding: utf-8 +from datetime import timedelta, datetime + __copyright__ = "Copyright (C) 2015 University of Wisconsin SSEC. All rights reserved." from astropy.time import Time, TimeDelta -IET_EPOCH = Time('1958-01-01', scale='tai') -UNIX_EPOCH = Time('1970-01-01', scale='utc') - def unixtime(dt): """ Datetime to Unix timestamp. """ - return (dt - UNIX_EPOCH).total_seconds() + return (dt - datetime(1970, 1, 1)).total_seconds() def cds_to_dt(days, millis, microseconds): """ CCSDS Day Segmented timecode to UTC datetime. """ - iet = cds_to_iet(days, millis, microseconds) - return (IET_EPOCH + TimeDelta(iet, format='sec')).utc.datetime + return datetime(1970, 1, 1) + timedelta(days=days, microseconds=1e6 * millis + microseconds) def cds_to_iet(days, ms, us): """ - CCSDS Day Segmented timecode parts to IET + CCSDS Day Segmented timecode parts to IET (microseconds) """ + iet_epoch = Time('1958-01-01', scale='tai') ccsds_epoch = Time('1958-01-01', scale='tai') - day = Time(ccsds_epoch.jd + days, scale='utc', format='jd') - IET_EPOCH + day = Time(ccsds_epoch.jd + days, scale='utc', format='jd') - iet_epoch return int(day.sec * 1e6 + ms * 1e3 + us) diff --git a/setup.py b/setup.py index d63918fd123654345434879d288303194566c7fe..89b3c378c4987a9c2e49e932c05b2b8a3da81480 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,9 @@ setup( 'setuptools_scm' ], install_requires=[ - 'h5py', 'astropy', + 'attrs', + 'h5py', ], extras_require={ 'testing': [ diff --git a/tests/test_timecode.py b/tests/test_timecode.py deleted file mode 100644 index 9d2633c591bcdd3105ac1d8fec94784dfcd0d040..0000000000000000000000000000000000000000 --- a/tests/test_timecode.py +++ /dev/null @@ -1,29 +0,0 @@ -from datetime import datetime, timedelta -from edosl0util import timecode - - -def test_unixtime(): - assert timecode.unixtime(timecode.UNIX_EPOCH) == 0 - - -def test_cds_to_timestamp(): - epoch = 0 - - secs = timecode.cds_to_timestamp(0, 0, 0, epoch) - assert secs == 0 - - secs = timecode.cds_to_timestamp(0, 0, 999, epoch) - assert secs == 0.000999 - - secs = timecode.cds_to_timestamp(1, 1, 999, epoch) - assert secs == 86400.001999 - - -def test_cds_stamp(): - epoch = timecode.UNIX_EPOCH - - assert timecode.cds_stamp(0, 0, 0, epoch) == timecode.UNIX_EPOCH - - assert timecode.cds_stamp(0, 0, 999, epoch) == datetime(1970, 1, 1, 0, 0, 0, 999) - - assert timecode.cds_stamp(1, 1, 999, epoch) == datetime(1970, 1, 2, 0, 0, 0, 1999)