ICESAT-2HackWeek / CloudMask

Fetch, classify, and label ICESat-2 data
BSD 2-Clause "Simplified" License
4 stars 6 forks source link

Discrepancies between times using astropy and datetime #13

Open facusapienza21 opened 3 years ago

facusapienza21 commented 3 years ago

The following two functions can be used to compute a time object given the seconds in GPS, that is, the total seconds since 1980-06-01 00:00. The first function uses the package astropy and the second datetime.

Screen Shot 2020-11-10 at 4 02 59 PM

However, we can see that they result in different times from the same timestamp (in this case, 0 seconds should match with 1980-06-01 00:00):

Screen Shot 2020-11-10 at 4 05 37 PM
mrsiegfried commented 3 years ago

The gps2dyr function using format='gps' returns TAI time, not GPS time. The format argument governs how time is represented, whereas the scale argument is what converts between time standards. astropy Time objects do not have GPS as a scale option; the astropy documentation provides a table showing the scale and reference date for specific format options.

TAI is always 19 seconds ahead of GPS (and 19 + # of leap seconds ahead of UTC), so to get to a GPS time epoch in astropy Time objects, you have to use (Time(time, format='gps')-TimeDelta(19, format='sec')).datetime