Skip to content

Commit ec11ea6

Browse files
committed
Implement support for YYYY-DDD format epochs (#43)
1 parent ae9c6d2 commit ec11ea6

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

oem/patterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
FLOAT = f"(?:[+-]?\\d\\.\\d+(?:[eE][+-]\\d{{1,3}})){HS}|[+-]?\\d+\\.\\d+"
1515
"""Floating-point number"""
1616

17-
DATE = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?"
17+
DATE = r"\d{4}-(?:\d{2}-\d{2}|\d{3})T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?"
1818
"""Date and time"""
1919

2020
KEY_VAL = f"([A-Z_]+){HS}={HS}(.+)"

oem/tools.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ def parse_datetime(epoch):
2727
Returns:
2828
parsed_epoch (DateTime): Parsed epoch.
2929
"""
30+
ymd_fmt = "%Y-%m-%d" if epoch.count("-") == 2 else "%Y-%j"
3031
if "." in epoch:
3132
return dt.datetime.strptime(
3233
epoch.replace("Z", "")[:epoch.index(".")+7].strip(),
33-
"%Y-%m-%dT%H:%M:%S.%f"
34+
f"{ymd_fmt}T%H:%M:%S.%f"
3435
)
3536
else:
3637
return dt.datetime.strptime(
3738
epoch.replace("Z", "").strip(),
38-
"%Y-%m-%dT%H:%M:%S"
39+
f"{ymd_fmt}T%H:%M:%S"
3940
)
4041

4142

@@ -48,7 +49,7 @@ def parse_utc(epoch, metadata):
4849
Returns:
4950
parsed_epoch (Time): UTC epoch.
5051
"""
51-
return Time(epoch, format="isot", scale="utc")
52+
return Time(parse_datetime(epoch), format="datetime", scale="utc")
5253

5354

5455
def parse_epoch(epoch, metadata):
@@ -65,14 +66,15 @@ def parse_epoch(epoch, metadata):
6566
this case, time calculations may be inaccurate.
6667
"""
6768
time_system = metadata["TIME_SYSTEM"].lower()
69+
dt_epoch = parse_datetime(epoch)
6870
if time_system in Time.SCALES:
69-
parsed_epoch = Time(epoch, format="isot", scale=time_system)
71+
parsed_epoch = Time(dt_epoch, format="datetime", scale=time_system)
7072
else:
7173
warnings.warn(
7274
f"Unsupported TIME_SYSTEM '{time_system}', falling back to "
7375
f"DateTime. Use caution with time calculations."
7476
)
75-
parsed_epoch = parse_datetime(epoch)
77+
parsed_epoch = dt_epoch
7678
return parsed_epoch
7779

7880

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CCSDS_OEM_VERS = 2.0
2+
COMMENT Valid example of a single data block with YYYY-DDD dates
3+
CREATION_DATE = 1996-309T17:22:31
4+
ORIGINATOR = NASA/JPL
5+
6+
META_START
7+
COMMENT This is a test comment
8+
COMMENT This is a test comment
9+
OBJECT_NAME = MARS GLOBAL SURVEYOR
10+
OBJECT_ID = 1996-062A
11+
CENTER_NAME = MARS BARYCENTER
12+
REF_FRAME = EME2000
13+
TIME_SYSTEM = UTC
14+
START_TIME = 1996-353T12:00:00.331
15+
STOP_TIME = 1996-353T21:28:00.331
16+
INTERPOLATION = HERMITE
17+
INTERPOLATION_DEGREE = 7
18+
META_STOP
19+
20+
COMMENT This is a test comment
21+
COMMENT This is a test comment
22+
23+
1996-353T12:00:00.331 2789.619 -280.045 -1746.755 4.73372 -2.49586 -1.04195
24+
1996-353T12:01:00.331 2783.419 -308.143 -1877.071 5.18604 -2.42124 -1.99608
25+
1996-353T12:02:00.331 2776.033 -336.859 -2008.682 5.63678 -2.33951 -1.94687

0 commit comments

Comments
 (0)