def test_veto_flag(self): d = query_flag('L1', 'data', 1126051217, 1126051217 + 100000, cache=True) v1n = query_flag('L1', 'CBC_HW_INJ', 1126051217, 1126051217 + 100000, cache=True) v1 = query_flag('L1', 'CBC_HW_INJ', 1126051217, 1126051217 + 100000, cache=True) self.assertTrue(abs((v1 + v1n).coalesce() - d) == 0) v2n = query_flag('L1', 'CBC_CAT2', 1126051217, 1126051217 + 100000, cache=True) v2 = query_flag('L1', 'CBC_CAT2_VETO', 1126051217, 1126051217 + 100000, cache=True) self.assertTrue(abs((v2 + v2n).coalesce() - d) == 0)
def test_query_str(self): d = query_flag('H1', 'data', 1126051217, 1126051217 + 100000) d1 = query_str('H1', '+data', 1126051217, 1126051217 + 100000) d2 = query_str('H1', '+H1:data', 1126051217, 1126051217 + 100000) d3 = query_str('H1', '+data[1126051217:1127051217]', 1126051217, 1126051217 + 100000) d4 = query_str('H1', '+data<0:0>[1126051217:1127051217]', 1126051217, 1126051217 + 100000) self.assertTrue(abs(d - d1) == 0) self.assertTrue(abs(d - d2) == 0) self.assertTrue(abs(d - d3) == 0) self.assertTrue(abs(d - d4) == 0) d5 = query_str('L1', '+data', 1126051217, 1126051217 + 100000) d6 = query_str('H1', '+L1:data', 1126051217, 1126051217 + 100000) self.assertTrue(abs(d5 - d6) == 0) d7 = query_flag('H1', 'CBC_HW_INJ', 1126051217, 1126051217 + 100000, cache=True) d8 = query_str('H1', '+data,-CBC_HW_INJ', 1126051217, 1126051217 + 100000) self.assertTrue(abs((d - d7) - d8) == 0)
def test_cumulative_query(self): segs1 = query_flag('H1', 'CBC_HW_INJ', 1126051217, 1126051217 + 100000, cache=True) segs2 = query_flag('H1', 'BURST_HW_INJ', 1126051217, 1126051217 + 100000, cache=True) segs = query_cumulative_flags('H1', ['CBC_HW_INJ', 'BURST_HW_INJ'], 1126051217, 1126051217 + 100000, cache=True) csegs = (segs1 + segs2).coalesce() self.assertTrue(abs(csegs - segs) == 0)
def test_direct_query(self): segs = query_flag('H1', 'DATA', 1126051217, 1126051217 + 100000, cache=True) self.assertTrue(len(segs) > 0)
def test_direct_empty_return(self): segs = query_flag('H1', 'DATA', 1126051217, 1126051217 + 1000, cache=True) self.assertTrue(len(segs) == 0)
def test_query_str(self): d = query_flag('H1', 'data', 1126051217, 1126051217 + 100000) d1 = query_str('H1', '+data', 1126051217, 1126051217 + 100000) d2 = query_str('H1', '+H1:data', 1126051217, 1126051217 + 100000) d3 = query_str('H1', '+data:1', 1126051217, 1126051217 + 100000) d4 = query_str('H1', '+data<0:0>[1126051217:1127051217]', 1126051217, 1126051217 + 100000) self.assertTrue(abs(d - d1) == 0) self.assertTrue(abs(d - d2) == 0) self.assertTrue(abs(d - d3) == 0) self.assertTrue(abs(d - d4) == 0) d5 = query_str('L1', '+data', 1126051217, 1126051217 + 100000) d6 = query_str('H1', '+L1:data', 1126051217, 1126051217 + 100000) self.assertTrue(abs(d5 - d6) == 0) d7 = query_flag('H1', 'CBC_HW_INJ', 1126051217, 1126051217 + 100000, cache=True) d8 = query_str('H1', '+data,-CBC_HW_INJ', 1126051217, 1126051217 + 100000) self.assertTrue(abs((d-d7) - d8) == 0)
"""This example shows how to determine when a CBC hardware injection is present in the data from a detector. """ import matplotlib.pyplot as pp from pycbc import dq start_time = 1126051217 end_time = start_time + 10000000 # Get times that the Livingston detector has CBC injections into the data segs = dq.query_flag('L1', 'CBC_HW_INJ', start_time, end_time) pp.figure(figsize=[10, 2]) for seg in segs: start, end = seg pp.axvspan(start, end, color='blue') pp.xlabel('Time (s)') pp.show()
def check_validtimes(detector, gps_start, gps_end, shift_to_valid=False, max_shift=None, segment_name='DATA', **kwargs): r"""Checks DQ server to see if the given times are in a valid segment. If the ``shift_to_valid`` flag is provided, the times will be shifted left or right to try to find a continous valid block nearby. The shifting starts by shifting the times left by 1 second. If that does not work, it shifts the times right by one second. This continues, increasing the shift time by 1 second, until a valid block could be found, or until the shift size exceeds ``max_shift``. If the given times are not in a continuous valid segment, or a valid block cannot be found nearby, a ``NoValidDataError`` is raised. Parameters ---------- detector : str The name of the detector to query; e.g., 'H1'. gps_start : int The GPS start time of the segment to query. gps_end : int The GPS end time of the segment to query. shift_to_valid : bool, optional If True, will try to shift the gps start and end times to the nearest continous valid segment of data. Default is False. max_shift : int, optional The maximum number of seconds to try to shift left or right to find a valid segment. Default is ``gps_end - gps_start``. segment_name : str, optional The status flag to query; passed to :py:func:`pycbc.dq.query_flag`. Default is "DATA". \**kwargs : All other keyword arguments are passed to :py:func:`pycbc.dq.query_flag`. Returns ------- use_start : int The start time to use. If ``shift_to_valid`` is True, this may differ from the given GPS start time. use_end : int The end time to use. If ``shift_to_valid`` is True, this may differ from the given GPS end time. """ # expand the times checked encase we need to shift if max_shift is None: max_shift = int(gps_end - gps_start) check_start = gps_start - max_shift check_end = gps_end + max_shift # if we're running in an mpi enviornment and we're not the parent process, # we'll wait before quering the segment database. This will result in # getting the segments from the cache, so as not to overload the database if MPI is not None and (MPI.COMM_WORLD.Get_size() > 1 and MPI.COMM_WORLD.Get_rank() != 0): # we'll wait for 2 minutes sleep(120) validsegs = dq.query_flag(detector, segment_name, check_start, check_end, cache=True, **kwargs) use_start = gps_start use_end = gps_end # shift if necessary if shift_to_valid: shiftsize = 1 while (use_start, use_end) not in validsegs and shiftsize < max_shift: # try shifting left use_start = gps_start - shiftsize use_end = gps_end - shiftsize if (use_start, use_end) not in validsegs: # try shifting right use_start = gps_start + shiftsize use_end = gps_end + shiftsize shiftsize += 1 # check that we have a valid range if (use_start, use_end) not in validsegs: raise NoValidDataError("Could not find a continous valid segment in " "in detector {}".format(detector)) return use_start, use_end
"""This example shows how to determine when a detector is active.""" import matplotlib.pyplot as pp from pycbc import dq from pycbc.results import ifo_color start_time = 1126051217 end_time = start_time + 100000 # Get times that the Hanford detector has data hsegs = dq.query_flag('H1', 'DATA', start_time, end_time) # Get times that the Livingston detector has data lsegs = dq.query_flag('L1', 'DATA', start_time, end_time) pp.figure(figsize=[10, 2]) for seg in lsegs: start, end = seg pp.axvspan(start, end, color=ifo_color('L1'), ymin=0.1, ymax=0.4) for seg in hsegs: start, end = seg pp.axvspan(start, end, color=ifo_color('H1'), ymin=0.6, ymax=0.9) pp.xlabel('Time (s)') pp.show()