nirspipe.io.bids#

BIDS dataset querying and participants.tsv helpers.

Module Contents#

Functions#

get_layout

Return a pybids BIDSLayout for the dataset, safe to query from parallel subjects.

validate_bids

Check the input dataset with the BIDS validator, exiting non-zero on any error.

write_bids_from_snirf

Convert one raw snirf file into a BIDS nirs entry.

get_participant_age

A participant’s age in years from participants.tsv, converted by participants.json’s Units.

get_nirs_files

Return paths to all snirf files for a given subject/session/task.

read_bids_filter

A --bids-filter-file: the pybids query keywords it adds, {"run": 1}.

channel_status_bads

The channels a recording’s channels.tsv marks bad in its status column.

bids_label

Build a BIDS filename stem (sub-.._ses-.._task-.._acq-.._run-..) from parsed entities.

Data#

API#

nirspipe.io.bids.logger = 'get_logger(...)'#
nirspipe.io.bids.get_layout(bids_dir: pathlib.Path, validate: bool = True) → bids.BIDSLayout#

Return a pybids BIDSLayout for the dataset, safe to query from parallel subjects.

nirspipe.io.bids.validate_bids(bids_dir: pathlib.Path) → None#

Check the input dataset with the BIDS validator, exiting non-zero on any error.

Carries on with a warning when no validator is installed, so a machine without one can still run; --skip-bids-validation is how a user proceeds past a failing dataset.

nirspipe.io.bids.write_bids_from_snirf(input_file: pathlib.Path, bids_dir: pathlib.Path, subject: str, task: str, session: str | None = None, run: str | None = None, overwrite: bool = False, optode_frame: str = 'unknown') → None#

Convert one raw snirf file into a BIDS nirs entry.

optode_frame names the space the SNIRF’s optode coordinates live in. SNIRF does not record it, so MNE reads them as “unknown” and mne-bids then writes no _optodes.tsv or _coordsystem.json, both of which BIDS requires: it will not guess a frame on the author’s behalf. Pass “head” when the positions were digitised against the nasion and the two preauricular points, “mri” when they already sit on a template brain: MNE reads “mri” as fsaverage, not as the subject’s own scan.

nirspipe.io.bids.get_participant_age(bids_root: pathlib.Path, subject: str, fix: str = 'pass --dpf as numbers') → float#

A participant’s age in years from participants.tsv, converted by participants.json’s Units.

Raises ValueError when the row, the column or a number is missing, or the unit is not one of years, months, weeks or days.

nirspipe.io.bids.get_nirs_files(layout: bids.BIDSLayout, subject: str, session: str | None = None, task: str | None = None, filter_file: pathlib.Path | None = None) → list[pathlib.Path]#

Return paths to all snirf files for a given subject/session/task.

task: if None, all tasks are returned. filter_file: optional JSON with extra pybids query kwargs, e.g. {“run”: “01”}.

nirspipe.io.bids.read_bids_filter(path: pathlib.Path) → dict#

A --bids-filter-file: the pybids query keywords it adds, {"run": 1}.

nirspipe.io.bids.channel_status_bads(layout: bids.BIDSLayout, nirs_path: pathlib.Path) → list[str]#

The channels a recording’s channels.tsv marks bad in its status column.

"S1_D2 760" bad, "S2_D1 760" good, "S2_D2 850" BAD  ->  ["S1_D2 760", "S2_D2 850"]

The nearest channels.tsv, inheritance included; none, or one without a status column, gives none. Case is ignored, as mne-bids ignores it.

nirspipe.io.bids.bids_label(subject: str, entities: dict) → str#

Build a BIDS filename stem (sub-.._ses-.._task-.._acq-.._run-..) from parsed entities.