eelbrain.NDVar

class eelbrain.NDVar(x: numpy.ndarray, dims: Union[Dimension, Sequence[Dimension]], name: str = None, info: dict = None)

Container for n-dimensional data.

Parameters:
x : array_like

The data.

dims : Sequence of Dimension

The dimensions characterizing the axes of the data. If present, Case should always occupy the first position.

name : str

Name for the NDVar.

info : dict

A dictionary with data properties (can contain arbitrary information that will be accessible in the info attribute).

Notes

An NDVar consists of the following components:

  • A numpy.ndarray, stored in the x attribute.
  • Meta-information describing each axis of the array using a Dimension object (for example, UTS for uniform time series, or Sensor for a sensor array). These dimensions are stored in the dims attribute, with the ith element of dims describing the ith axis of x.
  • A dictionary containing other meta-information stored in the info attribute.
  • A name stored in the name attribute.

NDVar objects support the native abs() and round() functions.

Indexing: For classical indexing, indexes need to be provided in the correct sequence. For example, assuming ndvar’s first axis is time, ndvar[0.1] retrieves a slice at time = 0.1 s. If time is the second axis, the same can be achieved with ndvar[:, 0.1]. In NDVar.sub(), dimensions can be specified as keywords, for example, ndvar.sub(time=0.1), regardless of which axis represents the time dimension.

Shallow copies: When generating a derived NDVars, x and dims are generated without copying data whenever possible. A shallow copy of info is stored. This means that modifying a derived NDVar in place can affect the NDVar it was derived from. When indexing an NDVar, the new NDVar will contain a view on the data whenever possible based on the underlying array (See NumPy Indexing). This only matters when explicitly modifying an NDVar in place (e.g., ndvar += 1) because NDVar methods that return NDVars never implicitly modify the original NDVars in place (see this note).

Examples

Create an NDVar for 600 time series of 80 time points each:

>>> data.shape
(600, 80)
>>> time = UTS(-.2, .01, 80)
>>> ndvar = NDVar(data, dims=(Case, time))

Baseline correction:

>>> ndvar -= ndvar.mean(time=(None, 0))

Methods

abs(self[, name]) Compute the absolute values
aggregate(self[, x, func, name]) Summarize data in each cell of x.
all(self[, dims]) Whether all values are nonzero over given dimensions
any(self[, dims]) Compute presence of any value other than zero over given dimensions
argmax(self) Find the index of the largest value.
argmin(self) Find the index of the smallest value.
assert_dims(self, dims)
astype(self, dtype) Copy of the NDVar with data cast to the specified type
bin(self[, step, start, stop, func, dim, …]) Bin the data along a given dimension (default 'time')
clip(self[, min, max, name, out]) Clip data (see numpy.clip())
copy(self[, name]) A deep copy of the NDVar’s data
diff(self[, dim, n, pad, name]) Discrete difference
dot(self, ndvar[, dim, name]) Dot product
envelope(self[, dim, name]) Compute the Hilbert envelope of a signal
extrema(self[, dims]) Extrema (value farthest away from 0) over given dimensions
fft(self[, dim, name]) Fast fourier transform
flatnonzero(self) Return indices where a 1-d NDVar is non-zero
get_axis(self, name) Return the data axis for a given dimension name
get_data(self, dims[, mask]) Retrieve the NDVar’s data with a specific axes order.
get_dim(self, name) Return the Dimension object named name
get_dimnames(self[, names, first, last]) Fill in a partially specified tuple of Dimension names
get_dims(self[, names, first, last]) Return a tuple with the requested Dimension objects
has_dim(self, name)
label_clusters(self[, threshold, tail, name]) Find and label clusters of values exceeding a threshold
log(self[, base, name]) Element-wise log
mask(self, mask[, name, missing]) Create a masked version of this NDVar (see numpy.ma.MaskedArray)
max(self[, dims]) Compute the maximum over given dimensions
mean(self[, dims]) Compute the mean over given dimensions
min(self[, dims]) Compute the minimum over given dimensions
nonzero(self) Return indices where the NDVar is non-zero
norm(self, dim[, ord, name]) Norm over dim
ols(self, x[, name]) Sample-wise ordinary least squares regressions
ols_t(self, x[, name]) Compute T-values for sample-wise ordinary least squares regressions
repeat(self, repeats[, name]) Repeat slices of the NDVar along the case dimension
residuals(self, x[, name]) The residuals of sample-wise ordinary least squares regressions
rms(self[, axis]) Compute the root mean square over given dimensions
sign(self[, name]) Element-wise indication of the sign
smooth(self, dim[, window_size, window, …]) Smooth data by convolving it with a window
std(self[, dims]) Compute the standard deviation over given dimensions
sub(self, *args, **kwargs) Retrieve a slice through the NDVar.
sum(self[, dims]) Compute the sum over given dimensions
summary(self, *dims, **regions) Aggregate specified dimensions.
threshold(self, v[, tail, name]) Set all values below a threshold to 0.
unmask(self[, name]) Remove mask from a masked NDVar
var(self[, dims, ddof]) Compute the variance over given dimensions