TimeSeries

TimeSeries class definition.

class TimeSeries(amplitude, dt)

Bases: object

A class for manipulating time series.

Variables:
  • amplitude (ndarray) – Denotes the time series amplitude one value per time step. Amplitude can be 1D or 2D, for the 2D case each row is a different time series.
  • dt (float) – Time step between samples in seconds.
__init__(amplitude, dt)

Initialize a TimeSeries object.

Parameters:
  • amplitude (ndarray) – Amplitude of the time series at each time step.
  • dt (float) – Time step between samples in seconds.
Returns:

TimeSeries – Instantiated with amplitude information.

Raises:

TypeError – If amplitude is not castable to ndarray or has dimensions greater than 2. Refer to error message(s) for specific details.

amp
amplitude
bandpassfilter(flow, fhigh, order=5)

Apply bandpass Butterworth filter to time series.

Parameters:
  • flow (float) – Low-cut frequency (content below flow is filtered).
  • fhigh (float) – High-cut frequency (content above fhigh is filtered).
  • order (int, optional) – Filter order, default is 5.
Returns:

None – Filters attribute amp.

cosine_taper(width)

Apply cosine taper to time series.

Parameters:width ({0.-1.}) – Amount of the time series to be tapered. 0 is equal to a rectangular and 1 a Hann window.
Returns:None – Applies cosine taper to attribute amp.
detrend()

Remove linear trend from time series.

Returns:None – Removes linear trend from attribute amp.
df
dt
fnyq
classmethod from_dict(dictionary)

Create TimeSeries object from dictionary representation.

Parameters:dictionary (dict) – Must contain keys “amplitude” and “dt”.
Returns:TimeSeries – Instantiated TimeSeries object.
Raises:KeyError – If any of the required keys (listed above) are missing.
classmethod from_json(json_str)

Instantiate TimeSeries object form Json string.

Parameters:json_str (str) – Json string with all of the relevant contents of TimeSeries. Must contain keys “amplitude” and “dt”.
Returns:TimeSeries – Instantiated TimeSeries object.
classmethod from_timeseries(timeseries)

Copy constructor for TimeSeries object.

Parameters:timeseries (TimeSeries) – TimeSeries to be copied.
Returns:TimeSeries – Copy of the provided TimeSeries object.
classmethod from_trace(trace)

Initialize a TimeSeries object from a trace object.

Parameters:trace (Trace) – Refer to obspy documentation for more information
Returns:TimeSeries – Initialized with information from trace.
fs
join()

Rejoin a split TimeSeries.

Returns:None – Updates the object’s internal attributes (e.g., amplitude).
n_samples
n_windows
nsamples
nsamples_per_window
nseries
nwindows
split(windowlength)

Split record into n series of length windowlength.

Parameters:windowlength (float) – Duration of desired shorter series in seconds. If windowlength is not an integer multiple of dt, the window length is rounded to up to the next integer multiple of dt.
Returns:None – Updates the object’s internal attributes (e.g., amplitude).

Notes

The last sample of each window is repeated as the first sample of the following time window to ensure an intuitive number of windows. Without this, for example, a 10-minute record could not be broken into 10 1-minute records.

Examples

>>> import numpy as np
>>> from sigpropy import TimeSeries
>>> amp = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> tseries = TimeSeries(amp, dt=1)
>>> wseries = tseries.split(2)
>>> wseries.amplitude
array([[0, 1, 2],
    [2, 3, 4],
    [4, 5, 6],
    [6, 7, 8]])
time
to_dict()

Dictionary representation of TimeSeries.

Returns:dict – Containing all of the relevant contents of the TimeSeries.
to_json()

Json string representation of TimeSeries object.

Returns:str – Json string with all of the relevant contents of the TimeSeries.
trim(start_time, end_time)

Trim time series in the interval [start_time, end_time].

Parameters:
  • start_time (float) – New time zero in seconds.
  • end_time (float) – New end time in seconds.
Returns:

None – Updates the attributes amp and nsamples.

Raises:

IndexError – If the start_time and end_time is illogical. For example, start_time is before the start of the delay or after end_time, or the end_time is after the end of the record.

windowlength