[AstroPy] Convert GPS time to UTC time
David Berry
d.berry at jach.hawaii.edu
Fri Dec 6 09:11:59 EST 2013
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 seconds.
David
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 )
# Combine these mappings to get the total GPS to UTC mapping.
gps_to_utc = Ast.CmpMap( gps_to_tai, tai_to_utc )
# Convert an example UTC date and time string to a floating point
# value in seconds.
( nc, utc_value ) = utc_frame.unformat( 1, "2013-10-03 12:22:02.1" )
# Using the above mapping to transform the seconds value to GPS.
gps_value = gps_to_utc.tran( utc_value )
# Convert the result to a date and time string and print. Use the TAI
# frame here as a convenience - it's only being used to do the formatting,
# which is the same for all timescales.
print( tai_frame.format( 1, gps_value ) )
On 6 December 2013 12:29, Hoàng Đức Thường <hoangthuong.hust at gmail.com>wrote:
> Hi,
>
> May anyone help me? I want to write a program convert GPS time to UTC
> time. Then how can I understand the algorithm ?
>
> Thank you !
>
> --
>
> ================================================
> Hoang Duc Thuong
>
> Université des Sciences et des Technologies de Hanoi(USTH)
> University of Science and Technology of Hanoi(USTH)
> Hanoi University of Science and Technology (HUST)
>
> Email: hoangthuong.hust at gmail.com
> Tel: +84 01692887738
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20131206/45f3629a/attachment.html>
More information about the AstroPy
mailing list