TimeSeriesDict

class gwpy.timeseries.TimeSeriesDict(*args, **kwds)[source]

Bases: gwpy.timeseries.core.TimeSeriesBaseDict

Ordered key-value mapping of named TimeSeries objects

This object is designed to hold data for many different sources (channels) for a single time span.

The main entry points for this object are the read() and fetch() data access methods.

Methods Summary

append(other[, copy]) Append the dict other to this one
clear(() -> None.  Remove all items from od.)
copy() Return a copy of this dict with each value copied to new memory
crop([start, end, copy]) Crop each entry of this dict
fetch(channels, start, end[, host, port, …]) Fetch data from NDS for a number of channels.
find(channels, start, end[, frametype, …]) Find and read data from frames for a number of channels.
fromkeys((S[, …) If not specified, the value defaults to None.
get(channels, start, end[, pad, dtype, …]) Retrieve data for multiple channels from frames or NDS
has_key((k) -> True if D has a key k, else False)
items(() -> list of (key, value) pairs in od)
iteritems() od.iteritems -> an iterator over the (key, value) pairs in od
iterkeys(() -> an iterator over the keys in od)
itervalues() od.itervalues -> an iterator over the values in od
keys(() -> list of keys in od)
plot([label]) Plot the data for this TimeSeriesBaseDict.
pop((k[,d]) -> v, …) value. If key is not found, d is returned if given, otherwise KeyError
popitem(() -> (k, v), …) Pairs are returned in LIFO order if last is true or FIFO order if false.
prepend(other, **kwargs) Prepend the dict other to this one
read(source, *args, **kwargs) Read data for multiple channels into a TimeSeriesDict
resample(rate, **kwargs) Resample items in this dict.
setdefault((k[,d]) -> od.get(k,d), …)
update(([E, …) If E present and has a .keys() method, does: for k in E: D[k] = E[k]
values(() -> list of values in od)
viewitems(…)
viewkeys(…)
viewvalues(…)
write(target, *args, **kwargs) Write this TimeSeriesDict to a file

Methods Documentation

append(other, copy=True, **kwargs)[source]

Append the dict other to this one

Parameters:

other : dict of TimeSeries

the container to append to this one

copy : bool, optional

if True copy data from other before storing, only affects those keys in other that aren’t in self

**kwargs

other keyword arguments to send to TimeSeries.append

See also

TimeSeries.append
for details of the underlying series append operation
clear() → None. Remove all items from od.
copy()[source]

Return a copy of this dict with each value copied to new memory

crop(start=None, end=None, copy=False)[source]

Crop each entry of this dict

This method calls the crop() method of all entries and modifies this dict in place.

Parameters:

start : LIGOTimeGPS, float, str

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

end : LIGOTimeGPS, float, str, optional

GPS end time of required data, defaults to end of data found; any input parseable by to_gps is fine

See also

TimeSeries.crop
for more details
fetch(channels, start, end, host=None, port=None, verify=False, verbose=False, connection=None, pad=None, allow_tape=None, type=None, dtype=None)[source]

Fetch data from NDS for a number of channels.

Parameters:

channels : list

required data channels.

start : LIGOTimeGPS, float, str

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

end : LIGOTimeGPS, float, str, optional

GPS end time of required data, defaults to end of data found; any input parseable by to_gps is fine

host : str, optional

URL of NDS server to use, if blank will try any server (in a relatively sensible order) to get the data

port : int, optional

port number for NDS server query, must be given with host.

verify : bool, optional, default: True

check channels exist in database before asking for data

verbose : bool, optional

print verbose output about NDS progress.

connection : nds2.connection, optional

open NDS connection to use.

allow_tape : bool, optional

allow data access from slow tapes. If host or connection is given, the default is to do whatever the server default is, otherwise servers will be searched in logical order allowing tape access if necessary to retrieve the data

type : int, str, optional

NDS2 channel type integer or string name.

dtype : numpy.dtype, str, type, or dict

numeric data type for returned data, e.g. numpy.float, or dict of (channel, dtype) pairs

Returns:

data : TimeSeriesBaseDict

a new TimeSeriesBaseDict of (str, TimeSeries) pairs fetched from NDS.

find(channels, start, end, frametype=None, frametype_match=None, pad=None, dtype=None, nproc=1, verbose=False, allow_tape=True, observatory=None, **readargs)[source]

Find and read data from frames for a number of channels.

Parameters:

channels : list

required data channels.

start : LIGOTimeGPS, float, str

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

end : LIGOTimeGPS, float, str, optional

GPS end time of required data, defaults to end of data found; any input parseable by to_gps is fine

frametype : str, optional

name of frametype in which this channel is stored, by default will search for all required frame types

frametype_match : str, optional

regular expression to use for frametype matching

pad : float, optional

value with which to fill gaps in the source data, defaults to ‘don’t fill gaps’

dtype : numpy.dtype, str, type, or dict

numeric data type for returned data, e.g. numpy.float, or dict of (channel, dtype) pairs

nproc : int, optional, default: 1

number of parallel processes to use, serial process by default.

allow_tape : bool, optional, default: True

allow reading from frame files on (slow) magnetic tape

verbose : bool, optional

print verbose output about NDS progress.

**readargs

any other keyword arguments to be passed to read()

fromkeys(S[, v]) → New ordered dictionary with keys from S.

If not specified, the value defaults to None.

get(channels, start, end, pad=None, dtype=None, verbose=False, allow_tape=None, **kwargs)[source]

Retrieve data for multiple channels from frames or NDS

This method dynamically accesses either frames on disk, or a remote NDS2 server to find and return data for the given interval

Parameters:

channels : list

required data channels.

start : LIGOTimeGPS, float, str

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

end : LIGOTimeGPS, float, str, optional

GPS end time of required data, defaults to end of data found; any input parseable by to_gps is fine

frametype : str, optional

name of frametype in which this channel is stored, by default will search for all required frame types

pad : float, optional

value with which to fill gaps in the source data, only used if gap is not given, or gap='pad' is given

dtype : numpy.dtype, str, type, or dict

numeric data type for returned data, e.g. numpy.float, or dict of (channel, dtype) pairs

nproc : int, optional, default: 1

number of parallel processes to use, serial process by default.

allow_tape : bool, optional, default: None

allow the use of frames that are held on tape, default is None to attempt to allow the TimeSeries.fetch method to intelligently select a server that doesn’t use tapes for data storage (doesn’t always work), but to eventually allow retrieving data from tape if required

verbose : bool, optional

print verbose output about NDS progress.

**kwargs

other keyword arguments to pass to either TimeSeriesBaseDict.find (for direct GWF file access) or TimeSeriesBaseDict.fetch for remote NDS2 access

has_key(k) → True if D has a key k, else False
items() → list of (key, value) pairs in od
iteritems()

od.iteritems -> an iterator over the (key, value) pairs in od

iterkeys() → an iterator over the keys in od
itervalues()

od.itervalues -> an iterator over the values in od

keys() → list of keys in od
plot(label='key', **kwargs)[source]

Plot the data for this TimeSeriesBaseDict.

Parameters:

label : str, optional

labelling system to use, or fixed label for all elements Special values include

  • 'key': use the key of the TimeSeriesBaseDict,
  • 'name': use the name of each element

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

**kwargs

all other keyword arguments are passed to the plotter as appropriate

pop(k[, d]) → v, remove specified key and return the corresponding

value. If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), return and remove a (key, value) pair.

Pairs are returned in LIFO order if last is true or FIFO order if false.

prepend(other, **kwargs)[source]

Prepend the dict other to this one

Parameters:

other : dict of TimeSeries

the container to prepend to this one

copy : bool, optional

if True copy data from other before storing, only affects those keys in other that aren’t in self

**kwargs

other keyword arguments to send to TimeSeries.prepend

See also

TimeSeries.prepend
for details of the underlying series prepend operation
read(source, *args, **kwargs)[source]

Read data for multiple channels into a TimeSeriesDict

Parameters:

source : str, Cache

a single file path str, or a Cache containing a contiguous list of files.

channels : ChannelList, list

a list of channels to read from the source.

start : LIGOTimeGPS, float, str optional

GPS start time of required data, anything parseable by to_gps() is fine

end : LIGOTimeGPS, float, str, optional

GPS end time of required data, anything parseable by to_gps() is fine

format : str, optional

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

nproc : int, optional

number of parallel processes to use, serial process by default.

Note

Parallel frame reading, via the nproc keyword argument, is only available when giving a Cache of frames, or using the format='cache' keyword argument.

gap : str, optional

how to handle gaps in the cache, one of

  • ‘ignore’: do nothing, let the undelying reader method handle it
  • ‘warn’: do nothing except print a warning to the screen
  • ‘raise’: raise an exception upon finding a gap (default)
  • ‘pad’: insert a value to fill the gaps

pad : float, optional

value with which to fill gaps in the source data, only used if gap is not given, or gap='pad' is given

Returns:

tsdict : TimeSeriesDict

a TimeSeriesDict of (channel, TimeSeries) pairs. The keys are guaranteed to be the ordered list channels as given.

Notes

The available built-in formats are:

Format Read Write Auto-identify
framecpp Yes Yes No
gwf Yes Yes Yes
gwf.framecpp Yes Yes No
gwf.lalframe Yes Yes No
hdf5 Yes No No
lalframe Yes Yes No
resample(rate, **kwargs)[source]

Resample items in this dict.

This operation over-writes items inplace.

Parameters:

rate : dict, float

either a dict of (channel, float) pairs for key-wise resampling, or a single float/int to resample all items.

**kwargs

other keyword arguments to pass to each item’s resampling method.

setdefault(k[, d]) → od.get(k,d), also set od[k]=d if k not in od
update([E, ]**F) → None. Update D from mapping/iterable E and F.

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

values() → list of values in od
viewitems() → a set-like object providing a view on od's items
viewkeys() → a set-like object providing a view on od's keys
viewvalues() → an object providing a view on od's values
write(target, *args, **kwargs)[source]

Write this TimeSeriesDict to a file

Arguments and keywords depend on the output format, see the online documentation for full details for each format.

Parameters:

target : str

output filename

format : str, optional

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

Notes

The available built-in formats are:

Format Read Write Auto-identify
framecpp Yes Yes No
gwf Yes Yes Yes
gwf.framecpp Yes Yes No
gwf.lalframe Yes Yes No
hdf5 Yes Yes No
lalframe Yes Yes No
EntryClass[source]

alias of TimeSeries