Neuro#

Neural-domain primitives for VneuroTK.

NeuroData#

class vneurotk.neuro.base.NeuroData(data, trial_starts=None, trial_ends=None, data_mode=None)#

Neural signal container with trial-structured views.

Holds the raw neural array plus optional trial-boundary information, and exposes epochs and continuous views derived from that structure. NeuroData is not a NumPy array subclass — use data for the raw array when NumPy operations are needed.

Parameters:
datanp.ndarray

Raw neural array.

trial_startsnp.ndarray or None

Start sample index per trial.

trial_endsnp.ndarray or None

End sample index per trial.

data_modestr or None

"continuous", "epochs", or "patterns".

Parameters:
  • data (np.ndarray)

  • trial_starts (np.ndarray | None)

  • trial_ends (np.ndarray | None)

  • data_mode (str | None)

Examples

>>> import numpy as np
>>> nd = NeuroData(np.random.randn(1000, 64))
>>> nd.shape
(1000, 64)
>>> nd.data[:100]   # plain ndarray slice
property continuous: ndarray#

Concatenated-trials view, shape (total_trial_samples, nchan).

If the underlying data is already in continuous format it is returned as-is with a warning.

Raises:
RuntimeError

If trial structure is not available (call BaseData.configure() first).

property data: ndarray#

Raw neural array as a plain numpy.ndarray.

property dtype: dtype#

Data type of the underlying data array.

property epochs: ndarray#

Trial-epoched view, shape (n_trials, n_timepoints, nchan).

If the underlying data is already in epochs format it is returned as-is with a warning.

Raises:
RuntimeError

If trial structure is not available (call BaseData.configure() first).

property ndim: int#

Number of dimensions of the underlying data array.

property shape: tuple#

Shape of the underlying data array.

property size: int#

Total number of elements.

TrialStructure#

class vneurotk.neuro.trial.TrialStructure(stim_labels, trial, trial_starts, trial_ends, vision_onsets, vision_info, trial_info)#

Value object produced by the trial-structure factory functions.

All fields are written atomically by BaseData._apply_trial_structure().

Parameters:
  • stim_labels (ndarray)

  • trial (ndarray)

  • trial_starts (ndarray)

  • trial_ends (ndarray)

  • vision_onsets (ndarray)

  • vision_info (VisionInfo)

  • trial_info (TrialInfo)

Builders#

vneurotk.neuro.trial.build_trial_structure_epochs(visual_ids, vision_onsets, neuro_shape, existing_vision_onsets=None)#

Build a TrialStructure for pre-epoched recordings.

Parameters:
visual_idsnp.ndarray

Stimulus ID per trial, shape (n_trials,).

vision_onsetsnp.ndarray or None

Per-trial onset offsets within each epoch.

neuro_shapetuple

Shape of the neuro array (n_trials, n_timebins, ...).

existing_vision_onsetsnp.ndarray or None

Fallback: onsets already stored on the Recording before this call.

Returns:
TrialStructure
Parameters:
  • visual_ids (ndarray)

  • vision_onsets (ndarray | None)

  • neuro_shape (tuple)

  • existing_vision_onsets (ndarray | None)

Return type:

TrialStructure

vneurotk.neuro.trial.build_trial_structure_continuous(visual_ids, trial_window, vision_onsets, ntime, sfreq, neuro_shape=None)#

Build a TrialStructure for continuous (raw) recordings.

Parameters:
visual_idsnp.ndarray

Stimulus ID per onset, shape (n_onsets,).

trial_windowlist of float | int

Two-element [start, end] relative to each onset. Float values are seconds; int values are samples.

vision_onsetsnp.ndarray

Onset sample indices, shape (n_onsets,).

ntimeint

Total number of time samples in the recording.

sfreqfloat

Sampling frequency in Hz.

neuro_shapetuple of int or None

Full neural-array shape, validated as (ntime, nchan) when provided.

Returns:
TrialStructure
Parameters:
  • visual_ids (ndarray)

  • trial_window (list[float | int])

  • vision_onsets (ndarray)

  • ntime (int)

  • sfreq (float)

  • neuro_shape (tuple[int, ...] | None)

Return type:

TrialStructure

MNE utility#

vneurotk.utils.mne_utils.get_event_samples(raw, event_name='stim_on')#
Parameters:

raw (mne.io.BaseRaw)

Return type:

NDArray