EEGData#
- class dpeeg.EEGData(edata: ndarray | None = None, label: ndarray | None = None, strict: bool = True, **kwargs)[source]#
The base eegdata class.
The most basic eeg data wrapper. It is essentially a python
dict, but with some additional functions added to it.- Parameters:
edata (array shape (n_trials, ...), optional) – EEG data.
label (array shape (n_trials, ...), optional) – The labels corresponding to the eeg data.
strict (bool) –
Truemeans that the number ofedataandlabelsamples must be the same.**kwargs (dict, optional) – Other parameter indicators.
Examples
If no value is passed, an empty EEGData object is initialized:
>>> dpeeg.EEGData() [edata=(0,), label=(0,)]
Or initialize with additional parameters:
>>> dpeeg.EEGData( ... edata=np.random.rand(16, 3, 20), ... label=np.random.randint(0, 3, 16), ... adj=np.random.rand(3, 3) ... ) [edata=(16, 3, 20), label=(16,), adj=(3, 3)]
Methods
Add a new value to the corresponding key.
Append a new eegdata at the end of the eegdata.
Check whether the number of samples of the current edata and label is equal.
copyCreates a deep copy of the current object.
Index internal data and return a new EEGData instance.
If the key is not found, return the default if given; otherwise, raise a KeyError.
Returns the number of trial samples.
Attributes
clsReturns all categories.
nclsReturns the number of categories.
shapeReturn the
edatashape.- pop(k[, d]) v, remove specified key and return the value[source]#
If the key is not found, return the default if given; otherwise, raise a KeyError.
- index(idx: Iterable[int] | slice) EEGData[source]#
Index internal data and return a new EEGData instance.
- Parameters:
idx (Iterable[int], slice) – The index to apply to the internal data.
- Returns:
A new EEGData instance containing the indexed data.
- Return type:
Examples
>>> eegdata = dpeeg.EEGData( ... edata=np.random.randn(16, 3, 10), ... label=np.random.randint(0, 3, 16), ... ) >>> eegdata.index([1, 2, 3]) [edata=(3, 3, 10), label=(3,)]
>>> eegdata.index(slice(6)) [edata=(6, 3, 10), label=(6,)]
- append(eegdata: EEGData, dims: list[int] | int = 0, ignore: bool = False)[source]#
Append a new eegdata at the end of the eegdata.
- Parameters:
eegdata (EEGData) – The new eegdata to be added. If the new eegdata contains key-value pairs that do not exist in the original eegdata, they will be ignored by default.
dims (int, list of int) – The dimension along which the new eegdata is merged with the old eegdata. If a single number is entered, all eegdata is added along that dimension. If a list is given, the new eegdata is added along the specified dimensions in the order given in the list and dictionary.
ignore (bool) – If True, add new key-value pairs from the new eegdata.
Examples
>>> eegdata = dpeeg.EEGData( ... edata=np.random.randn(16, 3, 10), ... label=np.random.randint(0, 3, 16), ... ) >>> eegdata.append(eegdata.copy()) >>> eegdata [edata=(32, 3, 10), label=(32,)]
>>> eegdata_adj = eegdata.copy() >>> eegdata_adj["adj"] = np.random.randn(16, 3, 3) >>> eegdata_adj [edata=(32, 3, 10), label=(32,), adj=(16, 3, 3)]
>>> eegdata.append(eegdata_adj, ignore=True) >>> eegdata [edata=(64, 3, 10), label=(64,), adj=(16, 3, 3)]
- add(key: str, value: ndarray | list[ndarray], dim: int = 0)[source]#
Add a new value to the corresponding key.
- Parameters:
key (str) – The key of eegdata.
value (ndarray, list of ndarray) – The new value to be added. If a list, all values in the list are added.
dim (int) – The dimension in which the new data is concatenated with the old data.
Examples
>>> eegdata = dpeeg.EEGData(edata=np.random.randn(16, 3, 10), ... label=np.random.randint(0, 3, 16)) >>> eegdata.add("edata", np.random.randn(16, 3, 10), dim=2) >>> eegdata [edata=(16, 3, 20), label=(16,)]