eegdash.corpus_shards module#

Plan the conversion in EEGDash: scan recording headers (no data read) and pack subjects into shards.

The entry point is plan_shards(); the CLI lives in scripts. It writes the same plan the corpus build has always used (records_<dsid>.csv, shards.tsv, plan_summary.json).

Writes <out>/records_<dsid>.csv one row per recording: subject session run task file sfreq nchans ntimes hours
<out>/shards.tsv shard_id dataset mode subjects n_records est_hours (tab-separated;

subjects = space-separated labels or “all”; mode = offline|online)

<out>/plan_summary.json

Scanner: the BIDS tree is walked directly (sub-/[ses-/]eeg/*_eeg.<set|vhdr|edf|bdf|…>) and SamplingFrequency / RecordingDuration / EEGChannelCount are read from the recording’s sidecar, following BIDS inheritance (a dataset-level task-<x>_eeg.json covers recordings without their own JSON - 8 of the 55 datasets are like that). When no sidecar gives the duration, the data file’s header is read with MNE (preload=False). EEGDash’s offline discovery would give the same numbers but globs the tree through mne_bids for every record, which on Lustre ran at ~2.5 s per recording (2026-09-18); the converter still goes through EEGDash, this is only the plan. Datasets are scanned in parallel processes.

Online datasets (NEMAR nm*, small): one shard each, all subjects, converted with –online. Subjects are packed greedily in sorted order until a shard would exceed –max-hours or –max-records.

eegdash.corpus_shards.entities(name: str) → dict[source]
eegdash.corpus_shards.find_sidecar(data: Path, root: Path) → dict[source]

BIDS inheritance: <stem>.json next to the file, else the nearest *_eeg.json up the tree whose entities are all present in the file name (typically a dataset-level task-<x>_eeg.json).

eegdash.corpus_shards.header_duration(path: Path) → tuple[float | None, float | None, int | None][source]

(sfreq, hours, n_eeg) from the data file header via MNE; None on failure.

eegdash.corpus_shards.pack_subjects(records: list[dict], max_hours: float, max_records: int) → list[list[str]][source]

Greedy packing of subjects (sorted) into shards; a single subject may exceed the limits alone.

eegdash.corpus_shards.plan_shards(cache_dir, out, offline_ids=(), online_ids=(), *, max_hours=200.0, max_records=400, workers=8)[source]

Write the shard plan for the given datasets and return (shard rows, summary).

Offline datasets are scanned from the local mirror (served-as ids resolved through EEGDashCorpus.status); online datasets get one shard each. Held-out ids are refused.

eegdash.corpus_shards.read_ids(path: str | Path) → list[str][source]
eegdash.corpus_shards.scan_dataset(cache_dir: Path, dsid: str, threads: int = 16, *, served_as: str | None = None) → list[dict][source]

Header-only record list of one locally mirrored dataset: BIDS sidecar (with inheritance), MNE header as fallback. Walks the data files, so recordings without their own JSON are still found. One tree walk and threaded sidecar reads: on Lustre each small-file open waits on the metadata server, and I-CARE’s 36,123 recordings took over 30 min read serially with one walk per extension (2026-09-24).

eegdash.corpus_shards.scan_record(data: Path, root: Path, dsid: str) → dict[source]

One recording’s row: sidecar first, the data file’s header only when the sidecar lacks duration or rate.

eegdash.corpus_shards.shard_rows(dsid: str, mode: str, records: list[dict], groups: list[list[str]]) → list[dict][source]