systole.utils.to_epochs#

systole.utils.to_epochs(signal: List | ndarray, triggers: List | ndarray | None = None, triggers_idx: List | ndarray | None = None, sfreq: int = 1000, tmin: float = -1.0, tmax: float = 10.0, event_val: int = 1, apply_baseline: float | Tuple[float, float] | None = 0.0, verbose: bool = False, reject: ndarray | None = None) Tuple[List[ndarray], List[ndarray]][source]#

Epoch signal based on event triggers.

Parameters:
signal

The raw signal that should be epoched. The first dimension is time and should match with len(triggers) if triggers is provided. If triggers_idx is provided, np.max(triggers_idx) should be less than signal.shape[0].

triggers

The boolean indices of the events, shape=(times*sfreq, 1).

triggers_idx

Trigger indexes. Each value encode the sample where an event occured (see also sfreq). Different conditions should be provided separately as list of arrays (can have different lenght).

sfreq

The sampling frequency (default is 1000 Hz).

tmin

Start time before event, in seconds, default is -1.0.

tmax

End time after event, in seconds, defautl is 10.0.

event_val

The index of event of interest. Default is 1. Only relevant if triggers is not None.

apply_baseline

If int or tuple, use the point or interval to apply a baseline (method: mean). If None, no baseline is applied. Default is set to 0.

verbose

If True, will return warnings if epoc are droped.

reject

Segments of the signal that should be rejected.

Returns:
epochs

List of (n Tials * Time) array.

reject

List of rejected trials for each condition.

Examples

# Load dataset

>>> ecg_df = import_dataset1(modalities=['ECG', 'Stim'])
>>> triggers_idx = [
>>>     np.where(ecg_df.stim.to_numpy() == 2)[0],
>>>     np.where(ecg_df.stim.to_numpy() == 1)[0]
>>> ]
>>> signal = ecg_df.ecg.to_numpy()

# Using event idx

>>> epoch, rejected = to_epochs(signal=signal, triggers_idx=triggers_idx)

# Using event triggers

>>> epoch, rejected = to_epochs(signal=signal, triggers=ecg_df.stim.to_numpy(),
>>>                             event_val=2, apply_baseline=(-1.0, 0.0))

# Using a rejection vector >>> reject = np.zeros(len(signal)) >>> reject[768285:] = 1 # Reject the second part of the recording >>> epoch, rejected = to_epochs( >>> signal=signal, triggers=ecg_df.stim.to_numpy(), event_val=2, >>> apply_baseline=(-1.0, 0.0), reject=reject >>> )