eegdash.to_bids#
Bring a dataset that is not in BIDS to a BIDS tree, one adapter per dataset.
A dataset each user obtains from its data holder under the holder’s terms (a
gated archive that may not be redistributed, so not on NEMAR) becomes a BIDS
tree at <cache_dir>/<name>-<version>/: the folder a local dataset is
read from (see eegdash.corpus), so files, verify, shards,
convert and merge take it over unchanged:
from eegdash.to_bids import to_bids
report = to_bids("tueg-2.0.1", "/data/tuh_eeg/v2.0.1", dry_run=True)
report = to_bids("tueg-2.0.1", "/data/tuh_eeg/v2.0.1")
Command line:
python -m eegdash.corpus bids tueg-2.0.1 --src DIR [--cache-dir C]
[--link symlink|hard|copy] [--exclude CSV] [--keep-held-out] [--dry-run]
[--n-jobs N] [--shard K --n-shards N] [--adapter module:Class]
[--json REPORT.json]
Headers are read, never the signal; data files are linked (symbolic links by
default), never rewritten when the source format is a BIDS data file; nothing
is written under the source. Held-out recordings are left out and reported.
The adapters are in ADAPTERS: the TUH EEG Corpus (tueg, from
NEDC). One outside the package is named module:Class (a subclass of
Adapter).
Functions
|
The adapter class of a dataset name ( |
|
An exclusion table, |
|
Write the BIDS tree of dataset_id at |
Classes
|
One dataset's layout and metadata, for |
|
The result of |
|
One row of channels.tsv. |
|
Source label -> BIDS name and type, by the first matching rule. |
|
One row of events.tsv, seconds from the start of the file. |
|
A recording, or every recording of a subject, left out of the tree. |
|
A data file's header, read by the core, never by the adapter. |
|
One source data file and where it goes in the BIDS tree. |
- class eegdash.to_bids.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.
- property dataset_id: str
the tree’s folder in the cache.
- Type:
<name>-<version>
- warn(message: str) None[source]
Record a warning for the report (and the README, if the adapter writes them there).
- recordings() Iterator[Recording][source]
Every data file of the source: a walk that opens no data file.
- channels(rec: Recording, header: Header) list[Channel][source]
One channel per label of header, in its order.
- sidecar(rec: Recording, header: Header) dict[str, Any][source]
The adapter’s keys of
_eeg.json:EEGReference,PowerLineFrequency, …
- 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.
- participants(subjects: Sequence[str]) tuple[list[dict], dict][source]
participants.tsv rows (
participant_idfirst) for subjects, and participants.json.
- dataset_description() dict[str, Any][source]
Name,License,Authors, DOI and links of dataset_description.json.
- readme(summary: dict[str, Any]) str[source]
README.md, from the run’s summary (subjects, recordings, hours, warnings).
- license_file() Path | None[source]
A file of the source (relative to it) copied to
LICENSE, or None.
- class eegdash.to_bids.BidsReport(dataset_id: str, adapter: str, options: dict[str, ~typing.Any]=<factory>, rows: list[dict] = <factory>, warnings: list[str] = <factory>, problems: list[str] = <factory>, held_out_kept: int = 0, seconds: float = 0.0)[source]
Bases:
objectThe result of
eegdash.to_bids.to_bids(): one row per recording, problems, warnings.- dataset_id: str
- adapter: str
- held_out_kept: int = 0
- seconds: float = 0.0
- property ok: bool
- property counts: dict[str, int]
Recordings per status, subjects in the tree (or planned), and hours.
- labels() dict[str, dict[str, Any]][source]
Source label -> recordings, its BIDS name and type, whether a rule mapped it.
- class eegdash.to_bids.Channel(name: str, type: str, units: str = 'n/a', description: str = '', mapped: bool = True)[source]
Bases:
objectOne row of channels.tsv.
- name: str
- type: str
- units: str = 'n/a'
- description: str = ''
- mapped: bool = True
- class eegdash.to_bids.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.Event(onset: float, duration: float, trial_type: str)[source]
Bases:
objectOne row of events.tsv, seconds from the start of the file.
- onset: float
- duration: float
- trial_type: str
- class eegdash.to_bids.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.
- key: str
- match: Literal['recording', 'subject']
- reason: str
- hashed: bool = False
- class eegdash.to_bids.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.
- sfreq: float
- n_times: int
- class eegdash.to_bids.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.
- source: Path
- subject: str
- task: str
- key: str = ''
- property entities: list[tuple[str, str]]
The BIDS entities, in file-name order (
sub ses task acq run).
- property stem: str
sub-<s>[_ses-<e>]_task-<t>[_acq-<a>][_run-<r>].
- property folder: Path
sub-<s>/[ses-<e>/]eeg, relative to the BIDS root.
- eegdash.to_bids.get_adapter(spec: str | type[Adapter]) type[Adapter][source]
The adapter class of a dataset name (
tueg), amodule:Classpath, or a class.
- eegdash.to_bids.read_exclusions(path: str | Path) list[Exclusion][source]
An exclusion table,
key,match,reason[,hashed]: a held-out table or--exclude.
- eegdash.to_bids.to_bids(dataset_id: str, src: str | Path, *, cache_dir: str | Path | None = None, link: str = 'symlink', exclude: str | Path | Sequence[Exclusion] | None = None, keep_held_out: bool = False, dry_run: bool = False, n_jobs: int = 1, shard: int | None = None, n_shards: int | None = None, adapter: str | type[Adapter] | None = None) BidsReport[source]
Write the BIDS tree of dataset_id at
<cache_dir>/<dataset_id>/from the source src.- Parameters:
dataset_id (str) –
<name>-<version>(tueg-2.0.1); the adapter is the one registered for the name, and must know the version.src (str | Path) – The source tree; never written to, and the output may not be in it.
cache_dir (str | Path | None) – The EEGDash cache (see
eegdash.paths.get_default_cache_dir()).link ({"symlink", "hard", "copy"}) – How a data file enters the tree. A symbolic link (absolute) shows a moved source at once in
verify; a hard link or a copy makes a tree that stands alone.exclude (str | Path | sequence of Exclusion | None) – More recordings or subjects to leave out: a CSV
key,match,reason(matchisrecording, matched against a recording’s key, the source’s stem by default, orsubject).keep_held_out (bool) – Do not apply the adapter’s held-out table (recorded in the report).
dry_run (bool) – Plan and read every header; write nothing.
n_jobs (int) – Processes, over subjects. They are spawned: a script that asks for more than one calls
to_bids()underif __name__ == "__main__":.shard (int | None) – This job-array task’s subjects: subjects sorted, every n_shards-th from shard. The root files and the report are written by a final call without a shard, which reuses what the tasks wrote.
n_shards (int | None) – This job-array task’s subjects: subjects sorted, every n_shards-th from shard. The root files and the report are written by a final call without a shard, which reuses what the tasks wrote.
adapter (str | type[Adapter] | None) – Another adapter for the name:
module:Classor a class.
- Returns:
One row per recording;
okwhen nothing was unreadable, invalid or refused.- Return type:
BidsReport