nirspipe.pipeline.prep_pipeline#
Preprocessing pipeline: all prep steps in a single module.
- Step outputs written to output_dir/sub-XX/[ses-YY/]nirs/:
desc-od raw intensity → ΔOD desc-sci SCI-pruned OD desc-motcorrected motion-corrected OD desc-preproc final HbO/HbR (Beer-Lambert output) desc-aux the recording’s auxiliary channels, if it has any (tsv.gz)
Each snirf is accompanied by a JSON provenance sidecar.
motion correction lives in pipeline/motion.py.
Module Contents#
Classes#
Outputs from run_prep() needed for reporting and downstream use. |
|
Functions#
Convert raw intensity signal to optical density. |
|
Return SCI score per channel name. |
|
Screen channels into raw.info[‘bads’]. |
|
|
|
Screening’s rejections minus the pairs a reviewer kept, as |
|
Screening’s rejections with a reviewer’s keeps released and every mark added, as |
|
Convert OD to haemoglobin concentration via Beer-Lambert law; |
|
Run the full preprocessing pipeline in locked step order. |
Data#
API#
- nirspipe.pipeline.prep_pipeline.logger = 'get_logger(...)'#
- nirspipe.pipeline.prep_pipeline.intensity_to_od(raw: mne.io.Raw) mne.io.Raw#
Convert raw intensity signal to optical density.
- nirspipe.pipeline.prep_pipeline.compute_sci(raw_od: mne.io.Raw, cardiac_l_freq: float, cardiac_h_freq: float) dict[str, float]#
Return SCI score per channel name.
- nirspipe.pipeline.prep_pipeline.mark_bad_channels(raw_od: mne.io.Raw, threshold: float, cardiac_l_freq: float, cardiac_h_freq: float, psp_threshold: float | None = None, min_good_frac: float | None = None, screen_scope: str = 'run', keep: list[str] | tuple = ()) tuple[mne.io.Raw, list[str], dict[str, float], dict[str, float]]#
Screen channels into raw.info[‘bads’].
The criteria are
nirspipe.qc.metrics.screening.CRITERIAand a channel is rejected if it fails any criterion that screens, so what gets pruned is decided by that table rather than here.thresholdis the SCI line a window has to clear, andpsp_thresholda PSP line it has to clear as well, None for none;min_good_fracis the share of windows that has to pass, and it is the line that rejects, None keeping the criterion’s own default.screen_scopeis “run” or “task” and decides which windows are counted; seeresolve_screen_scope(). Windows touching aBAD_span are never counted, and fewer than two left stops the run.Returns raw (modified in-place), the rejected channel names, the SCI scores, and the passing-window shares, the last two because the report and the quality record both want them on their own.
keep(pairs a reviewer kept) does not change the rejections returned; it only stops a run whose every channel failed from being refused here. Raises StageError if the criteria leave no usable channel and nothing is kept.
- nirspipe.pipeline.prep_pipeline.mark_what_can_be_judged(raw_od: mne.io.Raw, threshold: float, cardiac_l_freq: float, cardiac_h_freq: float, psp_threshold: float | None = None, min_good_frac: float | None = None, screen_scope: str = 'run', keep: list[str] | tuple = ()) tuple[mne.io.Raw, list[str], dict[str, float], dict[str, float]]#
mark_bad_channels()for a recording that must be shown whatever its state.What screening cannot judge rejects nothing and is stamped as
screening_gap, and every channel may fail, sokeep, which only stops that refusal, has nothing to do here.
- nirspipe.pipeline.prep_pipeline.release_kept(screened: list[str], keep: list[str]) tuple[list[str], list[str]]#
Screening’s rejections minus the pairs a reviewer kept, as
(still bad, kept).(["S1_D1 760", "S1_D1 850", "S2_D2 760", "S2_D2 850"], ["S2_D2"])->
(["S1_D1 760", "S1_D1 850"], ["S2_D2 760", "S2_D2 850"])
- nirspipe.pipeline.prep_pipeline.join_marks(raw_od: mne.io.Raw, screened: list[str], *, keep=(), manual=(), listed=(), forced=(), label: str = 'run') tuple[list[str], list[str]]#
Screening’s rejections with a reviewer’s keeps released and every mark added, as
(bad, kept).keepholds the pairs a reviewer kept,manualthe --bad-channels labels,listedthe channels.tsv rejections andforcedchannels marked for another reason. A mark outranks a keep; a pair --bad-channels both marks and keeps is refused. One function for the pipeline and raw QC, so the same inputs give both the same verdict.
- nirspipe.pipeline.prep_pipeline.od_to_haemo(raw_od: mne.io.Raw, dpf: list[float], age: float | None = None) mne.io.Raw#
Convert OD to haemoglobin concentration via Beer-Lambert law;
ageis what an age DPF came from.
- class nirspipe.pipeline.prep_pipeline.PrepResult#
Outputs from run_prep() needed for reporting and downstream use.
- raw_haemo: mne.io.Raw | None = None#
- class nirspipe.pipeline.prep_pipeline.PrepConfig#
- nirspipe.pipeline.prep_pipeline.run_prep(raw: mne.io.Raw, config: nirspipe.pipeline.prep_pipeline.PrepConfig, output_dir: pathlib.Path, source_entities: dict[str, str] | None = None, source_path: pathlib.Path | None = None, source_metadata: dict | None = None) nirspipe.pipeline.prep_pipeline.PrepResult#
Run the full preprocessing pipeline in locked step order.
- Steps (order is fixed; BIDS validation handled upstream before this call):
OD conversion -> desc-od_nirs.snirf
SCI channel marking -> desc-sci_nirs.snirf
Motion correction -> desc-motcorrected_nirs.snirf
Beer-Lambert -> desc-preproc_nirs.snirf
Aux extraction -> desc-aux_timeseries.tsv.gz (only if the recording has aux)
source_path is the BIDS file raw was read from; it becomes the Sources entry of the first output, and step 5 reads the aux channels back out of it. source_metadata is that file’s sidecar, inheritance applied; every output carries its REQUIRED _nirs.json fields on.
Under
config.lenienta recording screening cannot judge goes on with nothing rejected, and a step that fails is left out, named inPrepResult.skipped, with what follows it taking what it can.