All gravitational-wave data are recorded with timestamps in the GPS time system (recording the absolute number of seconds since the start of the GPS epoch at midnight on January 6th 1980).
The LIGO Scientific Collaboration stores such GPS times with nanosecond precision using the ligotimegps
object.
Astropy provides the excellent Time
object to allow easy conversion between this format and a number of other formats.
For convenience, this object is available in GWpy as gwpy.time.Time
.
On top of that, GWpy provides three simple methods to simplify converting between GPS times and Python-standard datetime
objects, namely:
tconvert |
Convert GPS times to ISO-format date-times and vice-versa. |
to_gps |
Convert any input date/time into a LIGOTimeGPS . |
from_gps |
Convert a GPS time into a datetime.datetime . |
gwpy.time.
tconvert
(gpsordate='now')[source]¶Convert GPS times to ISO-format date-times and vice-versa.
Parameters: | gpsordate :
|
---|---|
Returns: | date :
|
Notes
If the input object is a float
or LIGOTimeGPS
, it will get
converted from GPS format into a datetime.datetime
, otherwise
the input will be converted into LIGOTimeGPS
.
Examples
Integers and floats are automatically converted from GPS to
datetime.datetime
:
>>> from gwpy.time import tconvert
>>> tconvert(0)
datetime.datetime(1980, 1, 6, 0, 0)
>>> tconvert(1126259462.3910)
datetime.datetime(2015, 9, 14, 9, 50, 45, 391000)
while strings are automatically converted to LIGOTimeGPS
:
>>> to_gps('Sep 14 2015 09:50:45.391')
LIGOTimeGPS(1126259462, 391000000)
Additionally, a few special-case words as supported, which all return
LIGOTimeGPS
:
>>> tconvert('now')
>>> tconvert('today')
>>> tconvert('tomorrow')
>>> tconvert('yesterday')
gwpy.time.
to_gps
(t, *args, **kwargs)[source]¶Convert any input date/time into a LIGOTimeGPS
.
Any input object that can be cast as a Time
(with str
going through the datetime.datetime
) are acceptable.
Parameters: | t : *args, **kwargs
|
---|---|
Returns: | gps :
|
Raises: | TypeError
ValueError
|
Examples
>>> to_gps('Jan 1 2017')
LIGOTimeGPS(1167264018, 0)
>>> to_gps('Sep 14 2015 09:50:45.391')
LIGOTimeGPS(1126259462, 391000000)
>>> import datetime
>>> to_gps(datetime.datetime(2017, 1, 1))
LIGOTimeGPS(1167264018, 0)
>>> from astropy.time import Time
>>> to_gps(Time(57754, format='mjd'))
LIGOTimeGPS(1167264018, 0)
gwpy.time.
from_gps
(gps)[source]¶Convert a GPS time into a datetime.datetime
.
Parameters: |
|
---|---|
Returns: | datetime :
|
Examples
>>> from_gps(1167264018)
datetime.datetime(2017, 1, 1, 0, 0)
>>> from_gps(1126259462.3910)
datetime.datetime(2015, 9, 14, 9, 50, 45, 391000)