def from_veto_definer_file(cls, fp, start=None, end=None, ifo=None, format='ligolw'): """Read a `DataQualityDict` from a LIGO_LW XML VetoDefinerTable. """ if start is not None: start = to_gps(start) if end is not None: end = to_gps(end) # read veto definer file from gwpy.table.lsctables import VetoDefTable veto_def_table = VetoDefTable.read(fp, format=format) # parse flag definitions out = cls() for row in veto_def_table: if ifo and row.ifo != ifo: continue if start and 0 < row.end_time < start: continue elif start: row.start_time = max(row.start_time, start) if end and row.start_time > end: continue elif end and not row.end_time: row.end_time = end elif end: row.end_time = min(row.end_time, end) flag = DataQualityFlag.from_veto_def(row) if flag.name in out: out[flag.name].known.extend(flag.known) out[flag.name].known.coalesce() else: out[flag.name] = flag return out
def from_veto_definer_file(cls, fp, start=None, end=None, ifo=None, format='ligolw'): """Read a `DataQualityDict` from a LIGO_LW XML VetoDefinerTable. Parameters ---------- fp : `str` path of veto definer file to read start : `~gwpy.time.LIGOTimeGPS`, `int`, optional GPS start time at which to restrict returned flags end : `~gwpy.time.LIGOTimeGPS`, `int`, optional GPS end time at which to restrict returned flags ifo : `str`, optional interferometer prefix whose flags you want to read format : `str`, optional format of file to read (passed to `VetoDefTable.read`), currently only 'ligolw' is supported Returns ------- flags : `DataQualityDict` a `DataQualityDict` of flags parsed from the `veto_def_table` of the input file. Notes ----- This method does not automatically `~DataQualityDict.populate` the `active` segment list of any flags, a separate call should be made for that as follows >>> flags = DataQualityDict.from_veto_definer_file('/path/to/file.xml') >>> flags.populate() """ if start is not None: start = to_gps(start) if end is not None: end = to_gps(end) # read veto definer file from gwpy.table.lsctables import VetoDefTable if urlparse(fp).scheme in ['http', 'https']: response = request.urlopen(fp) local = tempfile.NamedTemporaryFile() with tempfile.NamedTemporaryFile() as temp: temp.write(response.read()) temp.flush() veto_def_table = VetoDefTable.read(temp.name, format=format) else: veto_def_table = VetoDefTable.read(fp, format=format) # parse flag definitions out = cls() for row in veto_def_table: if ifo and row.ifo != ifo: continue if start and 0 < row.end_time < start: continue elif start: row.start_time = max(row.start_time, start) if end and row.start_time > end: continue elif end and not row.end_time: row.end_time = end elif end: row.end_time = min(row.end_time, end) flag = DataQualityFlag.from_veto_def(row) if flag.name in out: out[flag.name].known.extend(flag.known) out[flag.name].known.coalesce() else: out[flag.name] = flag return out
def from_veto_definer_file(cls, fp, start=None, end=None, ifo=None, format='ligolw'): """Read a `DataQualityDict` from a LIGO_LW XML VetoDefinerTable. Parameters ---------- fp : `str` path of veto definer file to read start : `~gwpy.time.LIGOTimeGPS`, `int`, optional GPS start time at which to restrict returned flags end : `~gwpy.time.LIGOTimeGPS`, `int`, optional GPS end time at which to restrict returned flags ifo : `str`, optional interferometer prefix whose flags you want to read format : `str`, optional format of file to read (passed to `VetoDefTable.read`), currently only 'ligolw' is supported Returns ------- flags : `DataQualityDict` a `DataQualityDict` of flags parsed from the `veto_def_table` of the input file. Notes ----- This method does not automatically `~DataQualityDict.populate` the `active` segment list of any flags, a separate call should be made for that as follows >>> flags = DataQualityDict.from_veto_definer_file('/path/to/file.xml') >>> flags.populate() """ if start is not None: start = to_gps(start) if end is not None: end = to_gps(end) # read veto definer file from gwpy.table.lsctables import VetoDefTable if urlparse(fp).scheme in ['http', 'https']: response = request.urlopen(fp) with tempfile.NamedTemporaryFile() as temp: temp.write(response.read()) temp.flush() veto_def_table = VetoDefTable.read(temp.name, format=format) else: veto_def_table = VetoDefTable.read(fp, format=format) # parse flag definitions out = cls() for row in veto_def_table: if ifo and row.ifo != ifo: continue if start and 0 < row.end_time < start: continue elif start: row.start_time = max(row.start_time, start) if end and row.start_time > end: continue elif end and not row.end_time: row.end_time = end elif end: row.end_time = min(row.end_time, end) flag = DataQualityFlag.from_veto_def(row) if flag.name in out: out[flag.name].known.extend(flag.known) out[flag.name].known.coalesce() else: out[flag.name] = flag return out