1292 bug epoch time should be tdt instead of tdb#1295
Conversation
… return Terrestrial Time nanoseconds rather than TDB nanoseconds to adhere to CDF_TIME_TT2000 definition Rename spice.time.j2000ns_to_j2000s to tt_ns_to_et to correctly convert CDF_TIME_TT2000 to spice ET Update spice.time tests to for renamed/fixed time conversion functions Rename global variable in spice.time from J2000_EPOCH to J2000_TT_EPOCH
maxinelasp
left a comment
There was a problem hiding this comment.
Thanks for the quick update! Overall looks great, I had a few minor suggestions that you can take or leave.
|
|
||
| The common CDF coordinate `epoch` stores J2000 nanoseconds. SPICE requires | ||
| J2000 seconds be used. This is a common function to do that conversion. | ||
| The common CDF coordinate `epoch` stores terrestrial time (TT) J2000 |
| # # Spot check metadata data and attributes | ||
| # j2000_time = ( | ||
| # np.datetime64("2024-02-07T15:28:37.184000", "ns") - J2000_EPOCH | ||
| # np.datetime64("2024-02-07T15:28:37.184000", "ns") - J2000_TT_EPOCH |
There was a problem hiding this comment.
What if we move these to point to the J2000_TT_EPOCH constant variable?
There was a problem hiding this comment.
Not sure I understand. I don't know exactly what these commented out lines are for in this test, but they are pointing to the J2000_TT_EPOCH constant variable.
greglucas
left a comment
There was a problem hiding this comment.
It seems like we have several functions with slightly different names all doing similar conversions. Would it be beneficial to combine these into a single function with keyword argument inputs so that we are just referencing this one function with different parameters as we need them? Just a thought I'm writing down in case this appeals to you, no need to do it here.
def convert_time(my_time_in_whatever_frame, input_frame="TT", output_frame="ET"):
# Some logic to select your input functions
....
# Vectorize the spiceypy calls
np.vectorize(func, ...)| return np.array( | ||
| [spice.unitim(spice.sct2e(IMAP_SC_ID, s), "ET", "TT") for s in sclk_ticks] | ||
| ) |
There was a problem hiding this comment.
Is it worth inverting the np.vectorize you have in the function above (that one goes from TT to ET)? This is a for loop within Python currently.
There was a problem hiding this comment.
I'm happy to do that although my understanding of np.vectorize is that it is a python loop anyway. The main thing that I was trying to do here was avoid two for loops by doing these two steps of converting from s/c ticks to ET and then ET to TT each in their own loop. I could use np.vectorize on a functools.partial of the two chained spiceypy functions.
Side question: Do you think all of the manually "vectorized" functions in this module would benefit from using np.vectorize? My only complaint is that np.vecotrize returns an array with shape=() when a scalar is input.
There was a problem hiding this comment.
You are right, the documentation even says there is basically no speedup.
https://numpy.org/doc/stable/reference/generated/numpy.vectorize.html
The vectorize function is provided primarily for convenience, not for performance. The implementation is essentially a for loop.
So I guess the answer is maybe it isn't worth it and just write the np.array([value for value in list]) loop like you already are. I think the reason to use it is for the broadcasting types then? So if you wanted your function to accept a 0d, 1d, 2d arrays without having to do the for loops yourself for those cases.
@greglucas I agree. I'll write a new ticket to explore the idea of one time conversion function to rule them all. Brandon has done something quite complicated in the curreyer library to accomplish that goal. I am undecided if I like it or not. |
Rename functions to be clear about conversions to tt at J2000 epoch
085b7f5
into
IMAP-Science-Operations-Center:dev
Change Summary
Overview
Fix issue with spice time functions reporting TDB time instead of TT for CDF epoch values. This PR had to touch lots of files due to the function renaming. To make review easier, I suggest that you review in two segments. In the File Changes tab, select the first commit to view just the changes that were made to the
imap_processing.spice.time.pymodule and associated tests. Once finished with that, view the other commit that pushed the function and global variable name changes in that module to all of the locations that they were used.Updated Files
I'm not going to list all of the files to save time. The important changes are detailed below.
J2000_EPOCHtoJ2000_TT_EPOCHand updated value to TT timescale.met_to_j2000nsfunction tomet_to_tt_nsand modified it to return TT nanoseconds rather than TDB nanoseconds.j2000ns_to_j2000sfunction tott_ns_to_etand added conversion from TT to ET.sct_to_ttfunction to aid conversion from spacecraft clock ticks directly to TT with one for loop instead of chaining together multiple looping functions.sct_to_ttfunction.Closes: #1292