EventTable#
- class gwpy.table.EventTable(
- data=None,
- masked=False,
- names=None,
- dtype=None,
- meta=None,
- copy=True,
- rows=None,
- copy_indices=True,
- units=None,
- descriptions=None,
- **kwargs,
Bases:
TableA container for a table of events.
This object expands the default
Tablewith extra read/write formats, and methods to perform filtering, rate calculations, and visualisation.See also
astropy.table.Tablefor details on parameters for creating an
EventTable
Attributes Summary
Fetch a table of events from a database.
Read data into an
EventTable.Write this table to a file in the specified format.
Methods Summary
binned_event_rates(stride, column, bins[, ...])Calculate an event rate
TimeSeriesDict.cluster(index, rank, window)Cluster this
EventTableover a given column.event_rate(stride[, start, end, timecolumn])Calculate the rate
TimeSeriesfor thisTable.fetch_open_data(catalog[, columns, where, host])Fetch events from an open-data catalogue hosted by GWOSC.
filter(*column_filters)Apply one or more column slice filters to this
EventTable.get_column(name)Return the
Columnwith the given name.hist(column, **kwargs)Generate a
HistogramPlotof thisTable.scatter(x, y, **kwargs)Make a scatter plot of column
xvs columny.tile(x, y, w, h, **kwargs)Make a tile plot of this table.
Attributes Documentation
- fetch#
Fetch a table of events from a database.
- Parameters:
- *args
All positional arguments are specific to the data source, see below for basic usage.
- source
str,Engine The source of the remote data, see _Notes_ for a list of registered sources, OR an SQL database
Engineobject. Default is'sql'.- columns
listofstr, optional the columns to fetch from the database table, defaults to all
- where
str, orlistofstr, optional One or more column filters with which to downselect the returned table rows as they as read, e.g.
'snr > 5'; multiple conditions should be connected by ‘ && ‘, or given as alist, e.g.'snr > 5 && frequency < 1000'or['snr > 5', 'frequency < 1000']- engine
sqlalchemy.engine.Engine, optional The database engine to use when connecting.
- drivername
str Database backend and driver name.
- user
str, optional The username for authentication to the database.
- password
str, optional The password for authentication to the database.
- host
str, optional The name of the remote database host.
- post
int, optional Port to connect to on
host.- database
str, optional The name of the database to connect to.
- query
dict, optional Query parameters.
- kwargs
All other positional arguments are specific to the data format, see the online documentation for more details.
- Returns:
- table
EventTable A table of events recovered from the remote database.
- table
Examples
>>> from gwpy.table import EventTable
To download a table of all blip glitches from the Gravity Spy database:
>>> EventTable.fetch( ... tablename="glitches", ... source="gravityspy", ... where=["ml_label=Blip", "ml_confidence>0.9"], ... )
To download a table from any SQL-type server
>>> EventTable.fetch( ... drivername="postgresql", ... host="localname", ... tablename="data", ... )
- read#
Read data into an
EventTable.- Parameters:
- source
str,list Source of data, any of the following:
- args
Other positional arguments will be passed directly to the underlying reader method for the given format.
- format
str, optional The format of the given source files; if not given, an attempt will be made to automatically identify the format.
- columns
listofstr, optional The list of column names to read.
- where
str, orlistofstr, optional One or more column filters with which to downselect the returned table rows as they as read, e.g.
'snr > 5', similar to a SQLWHEREstatement. Multiple conditions should be connected by ‘ && ‘ or ‘ and ‘, or given as alist, e.g.'snr > 5 && frequency < 1000'or['snr > 5', 'frequency < 1000'].- parallel
int Number of threads to use for parallel reading of multiple files.
- verbose
bool Print a progress bar showing read status, default:
False.- .. note::
Keyword arguments other than those listed here may be required depending on the
format
- source
- Returns:
- table
EventTable
- table
- Raises:
astropy.io.registry.IORegistryErrorIf the
formatcannot be automatically identified.IndexErrorIf
sourceis an empty list.
- write#
Write this table to a file in the specified format.
Get help on the available writers for
EventTableusing thehelp()method:>>> EventTable.write.help() # general help >>> EventTable.write.help('root') # detailed help for the ROOT writer >>> EventTable.write.list_formats() # print list of available formats
- Parameters:
- target: `str`
Filename for output data file.
- *args
Other positional arguments will be passed directly to the underlying writer method for the given format.
- format
str Format for output data; if not given, an attempt will be made to automatically identify the format based on the
targetfilename.- **kwargs
Other keyword arguments will be passed directly to the underlying writer method for the given format.
- Raises:
astropy.io.registry.IORegistryErrorIf the
formatcannot be automatically identified.
Methods Documentation
- binned_event_rates(
- stride: float,
- column: str,
- bins: Sequence[tuple[float, float]] | Sequence[float],
- operator: str | Callable[[object, object], bool] = '>=',
- start: SupportsToGps | None = None,
- end: SupportsToGps | None = None,
- timecolumn: str | None = None,
Calculate an event rate
TimeSeriesDict.Calculate the event rate over a number of bins.
- Parameters:
- stride
float size (seconds) of each time bin
- column
str name of column by which to bin.
- bins
list a list of
tuplesmarking containing bins, or a list offloatsdefining bin edges against which an math operation is performed for each event.- operator
str,callable one of:
'<','<=','>','>=','==','!=', for a standard mathematical operation,'in'to use the list of bins as containing bin edges, ora callable function that takes compares an event value against the bin value and returns a boolean.
Note
If
binsis given as a list of tuples, this argument is ignored.- start
float,LIGOTimeGPS, optional GPS start epoch of rate
TimeSeries.- end
float,LIGOTimeGPS, optional GPS end time of rate
TimeSeries. This value will be rounded up to the nearest sample if needed.- timecolumn
str, optional, default:time name of time-column to use when binning events
- stride
- Returns:
- rates~gwpy.timeseries.TimeSeriesDict`
a dict of (bin,
TimeSeries) pairs describing a rate of events per second (Hz) for each of the bins.
- cluster(index: str, rank: str, window: float) Self[source]#
Cluster this
EventTableover a given column.Cluster over the
indexcolumn, maximizing over therankcolumn in the table.The clustering algorithm uses a pooling method to identify groups of points that are all separated in
indexby less thanwindow.Each cluster of nearby points is replaced by the point in that cluster with the maximum value of
rank.- Parameters:
- Returns:
- table
EventTable a new table that has had the clustering algorithm applied via slicing of the original
- table
Examples
To cluster an
EventTable(table) whoseindexisend_time,windowis0.1, and maximize oversnr:>>> table.cluster('end_time', 'snr', 0.1)
- event_rate(
- stride: float,
- start: SupportsToGps | None = None,
- end: SupportsToGps | None = None,
- timecolumn: str | None = None,
Calculate the rate
TimeSeriesfor thisTable.- Parameters:
- stride
float size (seconds) of each time bin
- start
float,LIGOTimeGPS, optional GPS start epoch of rate
TimeSeries- end
float,LIGOTimeGPS, optional GPS end time of rate
TimeSeries. This value will be rounded up to the nearest sample if needed.- timecolumn
str, optional name of time-column to use when binning events, attempts are made to guess this
- stride
- Returns:
- rate
TimeSeries a
TimeSeriesof events per second (Hz)
- rate
- Raises:
ValueErrorif the
timecolumncannot be guessed from the table contents
- classmethod fetch_open_data(
- catalog: str,
- columns: list[str] | None = None,
- where: str | list[str] | None = None,
- host: str = 'https://gwosc.org',
- **kwargs,
Fetch events from an open-data catalogue hosted by GWOSC.
This is an alias for
EventTable.fetch(format='gwosc').- Parameters:
- catalog
str The name of the catalog to fetch, e.g.
'GWTC-1-confident'.- columns
listofstr, optional The list of column names to read.
- where
str, orlistofstr, optional One or more column filters with which to downselect the returned table rows as they as read, e.g.
'snr > 5', similar to a SQLWHEREstatement. Multiple conditions should be connected by ‘ && ‘ or ‘ and ‘, or given alist, e.g.'mchirp < 3 && distance < 500'or['mchirp < 3', 'distance < 500']- host
str, optional The open-data host to use.
- **kwargs
Other keyword arguments are passed to the fetch method.
- catalog
- filter(*column_filters: FilterLike) Self[source]#
Apply one or more column slice filters to this
EventTable.Multiple column filters can be given, and will be applied concurrently
- Parameters:
- Returns:
- table
EventTable a new table with only those rows matching the filters
- table
Notes
See Filtering tables for more details on using filter tuples
Examples
To filter an existing
EventTable(table) to include only rows withsnrgreater than10, andfrequencyless than1000:>>> table.filter('snr>10', 'frequency<1000')
Custom operations can be defined using filter tuple definitions:
>>> from gwpy.table.filters import in_segmentlist >>> table.filter(('time', in_segmentlist, segs))
- get_column(name: str) Column[source]#
Return the
Columnwith the given name.This method is provided only for compatibility with the
igwn_ligolw.ligolw.Table.- Parameters:
- name
str the name of the column to return
- name
- Returns:
- column
astropy.table.Column
- column
- Raises:
KeyErrorif no column is found with the given name
- hist(column: str, **kwargs) Plot[source]#
Generate a
HistogramPlotof thisTable.- Parameters:
- Returns:
- plot
Plot The newly created figure.
- plot
See also
matplotlib.pyplot.figurefor documentation of keyword arguments used to create the figure.
matplotlib.figure.Figure.add_subplotfor documentation of keyword arguments used to create the axes.
gwpy.plot.Axes.histfor documentation of keyword arguments used to display the histogram, if the
methodkeyword is given, this method might not actually be the one used.
- scatter(x: str, y: str, **kwargs) Plot[source]#
Make a scatter plot of column
xvs columny.- Parameters:
- Returns:
- plot
Plot the newly created figure
- plot
See also
matplotlib.pyplot.figurefor documentation of keyword arguments used to create the figure
matplotlib.figure.Figure.add_subplotfor documentation of keyword arguments used to create the axes
gwpy.plot.Axes.scatterfor documentation of keyword arguments used to display the table
- tile(x: str, y: str, w: str, h: str, **kwargs) Plot[source]#
Make a tile plot of this table.
- Parameters:
- x
str name of column defining anchor point on the X-axis
- y
str name of column defining anchor point on the Y-axis
- w
str name of column defining extent on the X-axis (width)
- h
str name of column defining extent on the Y-axis (height)
- color
str, optional, default:None name of column by which to color markers
- **kwargs
any other keyword arguments, see below
- x
- Returns:
- plot
Plot the newly created figure
- plot
See also
matplotlib.pyplot.figurefor documentation of keyword arguments used to create the figure
matplotlib.figure.Figure.add_subplotfor documentation of keyword arguments used to create the axes
gwpy.plot.Axes.tilefor documentation of keyword arguments used to display the table