channel_labels
Channel labels: what an arbitrary EDF label says about a channel.
EDF labels are free text. The same electrode arrives as C3-A2, C3M2,
EEG C3-M2 or C3 - A2; a left EOG as E1, LOC, EOG(L) or
E-1; and some labels (EEG, EEG1) name a modality but no site at
all. Matching requirements by string equality against that is luck.
:func:parse_channel_label reads a label into a :class:ChannelLabel: the
active electrode and its reference in one canonical spelling, the body side
the electrode implies, the modality, and whether the label is generic
(no site to identify). The rules are the conventions of clinical PSG:
- 10-20 / 10-10 sites: a prefix (
Fp,AF,F,FC,C,CP,P,PO,O,T,TP,FT,M) and an odd digit (left hemisphere), an even digit (right) orz(midline). - Synonyms:
A1/A2are the mastoidsM1/M2;LOC/ROCandEOG(L)/EOG(R)(and theL/Rspellings) are the EOG electrodesE1/E2;EKGisECG. - Montages:
X-Y,X:Y,X/Yor the gluedXY(C3M2) are the electrodeXreferenced toY. The electrode is the first site; the reference never decides the side (C3-M2is left). - Modality prefix: a leading EDF+ token (
EEG,EOG,EMG,ECG…) names the modality and is not part of the montage.
Inference is conservative on purpose: a contradiction (left with an
even site) or no signal at all gives laterality=None, because a wrong
confident side routes the wrong eye or hemisphere into an analysis, which is
worse than asking. The parse is deterministic and unit-tested against a
committed corpus of real labels; extend the tables, not the callers.
ChannelLabel
pydantic-model
¶
Bases: BaseModel
What a label says about a channel; generic when it names no site.
Config:
frozen:True
Fields:
-
label(str) -
canonical(str | None) -
electrode(str | None) -
reference(str | None) -
modality(ChannelType) -
laterality(ChannelLaterality | None) -
generic(bool)
canonical = None
pydantic-field
¶
One spelling for one thing: C3-M2, E1, Fpz-Cz. None when the label names no site.
electrode = None
pydantic-field
¶
The active site, canonical.
generic = False
pydantic-field
¶
The label names a modality (EEG, EOG1) but no site; identity must come from elsewhere.
label
pydantic-field
¶
The label as written.
laterality = None
pydantic-field
¶
The side the electrode records; None when unknown or contradictory.
modality
pydantic-field
¶
The signal type the label implies.
reference = None
pydantic-field
¶
The reference, canonical, if any.
parse_channel_label(label)
¶
Read what label says about the channel it names.
summarise(labels)
¶
Count how a set of labels parses: identified, generic, sided; for corpus reports.