pyacs.lib.gpstime

Note: Leap seconds still needs to be checked an improve A Python implementation of GPS related time conversions.

Copyright 2002 by Bud P. Bruegger, Sistema, Italy mailto:bud@sistema.it http://www.sistema.it

Modifications for GPS seconds by Duncan Brown

PyUTCFromGpsSeconds added by Ben Johnson

This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

GPS Time Utility functions

This file contains a Python implementation of GPS related time conversions.

The two main functions convert between UTC and GPS time (GPS-week, time of week in seconds, GPS-day, time of day in seconds). The other functions are convenience wrappers around these base functions.

A good reference for GPS time issues is: http://www.oc.nps.navy.mil/~jclynch/timsys.html

Note that python time types are represented in seconds since (a platform dependent Python) Epoch. This makes implementation quite straight forward as compared to some algorigthms found in the literature and on the web.

pyacs.lib.gpstime.GpsSecondsFromPyUTC(pyUTC, _leapSecs=14)[source]

Convert Python epoch time to GPS seconds (since GPS epoch).

Parameters:
  • pyUTC (float) – Seconds since Python epoch (e.g. time.time()).

  • _leapSecs (int, optional) – Unused; kept for API compatibility.

Returns:

GPS seconds since 1980-01-06 00:00:00.

Return type:

int

pyacs.lib.gpstime.UTCFromGps(gpsWeek, SOW, leapSecs=14)[source]

Convert GPS week and seconds of week to UTC.

Parameters:
  • gpsWeek (int) – Full GPS week number (not modulo 1024).

  • SOW (float) – Seconds of week.

  • leapSecs (int, optional) – Leap seconds (GPS - UTC). Default is 14.

Returns:

(year, month, day, hour, minute, sec).

Return type:

tuple

pyacs.lib.gpstime.dayOfWeek(year, month, day)[source]

Return GPS day of week: 0=Sun, 1=Mon, …, 6=Sat.

Parameters:
  • year (int) – Date components.

  • month (int) – Date components.

  • day (int) – Date components.

Returns:

Day of week (0-6).

Return type:

int

pyacs.lib.gpstime.gpsFromUTC(year, month, day, hour, minute, ssec, leapSecs=30)[source]

Convert UTC to GPS week, seconds of week, GPS day, seconds of day.

Parameters:
  • year (int) – UTC date/time components.

  • month (int) – UTC date/time components.

  • day (int) – UTC date/time components.

  • hour (int) – UTC date/time components.

  • minute (int) – UTC date/time components.

  • ssec (float) – Seconds (and fraction).

  • leapSecs (int, optional) – Leap seconds (GPS - UTC). Default is 30; update as leap seconds change.

Returns:

(gpsWeek, secsOfWeek, gpsDay, secsOfDay).

Return type:

tuple

Notes

GPS time is seconds since 1980-01-06 00:00:00. Week starts Saturday midnight. See http://www.oc.nps.navy.mil/~jclynch/timsys.html. Python uses integer seconds; fractional seconds in ssec are preserved in the return value.

pyacs.lib.gpstime.gpsWeek(year, month, day)[source]

Return full GPS week number for given UTC date.

Parameters:
  • year (int) – UTC date.

  • month (int) – UTC date.

  • day (int) – UTC date.

Returns:

GPS week number.

Return type:

int

pyacs.lib.gpstime.julianDay(year, month, day)[source]

Return day of year (1-366) for given date.

Parameters:
  • year (int) – Date components.

  • month (int) – Date components.

  • day (int) – Date components.

Returns:

Day since Jan 1 of year.

Return type:

int

pyacs.lib.gpstime.mkUTC(year, month, day, hour, minute, sec)[source]

Convert UTC date/time to seconds since epoch (like mktime but for UTC).

Parameters:
  • year (int or float) – UTC components.

  • month (int or float) – UTC components.

  • day (int or float) – UTC components.

  • hour (int or float) – UTC components.

  • minute (int or float) – UTC components.

  • sec (int or float) – UTC components.

Returns:

Seconds since epoch.

Return type:

float

pyacs.lib.gpstime.testDayOfWeek()[source]
pyacs.lib.gpstime.testGpsWeek()[source]
pyacs.lib.gpstime.testJulD()[source]
pyacs.lib.gpstime.testPyUtilties()[source]
pyacs.lib.gpstime.testTimeStuff()[source]
pyacs.lib.gpstime.wtFromUTCpy(pyUTC, leapSecs=14)[source]

Convert Python UTC time to GPS week and time of week.

Parameters:
  • pyUTC (float) – Seconds since epoch (UTC).

  • leapSecs (int, optional) – Leap seconds offset. Default is 14.

Returns:

(gpsWeek, secsOfWeek).

Return type:

tuple

pyacs.lib.gpstime.ymdhmsFromPyUTC(pyUTC)[source]

Return (year, month, day, hour, minute, sec) from Python UTC time.

Parameters:

pyUTC (float) – Seconds since epoch (e.g. from time.time()).

Returns:

(year, month, day, hour, minute, sec).

Return type:

tuple