-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions to convert from met to ET and UTC #1210
Add functions to convert from met to ET and UTC #1210
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Nice, thorough tests.
Will the fix to the 5 second just be replacing this constant J2000_EPOCH
with a spice call?
@@ -13,6 +13,30 @@ | |||
|
|||
TICK_DURATION = 2e-5 # 20 microseconds as defined in imap_sclk_0000.tsc | |||
|
|||
# Hard code the J2000 epoch. This allows for CDF epoch to be converted without | |||
# use of SPICE though it should be noted that this results in a 5-second error | |||
# due to the occurrence of 5 leap-seconds since the J2000 epoch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably a TODO should go here, since this is where the epoch is defined, and where the 5 leapsecond fix will go, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True Nat. I meant to ask Tim if there is a ticket to revisit for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add the TODO. Yes, there is a ticket for this. There are two ways to fix this each with a pro and con. See ticket: #1208
To clarify, this J2000EPOCH value is correct. The bug is in the code in the cdf/utils.py
here:
dt64 = J2000_EPOCH + dataset["epoch"].values[0].astype("timedelta64[ns]")
start_time = np.datetime_as_string(dt64, unit="D").replace("-", "")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I just had one minor doc string requests.
# use of SPICE though it should be noted that this results in a 5-second error | ||
# due to the occurrence of 5 leap-seconds since the J2000 epoch. | ||
# The UTC string was generated by: | ||
# >>> spiceypy.et2utc(0, "ISOC", 9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these doc strings. Helps someone like me.
imap_processing/spice/time.py
Outdated
Returns | ||
------- | ||
numpy.ndarray[str] | ||
The mission elapsed time converted to UTC string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an example about the format it returns in? If I understand correctly, ISOC
format is something like YYYY-MM-DDTHH:MM:SSZ
. Is that right? or is it like this 1987-04-12T16:31:12.814
?
""" | ||
if isinstance(met, typing.Iterable): | ||
return np.asarray([np.datetime64(utc) for utc in met_to_utc(met)]) | ||
return np.datetime64(met_to_utc(met)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two functions are gonna be so helpful! Thank you for adding those
dt64 = met_to_datetime64(met) | ||
np.testing.assert_array_equal( | ||
dt64.astype("datetime64[us]"), expected_dt64.astype("datetime64[us]") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
No, actually, it is a bit more subtle. That epoch definition is correct in that it is the number of nanoseconds elapsed since the Unix epoch (00:00:00 UTC on 1 January 1970). The problem is that |
aa2ecc4
into
IMAP-Science-Operations-Center:dev
…ons-Center#1210) * Add functions to convert from met to ET and UTC * Switch MAG and GLOWS imports to use spice.time definition of J2000_EPOCH * PR feedback
Change Summary
Overview
Adds functions for converting from Mission Elapsed Time (MET) to ET and UTC
Updated Files
J2000_EPOCH
moved into the spice.time.py moduleJ2000_EPOCH
moved into the spice.time.py modulemet_to_sclkticks
function for reusemet_to_utc
functionmet_to_datetime64
function with SPICE backed implementation.spice/time.py
functions.spiceypy as spice
because it is confusing.Closes: #1183