experanto.interpolators.SequenceInterpolator

class SequenceInterpolator(root_folder, cache_data=False, keep_nans=False, interpolation_mode='nearest_neighbor', normalize=False, normalize_subtract_mean=False, normalize_std_threshold=None, **kwargs)[source]

Bases: Interpolator

Interpolator for time series data.

Handles regularly-sampled time series stored as memory-mapped or NumPy arrays. Supports nearest-neighbor and linear interpolation modes.

Parameters:
  • root_folder (str) – Path to the modality directory containing data.mem or data.npy.

  • cache_data (bool, default=False) – If True, loads memory-mapped data into RAM for faster access.

  • keep_nans (bool, default=False) – If False and interpolation_mode='linear', replaces NaN values with column means during interpolation. For 'nearest_neighbor', NaNs are left unchanged.

  • interpolation_mode (str, default='nearest_neighbor') – Interpolation method: 'nearest_neighbor' or 'linear'.

  • normalize (bool, default=False) – If True, normalizes data using stored mean/std statistics.

  • normalize_subtract_mean (bool, default=False) – If True, subtracts mean during normalization.

  • normalize_std_threshold (float, optional) – Minimum std threshold to prevent division by near-zero values.

  • **kwargs – Additional keyword arguments (ignored).

sampling_rate

Original sampling rate of the data in Hz.

Type:

float

time_delta

Time between samples (1 / sampling_rate).

Type:

float

n_signals

Number of signals (e.g., neurons, behavior channels).

Type:

int

Notes

For linear interpolation, values are computed as:

\[y(t) = y_0 \cdot \frac{t_1 - t}{t_1 - t_0} + y_1 \cdot \frac{t - t_0}{t_1 - t_0},\]

where \(t_0\) and \(t_1\) are the surrounding sample times.

Methods

__init__(root_folder[, cache_data, ...])

close()

create(root_folder[, cache_data])

Factory method to create the appropriate interpolator for a modality.

interpolate(times[, return_valid])

Map an array of time points to interpolated data values.

load_meta()

normalize_data(data)

normalize_init()

valid_times(times)

__init__(root_folder, cache_data=False, keep_nans=False, interpolation_mode='nearest_neighbor', normalize=False, normalize_subtract_mean=False, normalize_std_threshold=None, **kwargs)[source]
normalize_init()[source]
normalize_data(data)[source]
interpolate(times, return_valid=False)[source]

Map an array of time points to interpolated data values.

close()[source]
static create(root_folder, cache_data=False, **kwargs)

Factory method to create the appropriate interpolator for a modality.

Reads the meta.yml file in the folder to determine the modality type and instantiates the corresponding interpolator subclass.

Parameters:
  • root_folder (str) – Path to the modality directory.

  • cache_data (bool, default=False) – If True, loads all data into memory for faster access.

  • **kwargs – Additional arguments passed to the interpolator constructor.

Returns:

An instance of the appropriate interpolator subclass.

Return type:

Interpolator

Raises:

ValueError – If the modality type is not supported.

load_meta()
valid_times(times)