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: object

One 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() and readme(). It may append to self.warnings (through warn()) in any method: the core collects them per recording into the report. An adapter is pickled to the worker processes after recordings() 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.

changes() → str | None[source]

CHANGES, or None for no file.

channels(rec: Recording, header: Header) → list[Channel][source]

One channel per label of header, in its order.

check_source() → None[source]

Raise ValueError when the source is not this dataset.

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.

extension: ClassVar[str] = '.edf'
held_out() → list[Exclusion][source]

Recordings and subjects left out: tables/<name>-<version>.heldout.csv when there is one.

license_file() → Path | None[source]

A file of the source (relative to it) copied to LICENSE, or None.

linkable: ClassVar[bool] = True
name: ClassVar[str]
participants(subjects: Sequence[str]) → tuple[list[dict], dict][source]

participants.tsv rows (participant_id first) 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.

revision: ClassVar[int] = 1
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.

table(suffix: str) → Path[source]

The packaged table tables/<name>-<version><suffix>.

versions: ClassVar[tuple[str, ...]]
warn(message: str) → None[source]

Record a warning for the report (and the README, if the adapter writes them there).

warnings: list[str]
write_data(rec: Recording, dest: Path) → None[source]

Write the BIDS data file of rec to dest (linkable = False only).

class eegdash.to_bids.adapter.Channel(name: str, type: str, units: str = 'n/a', description: str = '', mapped: bool = True)[source]

Bases: object

One 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: object

Source 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 packaged tables/<id>.channels.csv), or the rows themselves. pattern is a regular expression matched against the whole label, name its replacement (\g<0> keeps the label, \1 a group), type one of CHANNEL_TYPES.

channels(header: Header) → list[Channel][source]

One Channel per label of header, in its order.

lookup(label: str) → tuple[str, str, bool][source]

(name, type, mapped) of label; (label, "MISC", False) when no rule matches.

class eegdash.to_bids.adapter.Event(onset: float, duration: float, trial_type: str)[source]

Bases: object

One 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: object

A recording, or every recording of a subject, left out of the tree.

hashed: bool = False
key: str
match: Literal['recording', 'subject']
matches(rec: Recording) → bool[source]
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: object

A data file’s header, read by the core, never by the adapter.

labels: tuple[str, ...]
meas_date: datetime | None
n_times: int
sfreq: float
units: tuple[str, ...]
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: object

One source data file and where it goes in the BIDS tree.

acquisition: str | None = None
property entities: list[tuple[str, str]]

The BIDS entities, in file-name order (sub ses task acq run).

extra: Mapping[str, str]
property folder: Path

sub-<s>/[ses-<e>/]eeg, relative to the BIDS root.

key: str = ''
run: str | None = None
session: str | None = None
source: Path
property stem: str

sub-<s>[_ses-<e>]_task-<t>[_acq-<a>][_run-<r>].

subject: str
task: str
eegdash.to_bids.adapter.read_exclusions(path: str | Path) → list[Exclusion][source]

An exclusion table, key,match,reason[,hashed]: a held-out table or --exclude.