gwpy.segments.
DataQualityDict
[source]¶Bases: collections.OrderedDict
An OrderedDict
of (key, DataQualityFlag
) pairs.
Since the DataQualityDict
is an OrderedDict
, all iterations over
its elements retain the order in which they were inserted.
Methods Summary
|
|
|
Coalesce all segments lists in this |
|
Build a copy of this dictionary. |
|
Build a |
|
Read a |
|
Create a new ordered dictionary with keys from iterable and values set to value. |
|
Return the value for key if key is in the dictionary, else default. |
|
Return the intersection of all flags in this dict |
|
|
|
|
|
Move an existing element to the end (or beginning if last is false). |
|
Plot this flag on a segments projection. |
|
value. |
|
Remove and return a (key, value) pair from the dictionary. |
|
Query the segment database for each flag’s active segments. |
|
Query for segments of a set of flags. |
|
Query the advanced LIGO DQSegDB for a list of flags. |
|
Query the inital LIGO segment database for a list of flags. |
|
Read segments from file into a |
|
Insert key with a value of default if key is not in the dictionary. |
|
Convert this |
|
Return the union of all flags in this dict |
|
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] |
|
|
|
Write this |
Methods Documentation
clear
()¶coalesce
(self)[source]¶Coalesce all segments lists in this DataQualityDict
.
This method modifies this object in-place.
self
a view of this flag, not a copy.
copy
(self, deep=False)[source]¶Build a copy of this dictionary.
deep : bool
, optional, default: False
perform a deep copy of the original dictionary with a fresh memory address
flag2 : DataQualityFlag
a copy of the original dictionary
from_ligolw_tables
(segmentdeftable, segmentsumtable, segmenttable, names=None, gpstype=<class 'lal.LIGOTimeGPS'>, on_missing='error')[source]¶Build a DataQualityDict
from a set of LIGO_LW segment tables
segmentdeftable : SegmentDefTable
the
segment_definer
table to read
segmentsumtable : SegmentSumTable
the
segment_summary
table to read
segmenttable : SegmentTable
the
segment
table to read
a list of flag names to read, defaults to returning all
gpstype : type
, 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_missing : str
, optional
action to take when a one or more
names
are not found in thesegment_definer
table, one of
'ignore'
: do nothing
'warn'
: print a warning
error'
: raise aValueError
dqdict : DataQualityDict
a dict of
DataQualityFlag
objects populated from the LIGO_LW tables
from_veto_definer_file
(fp, start=None, end=None, ifo=None, format='ligolw')[source]¶Read a DataQualityDict
from a LIGO_LW XML VetoDefinerTable.
fp : str
path of veto definer file to read
start : LIGOTimeGPS
, int
, optional
GPS start time at which to restrict returned flags
end : 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, currently only ‘ligolw’ is supported
flags : DataQualityDict
a
DataQualityDict
of flags parsed from theveto_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()
fromkeys
(iterable, value=None)¶Create a new ordered dictionary with keys from iterable and values set to value.
get
(self, key, default=None, /)¶Return the value for key if key is in the dictionary, else default.
intersection
(self)[source]¶Return the intersection of all flags in this dict
intersection : DataQualityFlag
a new
DataQualityFlag
who’s active and known segments are the intersection of those of the values of this dict
items
()¶keys
()¶move_to_end
(self, /, key, last=True)¶Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
plot
(self, label='key', **kwargs)[source]¶Plot this flag on a segments projection.
label : str
, optional
Labelling system to use, or fixed label for all flags, special values include
'key'
: use the key of theDataQualityDict
,
'name'
: use thename
of the flagIf anything else, that fixed label will be used for all lines.
**kwargs
all keyword arguments are passed to the
Plot
constructor.
figure : Figure
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
()¶value. If key is not found, d is returned if given, otherwise KeyError is raised.
popitem
(self, /, last=True)¶Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
populate
(self, source='http://segments.ldas.cit', segments=None, pad=True, on_error='raise', **kwargs)[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
The name associated with this flag. |
|
The set of segments during which this flag was known, and its state was well defined. |
Segments will be fetched from the database, with any
padding
added on-the-fly.
Entries in this dict will be modified in-place.
source : str
source of segments for this flag. This must be either a URL for a segment database or a path to a file on disk.
segments : SegmentList
, optional
a list of known segments during which to query, if not given, existing known segments for flags will be used.
pad : bool
, optional, default: True
on_error : str
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()
orDataQualityFlag.read()
.
self : DataQualityDict
a reference to the modified DataQualityDict
query
(flags, *args, **kwargs)[source]¶Query for segments of a set of flags.
This method intelligently selects the query_segdb
or the query_dqsegdb
methods based on the
url
kwarg given.
flags : iterable
A list of flag names for which to query.
*args
Either, two
float
-like numbers indicating the GPS [start, stop) interval, or aSegmentList
defining a number of summary segments
url : str
, optional
URL of the segment database, defaults to
$DEFAULT_SEGMENT_SERVER
environment variable, or'https://segments.ligo.org'
flagdict : DataQualityDict
A
dict
of(name, DataQualityFlag)
pairs
See also
DataQualityDict.query_segdb
DataQualityDict.query_dqsegdb
for details on the actual query engine, and documentation of other keyword arguments appropriate for each query
query_dqsegdb
(flags, *args, **kwargs)[source]¶Query the advanced LIGO DQSegDB for a list of flags.
flags : iterable
A list of flag names for which to query.
*args
Either, two
float
-like numbers indicating the GPS [start, stop) interval, or aSegmentList
defining a number of summary segments.
on_error : str
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
url : str
, optional
URL of the segment database, defaults to
$DEFAULT_SEGMENT_SERVER
environment variable, or'https://segments.ligo.org'
flagdict : DataQualityDict
An ordered
DataQualityDict
of (name,DataQualityFlag
) pairs.
query_segdb
(flags, *args, **kwargs)[source]¶Query the inital LIGO segment database for a list of flags.
flags : iterable
A list of flag names for which to query.
*args
Either, two
float
-like numbers indicating the GPS [start, stop) interval, or aSegmentList
defining a number of summary segments.
url : str
, optional
URL of the segment database, defaults to
$DEFAULT_SEGMENT_SERVER
environment variable, or'https://segments.ligo.org'
flagdict : DataQualityDict
An ordered
DataQualityDict
of (name,DataQualityFlag
) pairs.
read
(source, names=None, format=None, **kwargs)[source]¶Read segments from file into a DataQualityDict
source : str
path of file to read
format : str
, optional
source format identifier. If not given, the format will be detected if possible. See below for list of acceptable formats.
names : list
, optional, default: read all names found
list of names to read, by default all names are read separately.
coalesce : bool
, optional
if
True
coalesce the all segment lists before returning, otherwise return exactly as contained in file(s).
nproc : int
, optional, default: 1
number of CPUs to use for parallel reading of multiple files
verbose : bool
, optional, default: False
print a progress bar showing read status
flagdict : DataQualityDict
a new
DataQualityDict
ofDataQualityFlag
entries withactive
andknown
segments seeded from the XML tables in the given file.
Notes
The available built-in formats are:
Format |
Read |
Write |
Auto-identify |
---|---|---|---|
hdf5 |
Yes |
No |
No |
ligolw |
Yes |
Yes |
Yes |
setdefault
(self, /, 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
(self, ilwdchar_compat=None, **attrs)[source]¶Convert this DataQualityDict
into a trio of LIGO_LW segment tables
ilwdchar_compat : bool
, optional
**attrs
other attributes to add to all rows in all tables (e.g.
'process_id'
)
segmentdeftable : SegmentDefTable
the
segment_definer
table
segmentsumtable : SegmentSumTable
the
segment_summary
table
segmenttable : SegmentTable
the
segment
table
union
(self)[source]¶Return the union of all flags in this dict
union : DataQualityFlag
a new
DataQualityFlag
who’s active and known segments are the union of those of the values of this dict
update
()¶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
()¶write
(self, target, *args, **kwargs)[source]¶Write this DataQualityDict
to file
Notes
The available built-in formats are:
Format |
Read |
Write |
Auto-identify |
---|---|---|---|
hdf5 |
Yes |
Yes |
No |
ligolw |
Yes |
Yes |
Yes |
coalesce
(self)[source]Coalesce all segments lists in this DataQualityDict
.
This method modifies this object in-place.
self
a view of this flag, not a copy.
copy
(self, deep=False)[source]Build a copy of this dictionary.
deep : bool
, optional, default: False
perform a deep copy of the original dictionary with a fresh memory address
flag2 : DataQualityFlag
a copy of the original dictionary
from_ligolw_tables
(segmentdeftable, segmentsumtable, segmenttable, names=None, gpstype=<class 'lal.LIGOTimeGPS'>, on_missing='error')[source]Build a DataQualityDict
from a set of LIGO_LW segment tables
segmentdeftable : SegmentDefTable
the
segment_definer
table to read
segmentsumtable : SegmentSumTable
the
segment_summary
table to read
segmenttable : SegmentTable
the
segment
table to read
a list of flag names to read, defaults to returning all
gpstype : type
, 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_missing : str
, optional
action to take when a one or more
names
are not found in thesegment_definer
table, one of
'ignore'
: do nothing
'warn'
: print a warning
error'
: raise aValueError
dqdict : DataQualityDict
a dict of
DataQualityFlag
objects populated from the LIGO_LW tables
from_veto_definer_file
(fp, start=None, end=None, ifo=None, format='ligolw')[source]Read a DataQualityDict
from a LIGO_LW XML VetoDefinerTable.
fp : str
path of veto definer file to read
start : LIGOTimeGPS
, int
, optional
GPS start time at which to restrict returned flags
end : 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, currently only ‘ligolw’ is supported
flags : DataQualityDict
a
DataQualityDict
of flags parsed from theveto_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()
intersection
(self)[source]Return the intersection of all flags in this dict
intersection : DataQualityFlag
a new
DataQualityFlag
who’s active and known segments are the intersection of those of the values of this dict
plot
(self, label='key', **kwargs)[source]Plot this flag on a segments projection.
label : str
, optional
Labelling system to use, or fixed label for all flags, special values include
'key'
: use the key of theDataQualityDict
,
'name'
: use thename
of the flagIf anything else, that fixed label will be used for all lines.
**kwargs
all keyword arguments are passed to the
Plot
constructor.
figure : Figure
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
populate
(self, source='http://segments.ldas.cit', segments=None, pad=True, on_error='raise', **kwargs)[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
The name associated with this flag. |
|
The set of segments during which this flag was known, and its state was well defined. |
Segments will be fetched from the database, with any
padding
added on-the-fly.
Entries in this dict will be modified in-place.
source : str
source of segments for this flag. This must be either a URL for a segment database or a path to a file on disk.
segments : SegmentList
, optional
a list of known segments during which to query, if not given, existing known segments for flags will be used.
pad : bool
, optional, default: True
on_error : str
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()
orDataQualityFlag.read()
.
self : DataQualityDict
a reference to the modified DataQualityDict
query
(flags, *args, **kwargs)[source]Query for segments of a set of flags.
This method intelligently selects the query_segdb
or the query_dqsegdb
methods based on the
url
kwarg given.
flags : iterable
A list of flag names for which to query.
*args
Either, two
float
-like numbers indicating the GPS [start, stop) interval, or aSegmentList
defining a number of summary segments
url : str
, optional
URL of the segment database, defaults to
$DEFAULT_SEGMENT_SERVER
environment variable, or'https://segments.ligo.org'
flagdict : DataQualityDict
A
dict
of(name, DataQualityFlag)
pairs
See also
DataQualityDict.query_segdb
DataQualityDict.query_dqsegdb
for details on the actual query engine, and documentation of other keyword arguments appropriate for each query
query_dqsegdb
(flags, *args, **kwargs)[source]Query the advanced LIGO DQSegDB for a list of flags.
flags : iterable
A list of flag names for which to query.
*args
Either, two
float
-like numbers indicating the GPS [start, stop) interval, or aSegmentList
defining a number of summary segments.
on_error : str
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
url : str
, optional
URL of the segment database, defaults to
$DEFAULT_SEGMENT_SERVER
environment variable, or'https://segments.ligo.org'
flagdict : DataQualityDict
An ordered
DataQualityDict
of (name,DataQualityFlag
) pairs.
query_segdb
(flags, *args, **kwargs)[source]Query the inital LIGO segment database for a list of flags.
flags : iterable
A list of flag names for which to query.
*args
Either, two
float
-like numbers indicating the GPS [start, stop) interval, or aSegmentList
defining a number of summary segments.
url : str
, optional
URL of the segment database, defaults to
$DEFAULT_SEGMENT_SERVER
environment variable, or'https://segments.ligo.org'
flagdict : DataQualityDict
An ordered
DataQualityDict
of (name,DataQualityFlag
) pairs.
read
(source, names=None, format=None, **kwargs)[source]Read segments from file into a DataQualityDict
source : str
path of file to read
format : str
, optional
source format identifier. If not given, the format will be detected if possible. See below for list of acceptable formats.
names : list
, optional, default: read all names found
list of names to read, by default all names are read separately.
coalesce : bool
, optional
if
True
coalesce the all segment lists before returning, otherwise return exactly as contained in file(s).
nproc : int
, optional, default: 1
number of CPUs to use for parallel reading of multiple files
verbose : bool
, optional, default: False
print a progress bar showing read status
flagdict : DataQualityDict
a new
DataQualityDict
ofDataQualityFlag
entries withactive
andknown
segments seeded from the XML tables in the given file.
Notes
The available built-in formats are:
Format |
Read |
Write |
Auto-identify |
---|---|---|---|
hdf5 |
Yes |
No |
No |
ligolw |
Yes |
Yes |
Yes |
to_ligolw_tables
(self, ilwdchar_compat=None, **attrs)[source]Convert this DataQualityDict
into a trio of LIGO_LW segment tables
ilwdchar_compat : bool
, optional
**attrs
other attributes to add to all rows in all tables (e.g.
'process_id'
)
segmentdeftable : SegmentDefTable
the
segment_definer
table
segmentsumtable : SegmentSumTable
the
segment_summary
table
segmenttable : SegmentTable
the
segment
table
union
(self)[source]Return the union of all flags in this dict
union : DataQualityFlag
a new
DataQualityFlag
who’s active and known segments are the union of those of the values of this dict
write
(self, target, *args, **kwargs)[source]Write this DataQualityDict
to file
Notes
The available built-in formats are:
Format |
Read |
Write |
Auto-identify |
---|---|---|---|
hdf5 |
Yes |
Yes |
No |
ligolw |
Yes |
Yes |
Yes |