Util

Description

This module contains the util class, which implements several utility methods for EEG data manipulation. The class is designed to assist in k-fold operations and streamline preprocessing tasks such as cropping, timestamp generation, and trial selection for EEG data stored in dictionary format.

class bciflow.modules.core.util.util[source]

Bases: object

This class implements various utility methods to facilitate the manipulation of EEG data stored in dictionary format, including functions for timestamp creation, data cropping, trial extraction, function application on trials, and data concatenation.

None
timestamp(data):

Calculates the timestamps for the EEG data based on its starting time (tmin), sampling frequency (sfreq), and the number of time samples.

crop(data, tmin, window_size, inplace):

Crops the EEG data to a specified time window.

get_trial(data, ids):

Extracts specified trials from the EEG data based on given indices.

apply_to_trials(data, func, func_param, inplace=False):

Applies a specified function to each trial in the EEG data. Parameter inplace has an default value of False.

concatenate(data_collection):

Concatenates multiple EEG data dictionaries into a single one.

apply_to_trials(func, func_param={}, inplace=False)[source]

This method applies a given function to each trial in the EEG data. The function should accept a single-trial EEG dictionary as input. If inplace is set to False, it returns a new EEG dictionary with the function applied to each trial.

Parameters:
  • data (dict) – EEG data dictionary.

  • func (callable) – Function to apply to each trial.

  • func_param (dict, optional) – Additional keyword arguments to pass to func.

  • inplace (bool, optional) – If True, modifies the input data dictionary. If False, returns a new dictionary. Parameter is set as False by default.

Returns:

EEG data dictionary with the function applied to each trial (only if inplace=False).

Return type:

dict (optional)

concatenate()[source]

This method concatenates a list of EEG data dictionaries into a single EEG data dictionary.

Parameters:

data_collection (list[dict]) – A list of EEG data dictionaries to concatenate.

Returns:

A new EEG data dictionary containing the concatenated data from all input dictionaries.

Return type:

dict

crop(tmin, window_size, inplace)[source]

This method crops the EEG data, retaining a window of specified length starting from tmin. If inplace is set to False, it returns a new cropped EEG dictionary without modifying the input data.

Parameters:
  • data (dict) – EEG data dictionary.

  • tmin (float) – Starting time for the cropping.

  • window_size (float) – Duration (in seconds) of the time window to keep.

  • inplace (bool, optional) – If True, modifies the input data dictionary. If False, returns a new dictionary.

Returns:

Cropped EEG data (only if inplace=False).

Return type:

dict (optional)

Raises:

ValueError – If tmin + window_size exceeds the maximum time in the original data.

get_trial(ids)[source]

This method extracts the specified trials from the EEG data, based on the indices provided in ids.

Parameters:
  • data (dict) – EEG data dictionary.

  • ids (list[int] or np.ndarray) – Indices of the trials to extract.

Returns:

New EEG data dictionary containing only the selected trials.

Return type:

dict

timestamp()[source]

This method generates an array of timestamps based on the EEG data’s starting time (tmin), sampling frequency (sfreq), and number of time samples.

Parameters:

data (dict) – EEG data dictionary.

Returns:

Array of timestamps corresponding to each time sample.

Return type:

np.array