ApplyFunc#
- class dpeeg.transforms.ApplyFunc(func: Callable, keys: list[str] | None = None, **kwargs)[source]#
Apply a custom function to data.
- Parameters:
func (Callable) – Transformation data callback function. The first parameter of the function must be EEGData.
keys (list of str, optional) – The key of the eegdata to be transformed, if required. Applies to all eegdata by default.
**kwargs (dict, optional) – Additional arguments for callback function, if required.
- Returns:
data – Transformed eegdata.
- Return type:
eegdata or dataset
Examples
If you want to pass a function with parameters, such as you want to use np.expand_dims() with axis parameter, you can do as follows:
>>> eegdata = dpeeg.EEGData(edata=np.random.randn(16, 3, 10), ... label=np.random.randint(0, 3, 16)) >>> def expand_dim(data, dim=1): ... data["edata"] = np.expand_dims(data["edata"], dim) >>> transforms.ApplyFunc(expand_dim, dim=0)(eegdata, verbose=False) [edata=(1, 16, 3, 10), label=(16,)]
>>> split_eegdata = dpeeg.SplitEEGData(eegdata, eegdata.copy()) >>> transforms.ApplyFunc(expand_dim, ["train"])(split_eegdata, verbose=False) Train: [edata=(1, 1, 16, 3, 10), label=(16,)] Test : [edata=(1, 16, 3, 10), label=(16,)]