Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EdosL0Util
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SIPS
EdosL0Util
Commits
f5753592
Commit
f5753592
authored
7 years ago
by
Bruce Flynn
Browse files
Options
Downloads
Patches
Plain Diff
changes to timecode helpers
parent
a2660b1a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
edosl0util/headers.py
+20
-23
20 additions, 23 deletions
edosl0util/headers.py
edosl0util/timecode.py
+13
-13
13 additions, 13 deletions
edosl0util/timecode.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
34 additions
and
36 deletions
edosl0util/headers.py
+
20
−
23
View file @
f5753592
...
...
@@ -13,13 +13,10 @@ See:
"""
__copyright__
=
"
Copyright (C) 2015 University of Wisconsin SSEC. All rights reserved.
"
import
ctypes
as
c
from
datetime
import
datetime
,
timedelta
from
edosl0util.timecode
import
cds_stamp
,
cds_to_timestamp
from
edosl0util.timecode
import
cds_to_dt
GROUP_FIRST
=
0b01
GROUP_LAST
=
0b10
...
...
@@ -63,12 +60,10 @@ class Timecode(BaseStruct):
"""
Secondary header timecode baseclass.
"""
def
__repr__
(
self
):
return
str
(
self
.
asdatetime
())
def
astimestamp
(
self
):
raise
NotImplementedError
()
def
asdatetime
(
self
):
raise
NotImplementedError
()
...
...
@@ -98,20 +93,16 @@ class AquaCucTimecode(Timecode):
EPOCH_SECS
=
(
EPOCH
-
datetime
(
1970
,
1
,
1
)).
total_seconds
()
SUB_SECOND_UNITS
=
15.2
def
astimestamp
(
self
):
tc
=
self
.
timecode
return
cds_to_timestamp
(
tc
.
days
,
tc
.
milliseconds
,
tc
.
microseconds
,
self
.
EPOCH_SECS
)
def
asdatetime
(
self
):
"""
Return converted to UTC where leap seconds are as defined in `leap_seconds`.
FIXME: Verify this conversion is correct, specfically the use of
SUB_SECOND_UNIT.
"""
seconds
=
self
.
seconds
+
self
.
leap_seconds
micros
=
self
.
SUB_SECOND_UNITS
*
self
.
sub_seconds
return
self
.
EPOCH
+
timedelta
(
seconds
=
seconds
,
microseconds
=
micros
)
seconds
=
self
.
seconds
+
self
.
leap_seconds
return
cds_to_dt
(
(
seconds
-
self
.
leap_seconds
)
//
86400
,
micros
//
1e3
,
micros
%
1e3
)
class
DaySegmentedTimecode
(
Timecode
):
...
...
@@ -125,14 +116,8 @@ class DaySegmentedTimecode(Timecode):
(
'
microseconds
'
,
c
.
c_uint16
)
]
EPOCH
=
datetime
(
1958
,
1
,
1
)
EPOCH_SECS
=
(
EPOCH
-
datetime
(
1970
,
1
,
1
)).
total_seconds
()
def
astimestamp
(
self
):
return
cds_to_timestamp
(
self
.
days
,
self
.
milliseconds
,
self
.
microseconds
,
self
.
EPOCH_SECS
)
def
asdatetime
(
self
):
return
cds_
stamp
(
self
.
days
,
self
.
milliseconds
,
self
.
microseconds
)
return
cds_
to_dt
(
self
.
days
,
self
.
milliseconds
,
self
.
microseconds
)
class
AquaGirdSecondaryHeader
(
BaseStruct
):
...
...
@@ -178,12 +163,22 @@ class JpssFirstSecondaryHeader(BaseStruct):
]
class
ViirsPacketId
(
BaseStruct
):
_pack_
=
1
_fields_
=
[
(
'
scan_number
'
,
c
.
c_uint32
),
(
'
packet_time
'
,
DaySegmentedTimecode
),
]
_jpss_headers
=
{
GROUP_FIRST
:
JpssFirstSecondaryHeader
,
GROUP_CONTINUING
:
None
,
GROUP_LAST
:
None
,
GROUP_STANDALONE
:
JpssSecondaryHeader
,
}
def
jpss_header_lookup
(
primary_header
):
return
_jpss_headers
.
get
(
primary_header
.
sequence_grouping
)
...
...
@@ -269,4 +264,6 @@ def aqua_header_lookup(primary_header):
apid
=
primary_header
.
apid
grouping
=
primary_header
.
sequence_grouping
return
_aqua_headers
.
get
((
apid
,
grouping
))
_aqua_headers
=
aqua_headers
()
This diff is collapsed.
Click to expand it.
edosl0util/timecode.py
+
13
−
13
View file @
f5753592
# encoding: utf-8
__copyright__
=
"
Copyright (C) 2015 University of Wisconsin SSEC. All rights reserved.
"
from
date
time
import
datet
ime
,
t
ime
d
elta
from
astropy.
time
import
T
ime
,
T
ime
D
elta
JPSS
_EPOCH
=
datet
ime
(
1958
,
1
,
1
)
UNIX_EPOCH
=
datet
ime
(
1970
,
1
,
1
)
IET
_EPOCH
=
T
ime
(
'
1958
-01-01
'
,
scale
=
'
tai
'
)
UNIX_EPOCH
=
T
ime
(
'
1970
-01-01
'
,
scale
=
'
utc
'
)
def
unixtime
(
dt
):
"""
Datetime to Unix timestamp.
"""
if
dt
>
UNIX_EPOCH
:
return
(
dt
-
UNIX_EPOCH
).
total_seconds
()
return
(
UNIX_EPOCH
-
dt
).
total_seconds
()
return
(
dt
-
UNIX_EPOCH
).
total_seconds
()
def
cds_to_t
imestamp
(
days
,
millis
,
microseconds
,
epoch
):
def
cds_to_
d
t
(
days
,
millis
,
microseconds
):
"""
CDS
to unix timestamp seconds
.
C
CS
DS
Day Segmented timecode to UTC datetime
.
"""
return
epoch
+
(
86400
*
days
)
+
(
millis
/
1000.
)
+
(
microseconds
/
1000000.
)
iet
=
cds_to_iet
(
days
,
millis
,
microseconds
)
return
(
IET_EPOCH
+
TimeDelta
(
iet
,
format
=
'
sec
'
)).
utc
.
datetime
def
cds_
stamp
(
days
,
m
illis
,
microseconds
,
epoch
=
JPSS_EPOCH
):
def
cds_
to_iet
(
days
,
m
s
,
us
):
"""
CCSDS Day Segmented timecode
to UTC datetime.
CCSDS Day Segmented timecode
parts to IET
"""
return
epoch
+
timedelta
(
days
=
days
,
seconds
=
millis
/
1000.0
+
(
microseconds
/
1000000.
))
ccsds_epoch
=
Time
(
'
1958-01-01
'
,
scale
=
'
tai
'
)
day
=
Time
(
ccsds_epoch
.
jd
+
days
,
scale
=
'
utc
'
,
format
=
'
jd
'
)
-
IET_EPOCH
return
int
(
day
.
sec
*
1e6
+
ms
*
1e3
+
us
)
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
f5753592
...
...
@@ -14,6 +14,7 @@ setup(
],
install_requires
=
[
'
h5py
'
,
'
astropy
'
,
],
extras_require
=
{
'
testing
'
:
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment