Skip to content

Commit 6230eaa

Browse files
PyCBC Live: use Astropy to get a more precise current GPS time (#3583)
lal.GPSTimeNow() does not return the fractional part, which is a bit annoying when monitoring the O(1 s) lag of the early-warning configuration. I also simplified the logging a bit by pre-inserting the MPI rank in the format string.
1 parent d593203 commit 6230eaa

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

bin/pycbc_live

+13-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ See https://arxiv.org/abs/1805.11174 for an overview."""
1111

1212
import sys
1313
import argparse, numpy, pycbc, logging, cProfile, h5py, lal, json
14-
from time import time
1514
import os.path
1615
import itertools
1716
import platform
@@ -33,6 +32,7 @@ import pycbc.waveform.bank
3332
from pycbc.vetoes.sgchisq import SingleDetSGChisq
3433
from pycbc.waveform.waveform import props
3534
from pycbc import mchirp_area
35+
3636
try:
3737
from setproctitle import setproctitle
3838
except ImportError:
@@ -639,7 +639,8 @@ fft.verify_fft_options(args, parser)
639639
if args.output_background is not None and len(args.output_background) != 2:
640640
parser.error('--output-background takes two parameters: period and path')
641641

642-
log_format = "%(asctime)s {0} %(message)s".format(platform.node())
642+
log_format = '%(asctime)s {} {} %(message)s'.format(platform.node(),
643+
mpi.COMM_WORLD.Get_rank())
643644
pycbc.init_logging(args.verbose, format=log_format)
644645

645646
ctx = scheme.from_cli(args)
@@ -725,7 +726,7 @@ with ctx:
725726
# Synchronize start time if not provided on the command line
726727
if not args.start_time:
727728
evnt.barrier()
728-
tnow = lal.GPSTimeNow() if evnt.rank == 0 else None
729+
tnow = int(pycbc.gps_now()) if evnt.rank == 0 else None
729730
args.start_time = evnt.comm.bcast(tnow, root=0)
730731

731732
if args.round_start_time:
@@ -776,7 +777,7 @@ with ctx:
776777
coinc_pool = BroadcastPool(len(estimators))
777778
coinc_pool.allmap(set_coinc_id, range(len(estimators)))
778779

779-
logging.info('%s: Starting...', evnt.rank)
780+
logging.info('Starting')
780781

781782
if args.enable_profiling is not None and evnt.rank == args.enable_profiling:
782783
pr = cProfile.Profile()
@@ -786,8 +787,8 @@ with ctx:
786787
data_end = lambda: data_reader[tuple(data_reader.keys())[0]].end_time
787788
last_bg_dump_time = int(data_end())
788789
while data_end() < args.end_time:
789-
t1 = time()
790-
logging.info('%s: Analyzing from %s', evnt.rank, data_end())
790+
t1 = pycbc.gps_now()
791+
logging.info('Analyzing from %s', data_end())
791792

792793
results = {}
793794
evnt.live_detectors = set()
@@ -810,7 +811,7 @@ with ctx:
810811
if status is True:
811812
evnt.live_detectors.add(ifo)
812813
if evnt.rank > 0:
813-
logging.info('%s: Filtering %s', evnt.rank, ifo)
814+
logging.info('Filtering %s', ifo)
814815
results[ifo] = mf.process_data(data_reader[ifo])
815816
else:
816817
logging.info('Insufficient data for %s analysis', ifo)
@@ -901,11 +902,11 @@ with ctx:
901902

902903
if args.sync:
903904
evnt.barrier()
904-
tdiff = time() - t1
905-
lag = float(lal.GPSTimeNow() - data_end())
906-
logging.info('%s: Took %1.2f, duty factor of %.2f, '
905+
tdiff = pycbc.gps_now() - t1
906+
lag = float(pycbc.gps_now() - data_end())
907+
logging.info('Took %1.2f, duty factor of %.2f, '
907908
'lag %.2f s, %d live detectors',
908-
evnt.rank, tdiff, tdiff / valid_pad, lag,
909+
tdiff, tdiff / valid_pad, lag,
909910
len(evnt.live_detectors))
910911

911912
if args.output_status is not None and evnt.rank == 0:
@@ -925,7 +926,7 @@ with ctx:
925926
'start_sec': 240})
926927
status = {'author': 'Tito Dal Canton',
927928
'email': 'tito.canton@ligo.org',
928-
'created_gps': int(lal.GPSTimeNow()),
929+
'created_gps': int(pycbc.gps_now()),
929930
'status_intervals': status_intervals}
930931
try:
931932
with open(args.output_status, 'w') as status_fp:

pycbc/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,10 @@ def random_string(stringLength=10):
149149
"""Generate a random string of fixed length """
150150
letters = string.ascii_lowercase
151151
return ''.join(random.choice(letters) for i in range(stringLength))
152+
153+
def gps_now():
154+
"""Return the current GPS time as a float using Astropy.
155+
"""
156+
from astropy.time import Time
157+
158+
return float(Time.now().gps)

pycbc/frame/frame.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import math
2424
import os.path, glob, time
2525
import gwdatafind
26+
import pycbc
2627
from six.moves.urllib.parse import urlparse
2728
from pycbc.types import TimeSeries, zeros
2829

@@ -635,7 +636,7 @@ def attempt_advance(self, blocksize, timeout=10):
635636
return DataBuffer.advance(self, blocksize)
636637

637638
except RuntimeError:
638-
if lal.GPSTimeNow() > timeout + self.raw_buffer.end_time:
639+
if pycbc.gps_now() > timeout + self.raw_buffer.end_time:
639640
# The frame is not there and it should be by now, so we give up
640641
# and treat it as zeros
641642
DataBuffer.null_advance(self, blocksize)

0 commit comments

Comments
 (0)