iracema.core.timeseries

This module contains the implementation of the class TimeSeries.

class iracema.core.timeseries.TimeSeries(fs, data=None, start_time=None, unit=None, caption=None)[source]

Bases: object

Class for storing and manipulating time series objects, which model synchronous discrete time series.

Hint

This class is also available at the main package level as iracema.TimeSeries.

Variables
  • data (numpy array) – Data array sampled at fs Hz.

  • time (numpy array) – Numpy data array containing the time of each sample, relative to the original time reference.

  • fs (Decimal) – Sampling frequency for the data.

  • nyquist (Decimal) – Nyquist frequency for the data.

  • ts (Decimal) – Sampling period for the data.

  • start_time (Decimal) – The time the time series start (in seconds) relative to the original time reference.

  • duration (Decimal) – Duration of the time series (in seconds).

  • end_time (Decimal) – The time the time series end (in seconds) relative to the original time reference.

  • unit (str) – String containing the name of the unit for the data (for plotting).

  • nsamples (int) – Number of samples per time series in the data array.

  • nfeatures – Number of features for each sample in the data array.

  • unit – Unit for the data (for plotting).

  • caption – Text caption.

  • label – Label for the time series.

Parameters
  • fs (Decimal) – Sampling frequency for the data.

  • data (numpy array, optional) – Data array sampled at fs Hz. If this argument is not provided, the method _write_data() must be called after the initialization to set the data array.

  • start_time (float, optional) – The time in seconds the time series start, relative to the original time reference.

  • unit (str, optional) – Unit name for plotting the data of the time series.

  • caption (str, optional) – Text caption for the time series.

label = ''
unit = ''
caption = ''
property nsamples
property nfeatures
property duration
property nyquist
property end_time
property ts
property time
copy()[source]

Return a copy of the time series object (deep copy).

gain(db)[source]

Apply a gain of db dB to the time series and return the new object.

normalize(db=0.0)[source]

Return a copy of the audio time series, normalized to db dB.

diff(n=1)[source]

Return the n-th discrete difference for the time series

sliding_window(window_size, hop_size, function=None, window_name=None)[source]

Use a sliding window to aggregate the data from the time series by applying function to each analysis window. The content of each window will be passed as the first argument to the function. Return the aggregated data in an array.

Parameters
  • window_size (int) – Size of the window.

  • hop_size (int) – Number of samples to be skipped between two successive windowing operations.

  • function (function) – Function to be applied to each window. If no function is specified, each window will contain an unaltered excerpt of the time series.

  • window_name (str) – Name of the window function to be used. Options are: {“boxcar”, “triang”, “blackman”, “hamming”, “hann”, “bartlett”, “flattop”, “parzen”, “bohman”, “blackmanharris”, “nuttall”, “barthann”, “no_window”, None}.

zeros_to_nan()[source]

Converts zeros to np.nan in the data array. Returns a new time series.

hwr()[source]

Return a half-wave rectified copy of the time series.

pad(pre, post, value=0.0)[source]

Pad the edges of the time series.

Parameters
  • pre (int) – Pre-padding length.

  • post (int) – Post-padding length.

  • value (float or str) – Value for the padding operation. If a float number is provided, this value will be used in the padding. If instead the string ‘repeat’ is provided, the values at the edges will be repeated in the padding operation.

pad_like(timeseries, value=0.0)[source]

Pad the end of the current time series to match the length of the given time series.

resample_and_pad_like(timeseries, value=0.0)[source]

Resample and pad the end of the current time series to match the given time series.

merge(timeseries, unit=None, caption=None, start_time=None)[source]

Merge two time series. Both time series must have the same length and sampling frequency. The attributes unit, caption and start_time of the resulting time series can be optionally set using the method’s optional arguments. Otherwise these attributes will be equal to the values in the instance on which the method was called (self).

filter(critical_frequency, filter_type='low_pass', filter_order=4)[source]

Filters the time series using a butterworth digital filter. This is a wrapper over scipy.signal.butter.

Parameters
  • critical_frequency (float) – The critical frequency of frequencies.

  • filter_type ([‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’]) – The type of filter.

  • filter_order – The order of the filter.

plot(linewidth=1, alpha=0.9, **kwargs)[source]

Plot the time series using matplotlib.

time_to_sample_index(time)[source]

Convert time (in seconds) to the correspoding sample index in the time series.

get_samples(start, stop)[source]

Get an excerpt from the time series using sample indexes. Return a new TimeSeries object.

log10()[source]

Calculate the base 10 logarithm of the time series.

exception iracema.core.timeseries.DimensionalityError[source]

Bases: Exception

Exception raised for errors in dimensionality of arays