[AstroPy] Convert GPS time to UTC time
d.berry at jach.hawaii.edu
Fri Dec 6 09:17:46 EST 2013
On 6 December 2013 14:11, David Berry <d.berry at jach.hawaii.edu> wrote:
> GPS is offset by 19 seconds from TAI. TAI is itself offset from UTC by an
> integer number of seconds that increments each time a leap second occurs.
> So it's pretty easy to code, but you need to know what the current UTC-TAI
> value is.
> As an example, here is how to could be done using pyast. pyast does not
> yet support GPS directly, but it's a simple job to add on the extra 19
Spot the obvious error! It should have been...
import starlink.Ast as Ast
# Create frames describing UTC and TAI, in seconds. Indicate that values
# should be formatted using a standard ISO date and time string with 3
# decimal places in the seconds field.
tai_frame = Ast.TimeFrame( "TimeScale=TAI,Unit=s,Format=iso.3" )
utc_frame = Ast.TimeFrame( "TimeScale=UTC,Unit=s,Format=iso.3" )
# Get a mapping from TAI to UTC.
tai_to_utc = tai_frame.convert( utc_frame )
# TAI is GPS plus 19 seconds. Create a Mapping to describe this shift.
gps_to_tai = Ast.ShiftMap( 19.0 )
# Conbine these mappings to get the total GPS to UTC mapping.
gps_to_utc = Ast.CmpMap( gps_to_tai, tai_to_utc )
# Convert an example GPS date and time string to a floating point
# value in seconds. We use the TAI frame here as a convenience - it's
# only being used to do the parsing, which is the same for all timescales.
( nc, gps_value ) = tai_frame.unformat( 1, "2013-10-03 12:22:02.1" )
# Using the above mapping to transform it to UTC.
utc_value = gps_to_utc.tran( gps_value )
# Convert the result to a date and time string and print.
print( utc_frame.format( 1, utc_value ) )
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the AstroPy