Montage

class gpype.common.montage.Montage[source]

Bases: object

Ordered electrode labels for the EEG channels of a source.

A montage names the signal channels of an acquisition device. It describes which electrode sits on which channel, and is supplied by the user because amplifiers do not report electrode names.

A montage covers the signal channels only. Auxiliary channels a device may stream alongside EEG - counter, saturation, battery, validity - are labelled by the source itself and are not part of the montage.

Positions are resolved from a built-in table of standard electrode names rather than stored per instance, so a montage stays cheap to serialise. Labels outside the table simply have no position.

Example

>>> m = Montage(["Fz", "Cz", "Pz", "C3", "C4", "O1", "O2", "Oz"])
>>> len(m)
8
>>> m.index_of("Cz")
1
>>> m.position_of("Cz")
(0.0, 0.0)
__init__(labels, reference=None)[source]

Initialize a montage from an ordered list of electrode labels.

Parameters:
  • labels (list[str]) – Electrode labels, in channel order. Historical names (T3, T4, T5, T6) are normalised to their 10-20 equivalents.

  • reference (Optional[str]) – Label or description of the hardware reference, e.g. “Cz” or “linked_mastoids”. Recorded as metadata only; re-referencing is a separate processing step.

Raises:

ValueError – If labels is empty, contains non-strings, blank entries, or duplicates.

static normalise(label)[source]

Return the canonical form of an electrode label.

Parameters:

label (str) – Electrode label, possibly a historical alias.

Return type:

str

Returns:

The canonical label, with surrounding whitespace removed.

classmethod standard_1020(labels, reference=None)[source]

Create a montage and require every label to be a 10-20 name.

Use this when a typo should be an error rather than an unnamed channel.

Parameters:
  • labels (list[str]) – Electrode labels, in channel order.

  • reference (Optional[str]) – Hardware reference, if known.

Return type:

Montage

Returns:

The validated montage.

Raises:

ValueError – If any label is not part of the 10-20 system.

property labels

Electrode labels in channel order.

property reference

Hardware reference electrode or description, if known.

property system

Name of the electrode system, if all labels belong to one.

index_of(label)[source]

Return the channel index carrying the given electrode.

Parameters:

label (str) – Electrode label, alias accepted.

Return type:

int

Returns:

Zero-based channel index.

Raises:

KeyError – If the electrode is not part of this montage.

select(labels)[source]

Return channel indices for a subset of electrodes, in order.

Parameters:

labels (list[str]) – Electrode labels to look up.

Return type:

list[int]

Returns:

Channel indices in the order the labels were given.

Raises:

KeyError – If any electrode is not part of this montage.

position_of(label)[source]

Return the normalised 2-D scalp position of an electrode.

Parameters:

label (str) – Electrode label, alias accepted.

Return type:

Optional[tuple[float, float]]

Returns:

(x, y) on the projected head outline, or None if the label is not a known standard electrode.

positions()[source]

Return positions for all channels, in channel order.

Return type:

list[Optional[tuple[float, float]]]

Returns:

One entry per channel; None where the label is not a known standard electrode.

__len__()[source]

Number of channels described by this montage.

Return type:

int

__iter__()[source]

Iterate over electrode labels in channel order.

Return type:

Iterator[str]

__getitem__(index)[source]

Return the electrode label of a channel.

Parameters:

index (int) – Zero-based channel index.

Return type:

str

Returns:

Electrode label.

__eq__(other)[source]

Compare montages by labels and reference.

Return type:

bool

__repr__()[source]

Return a concise representation for logs and errors.

Return type:

str