Transforms#

This is used to transform the data within dpeeg. The transformation is applied to the data using the __call__ function, supporting input data types of EEG Data and EEG Dataset.

Usage can be referenced from the following examples:

Transforms.__call__(eegdata: BaseData, verbose=None)[source]#
Transforms.__call__(eegdata: BaseDataset, iter: Literal[False] = False, verbose=None)
Transforms.__call__(eegdata: BaseDataset, iter: Literal[True] = True, verbose=None)

Apply data transformation to eegdata or eegdataset.

Parameters:
  • eegdata (eegdata or eegdataset) – Apply data transformation to eegdata or eegdataset.

  • iter (bool) – Valid when the input type is eegdataset. True means directly returning the entire transformed dataset, False means iteratively returning the transformed data of each subject.

Examples

Allows transformation of data of type eegdata:

>>> eegdata = dpeeg.EEGData(edata=np.random.randn(16, 3, 10),
...                         label=np.random.randint(0, 3, 16))
>>> transforms.Unsqueeze()(eegdata, verbose=False)
[edata=(16, 1, 3, 10), label=(16,)]

Also allows input type eegdataset:

>>> eegdataset = dpeeg.datasets.EEGDataset([
...     eegdata.copy(), eegdata.copy(), eegdata.copy()
... ])
>>> transforms.Squeeze()(eegdataset, iter=False, verbose=False)
[EEGDataset:
  [eegdataset]: Subjects=3, type=EEGData
  [event_id]: None
]

setting iter can iteratively obtain the eegdata of each subject after transformation:

>>> tran = transforms.Unsqueeze()
>>> for subject, eegdata in tran(eegdataset, iter=True, verbose=False):
...     print(subject, eegdata)
0 [edata=(16, 1, 3, 10), label=(16,)]
1 [edata=(16, 1, 3, 10), label=(16,)]
2 [edata=(16, 1, 3, 10), label=(16,)]

Important

When the input type is EEG Dataset, the transformation will be applied to all subject data within the dataset. By default, all subject data will be read into memory for processing and returned. The transformation can be made subject-wise by specifying the iter parameter to save memory overhead.

Core#

Sequential

A sequential container.

SplitTrainTest

Split the data into training and testing sets.

ToEEGData

Convert different types of eegdata to EEGData.

Commonly#

Identity

Placeholder identity operator.

Crop

Crop a time interval.

SlideWin

Apply a sliding window to the dataset.

Unsqueeze

Insert a dimension on the data.

Squeeze

Remove a dimension on the data.

Transpose

Data dims transposed.

FilterBank

Filter Bank.

ApplyFunc

Apply a custom function to data.

LabelMapping

Rearrange the original label according to mapping rules.

PickLabel

Pick a subset of data.

Normalization#

ZscoreNorm

Z-score normalization per subject.

MinMaxNorm

Min-max normalization per subject.

Data Augmentation#

SegRecTime

Segmentation and reorganization in the time domain.

SlideWinAug

Sliding window data augmentation.