NIPY logo

Site Navigation

NIPY Community

Table Of Contents

Previous topic

testlib

Next topic

utils

timeseries

Module: timeseries

Inheritance diagram for nitime.timeseries:

Base classes for generic time series analysis.

The classes implemented here are meant to provide fairly basic objects for managing time series data. They should serve mainly as data containers, with only minimal algorithmic functionality.

In the timeseries subpackage, there is a separate library of algorithms, and the classes defined here mostly delegate any computational facilities they may have to that library.

Over time, it is OK to add increasingly functionally rich classes, but only after their design is well proven in real-world use.

Classes

Epochs

class nitime.timeseries.Epochs(t0=None, stop=None, offset=None, start=None, duration=None, time_unit=None, static=None, **kwargs)

Bases: nitime.descriptors.ResetMixin

Represents a time interval

__init__(t0=None, stop=None, offset=None, start=None, duration=None, time_unit=None, static=None, **kwargs)
static duration()

Duration array for the epoch

start
stop

Events

class nitime.timeseries.Events(time, labels=None, indices=None, time_unit=None, **data)

Bases: nitime.timeseries.TimeInterface

Represents timestamps and associated data

__init__(time, labels=None, indices=None, time_unit=None, **data)

Frequency

class nitime.timeseries.Frequency

Bases: float

A class for representation of the frequency (in Hz)

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

to_period(time_unit='ps')

Convert the value of a frequency to the corresponding period (defaulting to a representation in the base_unit)

TimeArray

class nitime.timeseries.TimeArray

Bases: numpy.ndarray, nitime.timeseries.TimeInterface

Base-class for time representations, implementing the TimeInterface

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

at(t, tol=None)

Returns the values of the TimeArray object at time t

convert_unit(time_unit)

Convert from one time unit to another in place

during(e)

Returns the values of the TimeArray object during Epoch e

index_at(t, tol=None, mode='closest')

Returns the integer indices that corresponds to the time t

The returned indices depend on both tol and mode. The tol parameter specifies how close the given time must be to those present in the array to give a match, when mode is closest. The default tolerance is 1 base_unit (by default, picoseconds). If you specify the tolerance as 0, then only exact matches are allowed, be careful in this case of possible problems due to floating point roundoff error in your time specification.

When mode is before or after, the tolerance is completely ignored. In this case, either the largest time equal or before the given t or the earliest time equal or after the given t is returned.

Parameters :

t : time-like

Anything that is valid input for a TimeArray constructor.

tol : time-like, optional

Tolerance, specified in the time units of this TimeArray.

mode : string

One of [‘closest’, ‘before’, ‘after’].

Returns :

The array with all the indices where the condition is met. :

max(axis=None, out=None)

Returns the maximal time

mean(*args, **kwargs)
min(*args, **kwargs)
prod(*args, **kwargs)
ptp(*args, **kwargs)
slice_during(e)

Returns the slice that corresponds to Epoch e

std(*args, **kwargs)

Returns the standard deviation of this TimeArray (with time units)

for detailed information, see numpy.std()

sum(*args, **kwargs)
var(*args, **kwargs)

TimeInterface

class nitime.timeseries.TimeInterface

Bases: object

The minimal object interface for time representations

This should be thought of as an abstract base class.

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

TimeSeries

class nitime.timeseries.TimeSeries(data, t0=None, sampling_interval=None, sampling_rate=None, duration=None, time=None, time_unit='s', metadata=None)

Bases: nitime.timeseries.TimeSeriesBase

Represent data collected at uniform intervals.

__init__(data, t0=None, sampling_interval=None, sampling_rate=None, duration=None, time=None, time_unit='s', metadata=None)

Create a new TimeSeries.

This class assumes that data is uniformly sampled, but you can specify the sampling in one of three (mutually exclusive) ways:

  • sampling_interval [, t0]: data sampled starting at t0, equal intervals of sampling_interval.
  • sampling_rate [, t0]: data sampled starting at t0, equal intervals of width 1/sampling_rate.
  • time: a UniformTime object, in which case the TimeSeries can ‘inherit’ the properties of this object.
Parameters :

data : array_like

Data array, interpreted as having its last dimension being time.

sampling_interval : float

Interval between successive time points.

sampling_rate : float

Inverse of the interval between successive time points.

t0 : float

If you provide a sampling rate, you can optionally also provide a starting time.

time :

