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) – True means that the number of edata and label samples 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

Add a new value to the corresponding key.

append

Append a new eegdata at the end of the eegdata.

check

Check whether the number of samples of the current edata and label is equal.

copy

Creates a deep copy of the current object.

index

Index internal data and return a new EEGData instance.

items

keys

pop

If the key is not found, return the default if given; otherwise, raise a KeyError.

trials

Returns the number of trial samples.

values

Attributes

cls

Returns all categories.

ncls

Returns the number of categories.

shape

Return the edata shape.

keys() a set-like object providing a view on D's keys[source]#
values() an object providing a view on D's values[source]#
items() a set-like object providing a view on D's items[source]#
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.

check() bool[source]#

Check whether the number of samples of the current edata and label is equal.

trials() int[source]#

Returns the number of trial samples.

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:

EEGData

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,)]