Skip to content
Snippets Groups Projects
Commit e3d36a81 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

don't use astroy when parsing packets

parent f5753592
No related branches found
Tags 0.10.0
No related merge requests found
# 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)
......@@ -13,8 +13,9 @@ setup(
'setuptools_scm'
],
install_requires=[
'h5py',
'astropy',
'attrs',
'h5py',
],
extras_require={
'testing': [
......
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment