DataQualityDict

class gwpy.segments.DataQualityDict[source]

An dict of (key, DataQualityFlag) pairs.

Attributes Summary

read

Read segments from file into a DataQualityDict.

write

Write this DataQualityDict to file.

Methods Summary

clear()

coalesce()

Coalesce all segments lists in this DataQualityDict.

copy(*[, deep])

Build a copy of this dictionary.

from_ligolw_tables(segmentdeftable, ...[, ...])

Build a DataQualityDict from a set of LIGO_LW segment tables.

from_veto_definer_file(source[, start, end, ifo])

Read a DataQualityDict from a LIGO_LW XML VetoDefinerTable.

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

intersection()

Return the intersection of all flags in this dict.

items()

keys()

plot([label])

Plot this dict on a segments projection.

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

populate([source, segments, pad, on_error])

Query the segment database for each flag's active segments.

query(flags, *args[, host, on_error, parallel])

Query the advanced LIGO DQSegDB for a list of flags.

query_dqsegdb(flags, *args[, host, ...])

Query the advanced LIGO DQSegDB for a list of flags.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

to_ligolw_tables(**attrs)

Convert this DataQualityDict into a trio of LIGO_LW segment tables.

union()

Return the union of all flags in this dict.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Attributes Documentation

read

Read segments from file into a DataQualityDict.

Parameters:
sourcestr

Path of file to read

formatstr, optional

Source format identifier. If not given, the format will be detected if possible. See below for list of acceptable formats.

nameslist, optional, default: read all names found

List of names to read, by default all names are read separately.

coalescebool, optional

If True coalesce the all segment lists before returning, otherwise return exactly as contained in file(s).

parallelint, optional, default: 1

Number of threads to use for parallel reading of multiple files.

verbosebool, optional, default: False

Print a progress bar showing read status.

Returns:
flagdictDataQualityDict

A new DataQualityDict of DataQualityFlag entries with active and known segments seeded from the XML tables in the given file.

write

Write this DataQualityDict to file.

Methods Documentation

clear() None.  Remove all items from D.
coalesce() Self[source]

Coalesce all segments lists in this DataQualityDict.

This method modifies this object in-place.

Returns:
self

A view of this flag, not a copy.

copy(*, deep: bool = False) Self[source]

Build a copy of this dictionary.

Parameters:
deepbool, optional, default: False

perform a deep copy of the original dictionary with a fresh memory address

Returns:
flag2DataQualityFlag

a copy of the original dictionary

classmethod from_ligolw_tables(segmentdeftable: ligo.lw.lsctables.SegmentDefTable, segmentsumtable: ligo.lw.lsctables.SegmentSumTable, segmenttable: ligo.lw.lsctables.SegmentTable, names: list[str] | None = None, gpstype: type[SupportsFloat] | Callable[[float], SupportsFloat] = <class 'lal.LIGOTimeGPS'>, on_missing: str = 'error') Self[source]

Build a DataQualityDict from a set of LIGO_LW segment tables.

Parameters:
segmentdeftableSegmentDefTable

The segment_definer table to read.

segmentsumtableSegmentSumTable

The segment_summary table to read.

segmenttableSegmentTable

The segment table to read.

nameslist of str, optional

A list of flag names to read. Default is to read all names.

gpstypetype, callable, optional

Class to use for GPS times in returned objects, can be a function to convert GPS time to something else. Default is LIGOTimeGPS.

on_missingstr, optional

Action to take when a one or more names are not found in the segment_definer table, one of

  • 'ignore' : do nothing

  • 'warn' : print a warning

  • error' : raise a ValueError

Returns:
dqdictDataQualityDict

A dict of DataQualityFlag objects populated from the LIGO_LW tables.

classmethod from_veto_definer_file(source: str, start: GpsLike | None = None, end: GpsLike | None = None, ifo: str | None = None, **read_kw) Self[source]

Read a DataQualityDict from a LIGO_LW XML VetoDefinerTable.

Parameters:
sourcestr, Path, file

Path or URL of veto definer file to read, or open file.

startLIGOTimeGPS, float, str

GPS start time of required data, any input parseable by to_gps is fine

endLIGOTimeGPS, float, str

GPS end time of required data, any input parseable by to_gps is fine

ifostr, optional

Interferometer prefix whose flags you want to read. Default is None (read all flags).

read_kw

Other keyword arguments are passed to read when reading the veto definer file.

Returns:
flagsDataQualityDict

A DataQualityDict of flags parsed from the veto_def_table of the input file.

Notes

This method does not automatically 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()
classmethod fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

intersection() DataQualityFlag[source]

Return the intersection of all flags in this dict.

Returns:
intersectionDataQualityFlag

a new DataQualityFlag who’s active and known segments are the intersection of those of the values of this dict

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
plot(label: str = 'key', **kwargs) Plot[source]

Plot this dict on a segments projection.

Parameters:
labelstr, optional

Labelling system to use, or fixed label for all flags, special values include

If anything else, that fixed label will be used for all lines.

kwargs

All keyword arguments are passed to the Plot constructor.

Returns:
figureFigure

the newly created figure, with populated Axes.

See also

matplotlib.pyplot.figure

For documentation of keyword arguments used to create the figure.

matplotlib.figure.Figure.add_subplot

For documentation of keyword arguments used to create the axes.

gwpy.plot.SegmentAxes.plot_segmentlist

For documentation of keyword arguments used in rendering the data.

pop(key, default=<unrepresentable>, /)

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

populate(source: str | None = 'http://segments.ldas.cit', segments: SegmentList | None = None, *, pad: bool = True, on_error: str = 'raise', **kwargs) Self[source]

Query the segment database for each flag’s active segments.

This method assumes all of the metadata for each flag have been filled. Minimally, the following attributes must be filled

name

The name associated with this flag.

known

The segments during which this flag was known.

Segments will be fetched from the database, with any padding added on-the-fly.

Entries in this dict will be modified in-place.

Parameters:
sourcestr

Source of segments for this flag. This must be either a URL for a segment database or a path to a file on disk.

segmentsSegmentList, optional

A list of known segments during which to query, if not given, existing known segments for flags will be used.

padbool, optional, default: True

Apply the padding associated with each flag, default: True.

on_errorstr

How to handle an error querying for one flag, one of

  • 'raise' (default): raise the Exception

  • 'warn': print a warning

  • 'ignore': move onto the next flag as if nothing happened

kwargs

Any other keyword arguments to be passed to DataQualityFlag.query() or DataQualityFlag.read().

Returns:
selfDataQualityDict

A reference to the modified DataQualityDict

classmethod query(flags: list[str], *args: GpsLike | Segment | SegmentList, host: str | None = 'http://segments.ldas.cit', on_error: str = 'raise', parallel: int = 10, **kwargs) Self[source]

Query the advanced LIGO DQSegDB for a list of flags.

Parameters:
flagsiterable

A list of flag names for which to query.

args

Either, two float-like numbers indicating the GPS [start, stop) interval, or a SegmentList defining a number of summary segments.

hoststr, optional

Name or URL of the DQSegDB instance to talk to. Defaults to dqsegdb2.utils.get_default_host().

on_errorstr, optional

how to handle an error querying for one flag, one of

  • 'raise' (default): raise the Exception

  • 'warn': print a warning

  • 'ignore': move onto the next flag as if nothing happened

parallelint, optional

Maximum number of threads to use for parallel connections to the DQSegDB host.

kwargs

All other keyword arguments are passed to dqsegdb2.query.query_segments().

Returns:
flagdictDataQualityDict

An ordered DataQualityDict of (name, DataQualityFlag) pairs.

Examples

The GPS interval(s) of interest can be passed as two arguments specifing the start and end of a single interval:

>>> DataQualityDict.query_dqsegdb(["X1:OBSERVING:1", "Y1:OBSERVING:1"], start, end)

Or, as a single Segment:

>>> DataQualityDict.query_dqsegdb(["X1:OBSERVING:1", "Y1:OBSERVING:1"], interval)

Or, as a SegmentList specifying multiple intervals.

>>> DataQualityDict.query_dqsegdb(["X1:OBSERVING:1", "Y1:OBSERVING:1"], intervals)
classmethod query_dqsegdb(flags: list[str], *args: GpsLike | Segment | SegmentList, host: str | None = 'http://segments.ldas.cit', on_error: str = 'raise', parallel: int = 10, **kwargs) Self[source]

Query the advanced LIGO DQSegDB for a list of flags.

Parameters:
flagsiterable

A list of flag names for which to query.

args

Either, two float-like numbers indicating the GPS [start, stop) interval, or a SegmentList defining a number of summary segments.

hoststr, optional

Name or URL of the DQSegDB instance to talk to. Defaults to dqsegdb2.utils.get_default_host().

on_errorstr, optional

how to handle an error querying for one flag, one of

  • 'raise' (default): raise the Exception

  • 'warn': print a warning

  • 'ignore': move onto the next flag as if nothing happened

parallelint, optional

Maximum number of threads to use for parallel connections to the DQSegDB host.

kwargs

All other keyword arguments are passed to dqsegdb2.query.query_segments().

Returns:
flagdictDataQualityDict

An ordered DataQualityDict of (name, DataQualityFlag) pairs.

Examples

The GPS interval(s) of interest can be passed as two arguments specifing the start and end of a single interval:

>>> DataQualityDict.query_dqsegdb(["X1:OBSERVING:1", "Y1:OBSERVING:1"], start, end)

Or, as a single Segment:

>>> DataQualityDict.query_dqsegdb(["X1:OBSERVING:1", "Y1:OBSERVING:1"], interval)

Or, as a SegmentList specifying multiple intervals.

>>> DataQualityDict.query_dqsegdb(["X1:OBSERVING:1", "Y1:OBSERVING:1"], intervals)
setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

to_ligolw_tables(**attrs) tuple[ligo.lw.lsctables.SegmentDefTable, ligo.lw.lsctables.SegmentSumTable, ligo.lw.lsctables.SegmentTable][source]

Convert this DataQualityDict into a trio of LIGO_LW segment tables.

Parameters:
attrs

Other attributes to add to all rows in all tables (e.g. 'process_id').

Returns:
segmentdeftableSegmentDefTable

The segment_definer table.

segmentsumtableSegmentSumTable

The segment_summary table.

segmenttableSegmentTable

The segment table.

union() DataQualityFlag[source]

Return the union of all flags in this dict.

Returns:
unionDataQualityFlag

a new DataQualityFlag who’s active and known segments are the union of those of the values of this dict

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values