Montages#

Montages#

A montage is a list of Derivation – a name, the channels averaged with a plus sign and the channels averaged with a minus sign – so a viewer can draw it and an analysis compute from exactly the same definition. Builders:

apply_montage() turns (n_channels, n_samples) data into the derivations; a NaN in any channel a derivation uses makes that sample NaN.

class brainmaze_eeg.montage.Derivation(name: str, plus: Tuple[str, ...], minus: Tuple[str, ...] = ())#

mean(plus) - mean(minus); minus empty = referential.

minus: Tuple[str, ...] = ()#
name: str#
plus: Tuple[str, ...]#
brainmaze_eeg.montage.apply_montage(data, channels: Sequence[str], derivations: Sequence[Derivation]) → ndarray#

(n_derivations, n_samples) from data (n_channels, n_samples).

brainmaze_eeg.montage.bipolar(channels: Sequence[str]) → List[Derivation]#

Each contact minus the next contact of the same lead: LA1-LA2, LA2-LA3…

A lead is the name without its trailing number. Only consecutive numbers are paired, so a missing (removed) contact is never bridged; channels without a trailing number are left out.

brainmaze_eeg.montage.common_average(channels: Sequence[str], exclude: Sequence[str] = ()) → List[Derivation]#

Each channel minus the mean of all channels, itself included (the standard common average reference). Channels in exclude (an ECG, a bad contact) are neither in the average nor re-referenced.

brainmaze_eeg.montage.double_banana(channels: Sequence[str]) → List[Derivation]#

The scalp longitudinal bipolar montage, from the 10-20 channels present (names matched ignoring case; old and new temporal names both accepted).

brainmaze_eeg.montage.nearest_neighbour(channels: Sequence[str], positions: Mapping[str, Sequence[float]], k: int = 1) → List[Derivation]#

Each contact minus the mean of its k nearest other contacts (positions: channel -> (x, y, z), e.g. millimetres). Contacts without a position are left out.

brainmaze_eeg.montage.referential(channels: Sequence[str]) → List[Derivation]#
brainmaze_eeg.montage.region_average(channels: Sequence[str], region_of: Mapping[str, str]) → List[Derivation]#

Each contact minus the mean of the OTHER contacts in its region (region_of: channel -> region label, e.g. an atlas label), like nearest_neighbour() – so a two-contact region gives the plain difference, not half of it. Contacts without a region, or alone in theirs, are left out.