eegdash.to_bids.adapter module#
What an adapter gives the converter: one dataset’s layout, channels and metadata.
An adapter walks a source tree and says, for each data file, where it goes in
BIDS (Recording), how its channels are named and typed
(Channel), which events it holds (Event) and what the
dataset-level files say. It never opens a data file: the core reads every
header (Header) with the reader the conversion uses and hands it over.
ChannelTable is the shared helper for Adapter.channels(): an
ordered list of regular expressions of the source label, each giving a BIDS
name and type; a label no row matches is MISC and counted as unmapped.
- class eegdash.to_bids.adapter.Adapter(src: Path, version: str)[source]
Bases:
objectOne dataset’s layout and metadata, for
eegdash.to_bids.to_bids().A subclass sets the class attributes and implements
recordings(),channels(),sidecar(),participants(),dataset_description()andreadme(). It may append toself.warnings(throughwarn()) in any method: the core collects them per recording into the report. An adapter is pickled to the worker processes afterrecordings()ran, so what it planned there is available to the per-recording methods.- Parameters:
src (Path) – The source tree, never written to.
version (str) – The source release, one of
versions.
- channels(rec: Recording, header: Header) list[Channel][source]
One channel per label of header, in its order.
- dataset_description() dict[str, Any][source]
Name,License,Authors, DOI and links of dataset_description.json.
- property dataset_id: str
the tree’s folder in the cache.
- Type:
<name>-<version>
- events(rec: Recording, header: Header) list[Event] | None[source]
The recording’s events; None writes no events.tsv.
- held_out() list[Exclusion][source]
Recordings and subjects left out:
tables/<name>-<version>.heldout.csvwhen there is one.
- license_file() Path | None[source]
A file of the source (relative to it) copied to
LICENSE, or None.
- participants(subjects: Sequence[str]) tuple[list[dict], dict][source]
participants.tsv rows (
participant_idfirst) for subjects, and participants.json.
- readme(summary: dict[str, Any]) str[source]
README.md, from the run’s summary (subjects, recordings, hours, warnings).
- recordings() Iterator[Recording][source]
Every data file of the source: a walk that opens no data file.
- sidecar(rec: Recording, header: Header) dict[str, Any][source]
The adapter’s keys of
_eeg.json:EEGReference,PowerLineFrequency, …
- sourcedata(subjects: Sequence[str]) dict[str, bytes][source]
Small text files for
sourcedata/: name -> content, about subjects only.subjects are those with a recording in the tree: a held-out subject’s files, or its lines in a shared table, are left out.
- class eegdash.to_bids.adapter.Channel(name: str, type: str, units: str = 'n/a', description: str = '', mapped: bool = True)[source]
Bases:
objectOne row of channels.tsv.
- description: str = ''
- mapped: bool = True
- name: str
- type: str
- units: str = 'n/a'
- class eegdash.to_bids.adapter.ChannelTable(rules: str | Path | Iterable[tuple[str, str, str]])[source]
Bases:
objectSource label -> BIDS name and type, by the first matching rule.
- Parameters:
rules (str | Path | Iterable[tuple[str, str, str]]) – A CSV with the columns
pattern,name,type(the packagedtables/<id>.channels.csv), or the rows themselves.patternis a regular expression matched against the whole label,nameits replacement (\g<0>keeps the label,\1a group),typeone ofCHANNEL_TYPES.
- class eegdash.to_bids.adapter.Event(onset: float, duration: float, trial_type: str)[source]
Bases:
objectOne row of events.tsv, seconds from the start of the file.
- duration: float
- onset: float
- trial_type: str
- class eegdash.to_bids.adapter.Exclusion(key: str, match: Literal['recording', 'subject'], reason: str, hashed: bool = False)[source]
Bases:
objectA recording, or every recording of a subject, left out of the tree.
- hashed: bool = False
- key: str
- match: Literal['recording', 'subject']
- reason: str
- class eegdash.to_bids.adapter.Header(labels: tuple[str, ...], units: tuple[str, ...], sfreq: float, n_times: int, meas_date: datetime | None)[source]
Bases:
objectA data file’s header, read by the core, never by the adapter.
- n_times: int
- sfreq: float
- class eegdash.to_bids.adapter.Recording(source: Path, subject: str, task: str, session: str | None = None, acquisition: str | None = None, run: str | None = None, key: str = '', extra: Mapping[str, str]=<factory>)[source]
Bases:
objectOne source data file and where it goes in the BIDS tree.
- property entities: list[tuple[str, str]]
The BIDS entities, in file-name order (
sub ses task acq run).
- property folder: Path
sub-<s>/[ses-<e>/]eeg, relative to the BIDS root.
- key: str = ''
- source: Path
- property stem: str
sub-<s>[_ses-<e>]_task-<t>[_acq-<a>][_run-<r>].
- subject: str
- task: str