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
1de5b7a8
Commit
1de5b7a8
authored
7 years ago
by
Greg Quinn
Browse files
Options
Downloads
Patches
Plain Diff
rdrgen: produce correct file names for RDRs
parent
2ee9754b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
edosl0util/rdrgen.py
+28
-6
28 additions, 6 deletions
edosl0util/rdrgen.py
tests/test_rdrgen.py
+13
-6
13 additions, 6 deletions
tests/test_rdrgen.py
with
41 additions
and
12 deletions
edosl0util/rdrgen.py
+
28
−
6
View file @
1de5b7a8
import
ctypes
import
itertools
import
os
from
collections
import
OrderedDict
from
datetime
import
datetime
...
...
@@ -13,8 +14,8 @@ from edosl0util.jpssrdr import (
StaticHeader
,
Apid
as
ApidListItem
,
PacketTracker
,
decode_rdr_blob
)
def
write_rdr
(
sat
,
blob
,
distributor
=
None
,
origin
=
None
,
domain
=
None
,
orbit_num
ber
=
0
,
def
write_rdr
(
sat
,
blob
,
dir_path
=
'
.
'
,
distributor
=
None
,
origin
=
None
,
domain
=
None
,
compressed
=
False
,
orbit_num
=
0
,
creation_time
=
None
,
gran_creation_time
=
None
,
software_ver
=
None
):
# TODO: write out the user block too??
distributor
=
distributor
or
origin
or
default_origin
...
...
@@ -34,7 +35,9 @@ def write_rdr(sat, blob,
gran_ver
=
'
A1
'
format_date
=
lambda
t
:
t
.
strftime
(
'
%Y%m%d
'
)
format_time
=
lambda
t
:
t
.
strftime
(
'
%H%M%S.%fZ
'
)
with
h5py
.
File
(
'
rdr.h5
'
,
'
w
'
)
as
h5_file
:
file_name
=
make_rdr_filename
(
rdr_type
.
product_id
,
sat
,
gran_time
,
gran_end_time
,
orbit_num
,
creation_time
,
origin
,
domain
,
compressed
)
with
h5py
.
File
(
os
.
path
.
join
(
dir_path
,
file_name
),
'
w
'
)
as
h5_file
:
set_h5_attrs
(
h5_file
,
{
'
Distributor
'
:
distributor
,
'
Mission_Name
'
:
'
S-NPP/JPSS
'
,
...
...
@@ -61,7 +64,7 @@ def write_rdr(sat, blob,
'
Beginning_Time
'
:
format_time
(
gran_time
),
'
Ending_Date
'
:
format_date
(
gran_end_time
),
'
Ending_Time
'
:
format_time
(
gran_end_time
),
'
N_Beginning_Orbit_Number
'
:
np
.
uint64
(
orbit_num
ber
),
# FIXME: detect?
'
N_Beginning_Orbit_Number
'
:
np
.
uint64
(
orbit_num
),
# FIXME: detect?
'
N_Beginning_Time_IET
'
:
np
.
uint64
(
gran_iet
),
'
N_Creation_Date
'
:
format_date
(
gran_creation_time
),
'
N_Creation_Time
'
:
format_time
(
gran_creation_time
),
...
...
@@ -84,13 +87,14 @@ def write_rdr(sat, blob,
set_h5_attrs
(
aggr_ds
,
{
'
AggregateBeginningDate
'
:
format_date
(
gran_time
),
'
AggregateBeginningGranuleID
'
:
gran_id
,
'
AggregateBeginningOrbitNumber
'
:
np
.
uint64
(
orbit_num
ber
),
'
AggregateBeginningOrbitNumber
'
:
np
.
uint64
(
orbit_num
),
'
AggregateBeginningTime
'
:
format_time
(
gran_time
),
'
AggregateEndingDate
'
:
format_date
(
gran_end_time
),
'
AggregateEndingGranuleID
'
:
gran_id
,
'
AggregateEndingOrbitNumber
'
:
np
.
uint64
(
orbit_num
ber
),
'
AggregateEndingOrbitNumber
'
:
np
.
uint64
(
orbit_num
),
'
AggregateEndingTime
'
:
format_time
(
gran_end_time
),
'
AggregateNumberGranules
'
:
np
.
uint64
(
1
)})
return
file_name
def
set_h5_attrs
(
h5_obj
,
attrs
):
...
...
@@ -227,6 +231,7 @@ class ApidSpec(object):
class
CrisScienceRdrType
(
object
):
product_id
=
'
RCRIS
'
short_name
=
'
CRIS-SCIENCE-RDR
'
gran_len
=
31997000
sensor
=
'
cris
'
...
...
@@ -236,6 +241,7 @@ class CrisScienceRdrType(object):
class
SpacecraftDiaryRdrType
(
object
):
product_id
=
'
RNSCA
'
short_name
=
'
SPACECRAFT-DIARY-RDR
'
gran_len
=
20000000
sensor
=
None
...
...
@@ -246,6 +252,22 @@ class SpacecraftDiaryRdrType(object):
ApidSpec
(
11
,
'
DIARY
'
,
max_expected
=
21
)]
def
make_rdr_filename
(
prod_id
,
sat
,
gran_time
,
gran_end_time
,
orbit_num
,
creation_time
,
origin
,
domain
,
compressed
):
sat_strs
=
{
'
snpp
'
:
'
npp
'
}
def
format_gran_time
(
t
):
return
t
.
strftime
(
'
%H%M%S
'
)
+
str
(
t
.
microsecond
/
100000
)
def
format_origin
(
o
):
if
o
.
endswith
(
'
-
'
):
return
o
[:
-
1
]
+
(
'
c
'
if
compressed
else
'
u
'
)
else
:
return
o
return
'
{p}_{s}_d{d:%Y%m%d}_t{b}_e{e}_b{n}_c{c:%Y%m%d%H%M%S%f}_{o}_{m}.h5
'
.
format
(
p
=
prod_id
,
s
=
sat_strs
[
sat
],
d
=
gran_time
,
b
=
format_gran_time
(
gran_time
),
e
=
format_gran_time
(
gran_end_time
),
n
=
orbit_num
,
c
=
creation_time
,
o
=
format_origin
(
origin
),
m
=
domain
)
def
timecode_to_iet
(
timecode
):
# FIXME: move to timecode.py
ccsds_epoch
=
Time
(
'
1958-01-01
'
,
scale
=
'
tai
'
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_rdrgen.py
+
13
−
6
View file @
1de5b7a8
...
...
@@ -50,14 +50,21 @@ def test_can_reproduce_rdr_from_class():
# generate new RDR from packets, injecting matching metadata from CLASS file
blob
=
m
.
build_rdr_blob
(
'
snpp
'
,
jpss_packet_stream
(
StringIO
(
pkt_buf
.
tobytes
())))
m
.
write_rdr
(
'
snpp
'
,
blob
,
distributor
=
'
arch
'
,
origin
=
'
nob-
'
,
domain
=
'
ops
'
,
creation_time
=
datetime
(
2017
,
9
,
13
,
22
,
3
,
40
,
173580
),
gran_creation_time
=
datetime
(
2017
,
9
,
12
,
1
,
37
,
43
,
474383
),
orbit_number
=
30441
,
software_ver
=
'
I2.0.03.00
'
)
tmp_dir
=
'
/tmp
'
file_name
=
m
.
write_rdr
(
'
snpp
'
,
blob
,
tmp_dir
,
distributor
=
'
arch
'
,
origin
=
'
nob-
'
,
domain
=
'
ops
'
,
creation_time
=
datetime
(
2017
,
9
,
13
,
22
,
3
,
40
,
173580
),
gran_creation_time
=
datetime
(
2017
,
9
,
12
,
1
,
37
,
43
,
474383
),
orbit_num
=
30441
,
software_ver
=
'
I2.0.03.00
'
)
# file names should be identical
assert
file_name
==
class_rdr_file
# use h5diff to verify files match. -p option is needed to allow some slop
# in comparing N_Percent_Missing_Data
p
=
subprocess
.
Popen
([
'
h5diff
'
,
'
-c
'
,
'
-p
'
,
'
1e-6
'
,
class_rdr_path
,
'
rdr.h5
'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
p
=
subprocess
.
Popen
(
[
'
h5diff
'
,
'
-c
'
,
'
-p
'
,
'
1e-6
'
,
class_rdr_path
,
os
.
path
.
join
(
tmp_dir
,
file_name
)],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
assert
p
.
communicate
()[
0
]
==
''
assert
p
.
returncode
==
0
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