Instead of sampling rate, you can explicitly provide an object of

class UniformTime. Note that you can still also provide a different :

sampling_rate/sampling_interval/duration to take the place of the one :

in this object, but only as long as the changes are consistent with the :

length of the data. :

time_unit : string

The unit of time.

Examples

The minimal specification of data and sampling interval:

>>> ts = TimeSeries([1,2,3],sampling_interval=0.25)
>>> ts.time
UniformTime([ 0.  ,  0.25,  0.5 ], time_unit='s')
>>> ts.t0
0.0 s
>>> ts.sampling_rate
4.0 Hz

Or data and sampling rate: >>> ts = TimeSeries([1,2,3],sampling_rate=2) >>> ts.time UniformTime([ 0. , 0.5, 1. ], time_unit=’s’) >>> ts.t0 0.0 s >>> ts.sampling_interval 0.5 s

A time series where we specify the start time and sampling interval: >>> ts = TimeSeries([1,2,3],t0=4.25,sampling_interval=0.5) >>> ts.data array([1, 2, 3]) >>> ts.time UniformTime([ 4.25, 4.75, 5.25], time_unit=’s’) >>> ts.t0 4.25 s >>> ts.sampling_interval 0.5 s >>> ts.sampling_rate 2.0 Hz

>>> ts = TimeSeries([1,2,3],t0=4.25,sampling_rate=2.0)
>>> ts.data
array([1, 2, 3])
>>> ts.time
UniformTime([ 4.25,  4.75,  5.25], time_unit='s')
>>> ts.t0
4.25 s
>>> ts.sampling_interval
0.5 s
>>> ts.sampling_rate
2.0 Hz
at(t, tol=None)

Returns the values of the TimeArray object at time t

copy()
during(e)

Returns the TimeSeries slice corresponding to epoch e

static from_time_and_data(time, data)
shape
static time()

Construct time array for the time-series object. This holds a UniformTime object, with properties derived from the TimeSeries object

TimeSeriesBase

class nitime.timeseries.TimeSeriesBase(data, time_unit, metadata=None)

Bases: object

Base class for time series, implementing the TimeSeriesInterface.

__init__(data, time_unit, metadata=None)

Common constructor shared by all TimeSeries classes.

data

the data is an arbitrary numpy array

TimeSeriesInterface

class nitime.timeseries.TimeSeriesInterface

Bases: nitime.timeseries.TimeInterface

The minimally agreed upon interface for all time series.

This should be thought of as an abstract base class.

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

UniformTime

class nitime.timeseries.UniformTime

Bases: numpy.ndarray, nitime.timeseries.TimeInterface

A representation of time sampled uniformly

Parameters :

length: int, the number of items in the time-array :

duration: float, the duration to be represented (given in the time-unit) of :

the array. If this item is an TimeArray, the units of the UniformTime :

array resulting will ‘inherit’ the units of the duration. Otherwise, the :

unit of the UniformTime will be set by that kwarg :

sampling_rate: float, the sampling rate (in 1/time-unit) :

sampling_interval: float, the inverse of the sampling_interval :

t0: the value of the first time-point in the array (in time-unit) :

time_unit: :

copy: whether to make a copy of not. Needs to be set to False :

XXX continue writing this :

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

at(t)

Returns the values of the UniformTime object at time t

during(e)

Returns the values of the UniformTime object during Epoch e

index_at(t, boolean=False)

Find the index that corresponds to the time bin containing t

Returns boolean mask if boolean=True and integer indices otherwise.

max(axis=None, out=None)

Returns the maximal time

min(axis=None, out=None)

Returns the minimal time

slice_during(e)

Returns the slice that corresponds to Epoch e

Functions

nitime.timeseries.concatenate_time_series(time_series_seq)

Concatenates a sequence of time-series objects in time.

The input can be any iterable of time-series objects; metadata, sampling rates and other attributes are kept from the last one in the sequence.

This one requires that all the time-series in the list have the same sampling rate and that all the data have the same number of items in all dimensions, except the time dimension

nitime.timeseries.get_time_unit(obj)

Extract the time unit of the object. If it is an iterable, get the time unit of the first element.

nitime.timeseries.str_tspec(tspec, arg_names)

Turn a single tspec into human readable form

nitime.timeseries.str_valid_tspecs(valid_tspecs, arg_names)

Given a set of valid_tspecs, return a string that turns them into human-readable form