Gitlab will migrate to a new storage backend starting 0300 UTC on 2020-04-04. We do not anticipate a maintenance window for this migration. Performance may be impacted over the weekend. Thanks for your patience.

Commit 4102eca1 authored by Patrick Godwin's avatar Patrick Godwin

replace lal gpstime utilities with stdlib + dateutil

parent d15f6652
Pipeline #68644 failed with stages
in 6 minutes and 57 seconds
......@@ -25,8 +25,7 @@ import time
import numpy
import lal
from lal import LIGOTimeGPS
from . import utils
#-------------------------------------------------
......@@ -43,7 +42,7 @@ def now():
"""!
A convenience function to return the current gps time
"""
return float(LIGOTimeGPS(lal.UTCToGPS(time.gmtime()), 0))
return utils.gps_now()
def median(l):
......
......@@ -22,8 +22,6 @@ from six.moves import urllib
import numpy
import urllib3
import lal
from .. import aggregator
from . import common
from . import line_protocol
......
......@@ -18,8 +18,6 @@ except ImportError:
import bottle
import numpy
from lal import gpstime
from . import aggregator
from . import utils
......@@ -243,8 +241,8 @@ def random_trigger_value(field, size, far_threshold = 1e-2):
def _convert_gps_times(gps_times, epoch):
if epoch == 'ns':
return utils.gps_to_unix(gps_times)
elif epoch == 'datetime':
return [gpstime.gps_to_str(t, "%Y-%m-%dT%H:%M:%S.%fZ") for t in gps_times]
else:
raise NotImplementedError
def _add_parser_args(parser):
parser.add_argument('-b', '--backend', default='wsgiref',
......
......@@ -7,6 +7,7 @@ __description__ = "a module to store commonly used utility functions"
### imports
import argparse
import bisect
from collections import namedtuple
import functools
import json
......@@ -17,14 +18,41 @@ import sys
import time
import timeit
from datetime import datetime
from dateutil.tz import tzutc
from dateutil.parser import parse as str_to_utc
import h5py
import numpy
from scipy.interpolate import interp1d
import lal
from lal import gpstime
EPOCH_UNIX_GPS = 315964800
from . import aggregator
#-------------------------------------------------
### leapseconds utilities
leapseconds_table = [
46828800, # 1981-Jul-01
78364801, # 1982-Jul-01
109900802, # 1983-Jul-01
173059203, # 1985-Jul-01
252028804, # 1988-Jan-01
315187205, # 1990-Jan-01
346723206, # 1991-Jan-01
393984007, # 1992-Jul-01
425520008, # 1993-Jul-01
457056009, # 1994-Jul-01
504489610, # 1996-Jan-01
551750411, # 1997-Jul-01
599184012, # 1999-Jan-01
820108813, # 2006-Jan-01
914803214, # 2009-Jan-01
1025136015, # 2012-Jul-01
1119744016, # 2015-Jul-01
1167264017, # 2017-Jan-01
]
def leapseconds(gpstime):
return bisect.bisect_left(leapseconds_table, gpstime)
#-------------------------------------------------
......@@ -111,7 +139,8 @@ def gps_now():
"""
Returns the current gps time.
"""
return float(lal.GPSTimeNow()) + (timeit.default_timer() % 1)
gpsnow = time.time() - EPOCH_UNIX_GPS
return gpsnow + leapseconds(gpsnow)
def gps_to_latency(gps_time):
......@@ -128,7 +157,11 @@ def rfc3339_to_gps(time_str):
if time_str[-1] != 'Z':
raise ValueError('missing Z indicating UTC+0')
return float(gpstime.str_to_gps(time_str[:-1]))
#utc = str_to_utc(time_str[:-1])
utc = str_to_utc(time_str, tzinfos={'Z': 0})
tdelta = utc - datetime.fromtimestamp(0, tzutc())
gps_time = tdelta.total_seconds() - EPOCH_UNIX_GPS
return gps_time + leapseconds(gps_time)
def gps_to_unix(gps_time):
......@@ -136,19 +169,19 @@ def gps_to_unix(gps_time):
Converts from GPS to UNIX time, allows use of numpy arrays or scalars.
"""
if isinstance(gps_time, numpy.ndarray):
leapseconds = lal.GPSLeapSeconds(int(gps_time[0]))
return ((gps_time + lal.EPOCH_UNIX_GPS - leapseconds) * 1e9).astype(int)
leapsec = leapseconds(int(gps_time[0]))
return ((gps_time + EPOCH_UNIX_GPS - leapsec) * 1e9).astype(int)
else:
leapseconds = lal.GPSLeapSeconds(int(gps_time))
return int((gps_time + lal.EPOCH_UNIX_GPS - leapseconds) * 1e9)
leapsec = leapseconds(int(gps_time))
return int((gps_time + EPOCH_UNIX_GPS - leapsec) * 1e9)
def unix_to_gps(unix_time):
"""
Converts from UNIX to GPS time, allows use of numpy arrays or scalars.
"""
### FIXME: doesn't handle leapseconds correctly, should use lal.GPSLeapSeconds
return (unix_time / 1e9) - lal.EPOCH_UNIX_GPS + 18
### FIXME: doesn't handle leapseconds correctly
return (unix_time / 1e9) - EPOCH_UNIX_GPS + 18
#-------------------------------------------------
......
bottle==0.12.16
h5py==2.9.0
ligo-common==1.0.3
ligo-segments==1.2.0
numpy==1.16.1
PyYAML==3.13
scipy==1.2.1
urllib3==1.10.2
bottle>=0.12
h5py>=2.3
ligo-common>=1.0
numpy>=1.7
PyYAML>=3.10
urllib3>=1.10
python-dateutil
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment