Usage#
NIRSPipe is a set of command-line entry points. What each step does is described in Processing workflow and Hyperscanning; this page lists how to call them.
Command |
Purpose |
|---|---|
Preprocessing and postprocessing of a BIDS dataset ( |
|
Convert one raw SNIRF file into BIDS |
|
Data preparation: crop, align dyads, edit markers, write span tables |
|
Raw QC as a BIDS App: each recording’s report ( |
|
Redraw the provenance graphs of a tree from its sidecars |
|
Dyad analysis: coherence, correlation, phase-scrambled null |
|
The re-paired null |
|
The nulls read with the channels averaged, per occasion and cohort |
|
Re-average saved coherence maps over another band |
|
Rebuild each dyad’s landing page |
|
Concatenate the per-dyad long tables into one table per kind |
|
Rating viewers for the QC reports |
|
The GUI, a local web app in your browser |
Examples#
The cardiac and respiration bands, the DPF and the head template depend on the participants’ age. --population fills them for an age group, and a flag typed for one of them overrides it (Population). --sci-threshold is never filled: every run names its own line.
Preprocessing only, with a report per run:
nirspipe /data/bids /data/derivatives participant --population adult --sci-threshold 0.8
A first-level GLM, the events taken from the SNIRF annotations with a fixed duration. Short-channel regression runs by default on a montage with short channels:
nirspipe /data/bids /data/derivatives participant --population adult --sci-threshold 0.8 \
--mode glm --stim-dur 15 --drift-high-pass 0.01 --contrast-file contrasts.tsv
--drift-high-pass auto sets the cutoff for each run from its own events instead (Choosing the drift cutoff).
Resting state, ALFF and connectivity, with regions:
nirspipe /data/bids /data/derivatives participant --population adult --sci-threshold 0.8 \
--mode rest --roi-mapping rois.json
A denoised residual for analyses done elsewhere, such as dyad coherence on task data:
nirspipe /data/bids /data/derivatives participant --population adult --sci-threshold 0.8 \
--mode denoise --high-pass 0.02 --low-pass 0.2
Children, whose faster heart rate needs a higher cardiac band or good channels are rejected:
nirspipe /data/bids /data/derivatives participant --population child --sci-threshold 0.8
An ageing study from 20 to 80 years, one DPF per participant from their age in participants.tsv:
nirspipe /data/bids /data/derivatives participant --population adult --dpf age --sci-threshold 0.8
An exercise task, which raises the heart rate past the resting band:
nirspipe /data/bids /data/derivatives participant --population adult --cardiac-h-freq 3.0 \
--sci-threshold 0.8
Every value typed, without --population:
nirspipe /data/bids /data/derivatives participant \
--dpf 6.0 --sci-threshold 0.8 \
--cardiac-l-freq 0.7 --cardiac-h-freq 1.8 --resp-l-freq 0.1 --resp-h-freq 0.5
Then the cohort pages, which need no preprocessing flag:
nirspipe /data/bids /data/derivatives group
--dry-run resolves the settings, writes each subject’s run record and stops. --nprocs 4 lets the run use four cores: four subjects at once, or fewer subjects with the spare cores going to each one’s numerics. One subject failing does not end a batch: the failed subjects are named at the end and the command exits non-zero.
Conventions#
Entity flags are spelled the same on every command:
--participant-label,--session-label,--task-label,--run-label,--group-id. A label may be given with itssub-/ses-/task-prefix or without. List options take space-separated values or the flag repeated. The BIDS App options also answer to their underscore spellings (--participant_label,--bids_filter_file, …).Every command but
nirspipe-guitakes--version, andnirspipeand thenirspipe-hypercommands also take--verbose.Flags are typed in full. A shortened spelling, such as the first three letters of
--population, is refused, so a script keeps working when a flag sharing its start is added later.Values are checked as they are read. A value outside what its flag can mean (an SCI line above 1, a share outside 0 to 1, a window of 0 s, a negative seed) or a range typed backwards (a
--high-passabove the--low-pass, a--tminafter the--tmax) stops the command before anything runs. A--configfile’s values go through the same checks.Errors. A message that stops a command starts with
Error:, and the command exits non-zero. In a batch, a line naming one subject or group with[error]or[skip]reports that unit only, and the others still run.Tables you supply are read by extension:
.tsvtab-separated,.csvcomma-separated, anything else sniffed (Table files).BIDS validation. Commands that read a BIDS dataset (
nirspipe,nirspipe-prep, andnirspipe-qcat the participant level and, with--pairs-csv, at the group level) check it with bids-validator when it is installed;--skip-bids-validationskips the check. Commands that read only a derivatives tree never validate.Output directories. A command that writes a tree stops when its output directory is its input directory;
nirspipe-prep crop --input-descis the exception.Parallelism.
--nprocs N(also--n_cpus) lets a command use N cores; without it, subjects run one at a time.nirspipe ... participant,nirspipe-qc ... participantand thenirspipe-prepsubcommandscrop,edit-markersandkeep-spanstake it. The dyad commandsnirspipe-hyper,nirspipe-hyper-pairnullandnirspipe-qc ... grouptake it too and run N groups at once, so memory use grows with N.
Configuration file#
--config takes a TOML file of settings, so a run can be kept under version control and run again. Every run writes one: its run record, sub-<label>/logs/sub-<label>.toml (with _ses- and _task- added when --session-label or --task-label chose part of the subject), is in this format, so --config on a record reruns the run it records. The files the run read are copied beside the record (Run record), and the rerun reads those copies, so it uses the same tables even after the originals change or move. A record moved without its inputs/ folder reads the paths in its settings instead, with a warning.
[prep]
dpf = [6.0]
sci_threshold = 0.8
cardiac_l_freq = 0.7
cardiac_h_freq = 2.0
resp_l_freq = 0.1
resp_h_freq = 0.5
[post]
mode = "glm"
high_pass = 0.01
low_pass = 0.5
noise_model = "auto"
drift_model = "cosine"
drift_high_pass = 0.01
events_path = "path/to/events.tsv"
nirspipe /data/bids /data/out participant --config study_config.toml
# rerun a subject exactly, or with one setting changed
nirspipe /data/bids /data/out2 participant --config /data/out/sub-01/logs/sub-01.toml --noise-model ar1
Keys are flag names without the leading -- and with hyphens turned into underscores, in the flag’s own units. [prep] holds the preprocessing flags, the cardiac, respiration and separation bands among them; [post] holds mode, the postprocessing flags and roi_mapping; [execution] holds the selection (participant_label, session_label, task_label, bids_filter_file, ignore, allow_cropped_input). A key outside a section, an unknown section or key, or a value the flag would refuse stops the run before anything is read, naming the key. The input and output directories and the analysis level always come from the command line.
nirspipe-hyper --config reads a dyad’s run record, group-<id>/logs/group-<id>_task-<task>.toml, the same way: its [hyper] section, keyed by flag name, fills every setting the command line leaves out, and the directories and --pairs-csv come from the command line.
nirspipe-hyper /data/out /data/hyper2 group --pairs-csv pairs.csv \
--config /data/hyper/group-G01/logs/group-G01_task-hold.toml --band-fmin 0.05
Mode defaults#
Each post setting is taken from the first layer that has it: the command line, then --config, then the mode’s defaults below, then the code default (mostly off). A preprocessing setting has no mode layer.
Setting |
|
|
|
|---|---|---|---|
|
0.01 |
none |
0.01 |
|
0.5 |
none |
0.08 |
|
none |
|
|
|
none |
required: Hz or |
0.01 |
|
|
|
|
|
|
No mode fills a value that depends on the design, the montage or the population: the cosine cutoff of a task design, which you type or ask for as auto; short-channel regression, which defaults to auto in every mode (pca where the run’s montage has a channel at or under --short-max-dist, none where it has none); and the cardiac and respiration bands, which --population fills. To switch a mode’s value off, say so: --high-pass none, --drift-model none, --short-channel none, or high_pass = "none" in the file. The run report lists every setting you did not type, and where it came from.
Population#
--population fills the values that depend on the participants’ age, unless the command line or --config sets them.
|
Ages |
Cardiac band (Hz) |
Respiration band (Hz) |
DPF |
Head template |
|---|---|---|---|---|---|
|
under 1 year |
1.5 to 3.1 |
0.3 to 1.1 |
the age equation at 0.5 years |
each participant’s nearest infant template, by their age in |
|
1 to 12 years |
0.8 to 2.6 |
0.2 to 0.9 |
at 8 years |
fsaverage, as MNE ships no template for 2 to 18 years |
|
12 to 18 years |
0.7 to 1.8 |
0.1 to 0.4 |
at 15 years |
fsaverage, as MNE ships no template for 2 to 18 years |
|
18 to 65 years |
0.7 to 1.8 |
0.1 to 0.5 |
at 30 years |
fsaverage |
|
65 years and over |
0.7 to 1.8 |
0.1 to 0.5 |
at 70 years |
fsaverage |
The bands cover the ages of the group, from the Channel screening table. The DPF is computed at one age for the whole batch (Beer-Lambert law). For a cohort that spans more than one group, use --dpf age, which takes each participant’s own age. Under infant, every participant needs an age in participants.tsv, or pass --template. nirspipe-qc ... participant takes --population the same way. The run report and the Methods say which values the population filled.
Contrast file#
--contrast-file names a table of linear contrasts over the condition regressors: a TSV or CSV with one row per contrast, its name in a contrast column and one column per trial_type value holding its weight. An empty cell leaves that condition out of the contrast (the columns are aligned here for reading; the file separates them with tabs or commas):
contrast task rest tap_left tap_right
task_vs_rest 1 -1
left_minus_right 1 -1
A TOML file of the same contrasts, one entry per contrast mapping trial_type values to weights, is read as well:
task_vs_rest = { task = 1.0, rest = -1.0 }
left_minus_right = { tap_left = 1.0, tap_right = -1.0 }
A cell that is not a number, a contrast named twice or one that weights nothing stops the run before its first subject, naming the line; a condition the design does not carry stops the subject. Written to <run>_desc-contrast_nirsmap.tsv, one row per contrast and channel.
nirspipe#
participant preprocesses each selected subject, and postprocesses it when --mode is given. group reads the quality records under OUTPUT_DIR and writes the cohort pages; it reads nothing from BIDS_DIR and needs no preprocessing flag. A participant-level setting typed at the group level is refused, as in nirspipe-qc, and a selection flag there is ignored with a warning. The run stops before writing anything when the output directory is the input, or when --participant-label names a subject the dataset does not have. What each step does is in Processing workflow.
A flag you type that the run, as set, does not read is named in a warning before the first subject and again under the run report’s command: a postprocessing flag without --mode, a GLM flag such as --stim-dur under --mode rest, --fir-delays without --hrf-model fir, a drift setting another --drift-model ignores, a censoring setting without --gvtd-censor. A value that came from --config is never called typed.
BIDS-compatible fNIRS preprocessing and postprocessing pipeline. Prep always runs; add --mode to run postprocessing. Dyad analysis lives in nirspipe-hyper, which reads what this writes.
usage: nirspipe bids_dir output_dir {participant,group} [options]
Positional Arguments#
- bids_dir
BIDS dataset directory.
- output_dir
Output directory (BIDS Derivatives).
- analysis_level
Possible choices: participant, group
Processing level.
groupis the BIDS Apps name for the cohort pass; it writes desc-subjects_qc.tsv, desc-conditions_qc.tsv (one row per run and condition) and desc-subjects_report.html and, where the tree holds groups, desc-groups_qc.tsv and desc-groups_report.html.
Named Arguments#
- --version
show program’s version number and exit
preprocessing (required for participant level)#
- --dpf
Differential pathlength factor: one value, one per wavelength, or age for one per wavelength from each participant’s age in participants.tsv (Scholkmann & Wolf 2013).
- --sci-threshold
Scalp coupling index a window must reach, e.g. 0.8. Required: no default.
subject / session / task selection#
- --participant-label, --participant_label
Subject ID(s) to process.
- --session-label, --session_label
Session label(s) to process.
- --task-label, --task_label
Task label(s) to process.
- --bids-filter-file, --bids_filter_file
JSON file with extra pybids query filters.
preprocessing (optional)#
- --motion-correction
Possible choices: tddr, wavelet, tpca, spline, spline_sg, wavelet_tddr, spline_wavelet, none
Motion correction method (default tddr).
Default:
'tddr'- --template
Possible choices: fsaverage, 2wk, 1mo, 2mo, 3mo, 4.5mo, 6mo, 7.5mo, 9mo, 10.5mo, 12mo, 15mo, 18mo, 2yr
Head the optodes are placed on and drawn over: fsaverage (adult) or an MNE infant template by age, 2wk to 2yr. Default fsaverage; with --dpf age, the template nearest each participant’s age, and ages over 2 and under 18 need this option.
- --population
Possible choices: infant, child, adolescent, adult, older
Age group whose values fill the four cardiac and respiration band edges, --dpf and --template where they are not given: infant (under 1 year), child (1 to 12 years), adolescent (12 to 18 years), adult (18 to 65 years), older (65 years and over). The DPF is the age equation at one age for the whole batch; infant places each participant on the template nearest their age.
- --motion-std-thresh
Motion detection threshold of the spline methods, in standard deviations of each channel’s first difference: a source-detector pair’s samples are marked where either wavelength changes by more than this within the detection window. Read by spline, spline_wavelet; default per method (spline 20, spline_wavelet 13). Refused with any other method.
- --wavelet-iqr
Wavelet outlier fence, in interquartile ranges beyond the quartiles: detail coefficients past it are zeroed, so a smaller value removes more of the signal. Read by wavelet, wavelet_tddr, spline_wavelet; default per method (wavelet 1.5, wavelet_tddr 1.5, spline_wavelet 0.8). Refused with any other method.
- --bad-channels
Source-detector labels to mark as bad, e.g. ‘S1_D1,S2_D3’, for every subject; or a table with a bad_channels column, rows optionally limited by participant_id, session, task, acq and run as in --keep-spans. Either wavelength marks the pair. Marked, not removed, and added to the SCI-detected bad channels. A table with a rater column holds one rater’s decisions.
- --keep-spans
Table of the stretches to use (onset and duration in s on each recording’s own time axis), rows optionally limited by participant_id, session, task, acq and run. The rest is marked BAD_unselected and left out of screening and every estimate; a recording no row matches is used whole. See --keep-spans-from.
- --keep-spans-from
Measure each --keep-spans onset from the first annotation named MARKER instead of the recording’s start, so one row serves recordings that did not start time-locked; an onset may be negative. --bad-spans stays on the recording’s own axis.
- --bad-spans
Table of corrupted stretches (motion, a loose optode) in the --keep-spans format. Each is marked BAD_manual: left out of screening and of every estimate. One rater’s, as for --bad-channels. Filled by --censor-fill before any filter.
- --cardiac-l-freq
Lower bound of cardiac band in Hz (required at participant level unless --population sets it). Adult resting ~0.7; children and infants higher (e.g. 1.0-1.7).
- --cardiac-h-freq
Upper bound of cardiac band in Hz (required at participant level unless --population sets it). Adult resting ~1.5; children and infants higher (e.g. 2.5-3.0).
- --resp-l-freq
Lower bound of respiration band in Hz (required at participant level unless --population sets it). Adult ~0.1; infants higher.
- --resp-h-freq
Upper bound of respiration band in Hz (required at participant level unless --population sets it). Adult ~0.5; infants higher.
- --psp-threshold
Peak spectral power (QT-NIRS scale) a window must also reach. No default: SCI alone decides and PSP is only shown. 0.1 is a line for fitting the headgear; 0.075 has been used after recording.
- --min-good-frac
Share of windows a channel must pass in to be kept, 0 to 1 (default 0.75). A window passes when it clears --sci-threshold, and --psp-threshold if given. This is the criterion that rejects.
- --screen-scope
Possible choices: run, task
Which windows count toward --min-good-frac: ‘run’ (default) the whole recording, ‘task’ only the annotated task blocks. ‘task’ falls back to ‘run’ when no annotation holds two screening windows.
Default:
'run'- --short-max-dist
Separation at or below which a channel is short-distance, in mm (default 10). Short channels see scalp only and are measured, and regressed, separately from the long ones.
- --long-min-dist
Separation at or above which a channel is long, in mm (default 15). A channel in the gap above --short-max-dist counts as neither short nor long.
- --long-max-dist
Separation above which a channel is too far to be long, in mm. Off by default, so any separation past --long-min-dist counts as long.
- --window-length
Sliding-window length for the windowed SCI, PSP and GVTD series (default 10).
Default:
10.0- --epoch-tmin
Trial window start relative to event onset in s, for the epoch figures, the glm block average and per-trial scoring; negative pulls in a baseline. Omitted, the figures and the block average use -5 to 25 s and each trial is scored over its own duration.
- --epoch-tmax
Trial window end relative to event onset in s. Given together with --epoch-tmin, or neither.
- --epoch-chunk-duration
Cut each task annotation into trials this long before epoching, so a block design gets one trial per piece: a 240 s block at 25 s gives 9, the remainder dropped.
- --by-condition
Also write one QC report page per annotated condition, as cond-<condition>. Its numbers are sliced from the run’s windowed pass, its spectra and epochs are redrawn on the condition, and its verdict is the condition’s; the data were processed under the run’s.
Default:
False- --gvtd-censor
Possible choices: long, short, all
Mark the frames GVTD flags as BAD_gvtd on the given channel set: long if none is named, or
allto also catch movement seen only on short channels. Annotated, never cut, so epoching drops the trials they overlap. Off by default: on a high-motion recording it can flag everything.- --gvtd-censor-n-std
Threshold for --gvtd-censor, in left-tail SDs above the GVTD mode (default 10, a lenient value for censoring). The reports score at the same 10.
Default:
10.0- --gvtd-min-epoch
Shortest surviving stretch --gvtd-censor keeps (default 30). Anything shorter is censored with the artifacts around it.
Default:
30.0
postprocessing (requires --mode)#
- --mode
Possible choices: denoise, glm, rest
Postprocessing mode: denoise (bandpass, plus confound regression when short-channel regression runs or --drift-model is given), glm or rest. Each mode fills in its own defaults for the post settings, which --config and then the command line override. The run record names where each setting came from.
- --high-pass
High-pass filter cutoff in Hz, e.g. 0.01, or none to switch off the mode’s default.
- --low-pass
Low-pass filter cutoff in Hz, e.g. 0.5, or none to switch off the mode’s default.
- --filter-method
Possible choices: iir, fir
Bandpass design, default ‘iir’. ‘iir’ is a zero-phase Butterworth. ‘fir’ is a hamming-windowed linear-phase filter, which needs 3.3 * sfreq / transition samples and is refused when that is longer than the recording.
- --filter-order
Butterworth order, default 4, ignored by --filter-method fir. Applied with filtfilt, so the effective rolloff is twice this and the cutoff sits at -6 dB.
- --export-mean-filled
Also write desc-meanfilled beside the final residual: every frame inside a BAD_ span set to its channel’s kept mean, annotations kept, for tools that ignore annotations. Not for ALFF, fALFF or a GLM: the filled frames are placeholders.
- --censor-fill
Possible choices: linear, spline, lomb
How corrupted BAD_ spans (all but BAD_unselected) are filled before the bandpass, default ‘linear’: ‘linear’ joins the kept samples either side, ‘spline’ fits one cubic spline through them, ‘lomb’ rebuilds the span from a Lomb-Scargle fit up to 0.25 Hz. The spans stay marked.
- --resample-sfreq
Target sampling rate in Hz after filtering, e.g. 2.0.
- --combine-runs, --no-combine-runs
After postprocessing, join each task’s runs, each z-scored per channel over its kept frames, into one series written without the run entity, and compute FC on it. A channel joins only from the runs where it is good. ALFF and GLM tables stay per run.
- --chromophores
Possible choices: hbo, hbr, hbt
Chromophores the GLM tables, block average, FC and ALFF carry, default hbo hbr. hbt, total haemoglobin, is HbO + HbR of each channel; the stage files keep HbO and HbR.
- --fc
Also write the connectivity products rest mode writes, from the residual this mode leaves: the task residual in glm, the confound residual in denoise. Ignored by --mode rest, which writes them anyway.
- --min-time
Seconds outside every BAD_ span a run needs before FC and ALFF are computed; default 0, off. A run under it gets no FC or ALFF file, and its residual’s sidecar says why. The GLM fit is not affected.
postprocessing: GLM and confound regression#
- --stim-dur
Stimulus duration (s) for annotation-based events: one number for every condition, or NAME=SEC per condition (a plain number then covers the rest), e.g. Tapping=20 Control=15. 0 fits an instantaneous response whose beta is its peak. Mutually exclusive with --events-path.
- --hrf-model
Possible choices: spm, spm + derivative, spm + derivative + dispersion, glover, glover + derivative, glover + derivative + dispersion, fir
HRF basis. ‘spm + derivative’ adds temporal derivative column.
- --noise-model
Residual autocorrelation model, default ‘auto’ in glm mode and ‘ols’ in rest and denoise: ‘ols’, ‘auto’ (an AR order of 4x the sampling rate), ‘arN’ for order N, or ‘ar_irls’, which adds a robust norm so residual motion is down-weighted (‘ar_irlsN’ caps its order), or ‘worsley’, auto’s order with the coefficients corrected for the bias the fit leaves in the residual (‘worsleyN’ for order N). Too low an order inflates task t values.
- --drift-model
Possible choices: cosine, polynomial, none
Low-frequency drift regressors in design matrix. glm and rest default to cosine; optional in denoise, where the bandpass detrends.
- --drift-high-pass
High-pass cutoff for cosine drift in Hz. Required by --mode glm, since it depends on the design: at most 1/(2 x the slowest condition repeat). ‘auto’ (glm only) computes that per run from its events, capped at 0.01 Hz and never below --high-pass.
- --drift-order
Polynomial drift order (polynomial drift model only), default 1.
- --fir-delays
FIR delay bins in scans, e.g. 0 1 2 3 4 5 (only used when --hrf-model fir).
- --short-channel
Possible choices: auto, none, mean, pca
Short-channel confound regressor strategy, default auto: pca where the montage has a channel at or under --short-max-dist, none where it has none. Honoured by every mode: glm fits it alongside the task, denoise and rest on its own. ‘mean’ gives one column per chromophore; ‘pca’ gives one column per short channel, orthogonalised, which fits the same as entering every short channel.
- --aux-regressors
Also regress out the recording’s auxiliary signals (accelerometer, respiration, pulse), from the aux table preprocessing wrote, in every mode. Each is anti-aliased onto the data’s samples, band-passed as the data and z-scored. Off by default. Useful where the montage has no short channels.
- --aux-channels
The aux channels --aux-regressors enters, by their column names in desc-aux_timeseries.tsv.gz, e.g. ACC_X ACC_Y ACC_Z. Default: every channel in it.
- --events-path
Path to *_events.tsv. {sub}, {ses}, {task}, {acq} and {run} in it are filled from each run, e.g. events/sub-{sub}_task-{task}_events.tsv; without them one file serves every run. If omitted, extracted from snirf annotations.
- --contrast-file
GLM contrasts: a TSV or CSV with one row per contrast, its name in a contrast column and a weight under each condition’s column (an empty cell leaves it out), or a TOML of contrast = {condition = weight}.
- --p-correction
Possible choices: none, fdr_bh, fdr_by, holm, bonferroni
Multiple-comparison correction of the GLM and contrast p values (default none), within one regressor or contrast and one chromophore, over the long channels not marked bad. p_value, two-sided, is always written; a method adds a p_<method> column beside it, and the family column says how many tests it ran over.
output#
- --no-report
Skip the QC HTML report.
Default:
False- --roi-mapping
JSON file mapping ROI labels to lists of channel names. Groups the report denoising carpet and lists each region’s long channels kept, and in rest mode adds the ROI correlation matrix and one seed topography per ROI; at group level the cohort page counts the runs per region that kept none. Optional.
execution#
- --config
A run record (sub-<label>/logs/sub-<label>*.toml) or a TOML of the same shape: [prep] and [post] keyed by flag name. Reruns with its settings; flags given here override it, and its post settings override the mode’s defaults.
- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many subjects run at once and spare cores go to each subject’s numerics. Omit to run one subject at a time on every core.
- --dry-run
Write each subject’s run record, then stop without processing.
Default:
False- --verbose
Print debug messages on the console too, each step’s timing and paths among them.
Default:
False
escape hatches#
- --ignore
Possible choices: bids-validation, channel-status
Processing aspects to skip. ‘channel-status’: do not mark bad the channels each run’s BIDS channels.tsv marks bad in its status column, which are otherwise unioned with --bad-channels.
- --skip-bids-validation, --skip_bids_validation, --skip_bids_validator
Do not check the input with bids-validator. Files BIDS does not recognise are left out either way.
Default:
False- --allow-cropped-input
Run on a
nirspipe-prep croptree, which is otherwise refused. Every condition is then preprocessed on its own, and motion correction and the bandpass each see one segment, which moves both. Preprocess the uncut recording and crop the result instead (nirspipe-prep crop --input-desc).Default:
False
nirspipe-snirf2bids#
Converts one raw SNIRF file per call (Converting raw SNIRF).
Convert a raw snirf file to BIDS format (one subject at a time). For multiple subjects, loop over this command or use the GUI SNIRF to BIDS page.
usage: nirspipe-snirf2bids input_file bids_dir --participant-label PARTICIPANT_LABEL --task-label TASK_LABEL [options]
Positional Arguments#
- input_file
Input snirf file.
- bids_dir
Output BIDS dataset directory.
Named Arguments#
- --version
show program’s version number and exit
- --participant-label, --participant_label
Subject label, e.g. ‘01’ or ‘patient01’. BIDS has no group folders, so encode patient/control in the label if IDs overlap.
- --task-label, --task_label
Task label, e.g. tapping.
- --session-label, --session_label
Session label. Omit if dataset has no session layer.
- --run-label
Run index, e.g. 01.
- --optode-frame
Possible choices: unknown, head, mri
Space of the SNIRF’s optode coordinates, which SNIRF does not record (default unknown). Under unknown no _optodes.tsv or _coordsystem.json is written, both of which BIDS requires. ‘head’: digitised against the nasion and preauricular points. ‘mri’: already on a template brain (MNI or fsaverage), as many acquisition programs export them.
Default:
'unknown'- --overwrite
Replace a recording the dataset already holds under the same entities. Without it the conversion stops there.
Default:
False
nirspipe-prep#
crop, align and edit-markers apply each write a new tree under OUTPUT_DIR (cropped/, aligned/, marker_edited/); edit-markers export writes event tables for editing and keep-spans one table. Without --participant-label a subcommand reads every subject of its input. What each does is in Data preparation.
fNIRS data preparation: cropping, alignment, marker editing and --keep-spans tables.
usage: nirspipe-prep [-h] [--version] {crop,align,edit-markers,keep-spans} ...
Named Arguments#
- --version
show program’s version number and exit
Sub-commands#
crop#
Crop SNIRFs to a time window or segments.
nirspipe-prep crop [-h]
[--participant-label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]]
[--session-label SESSION_LABEL] [--task-label TASK_LABEL]
[--run-label RUN_LABEL] [--nprocs N]
[--skip-bids-validation] [--tmin SECONDS] [--tmax SECONDS]
[--segments-path SEGMENTS_PATH] [--align {none,trigger}]
[--trigger-name TRIGGER_NAME] [--combine | --no-combine]
[--margin SEC|auto] [--band-fmin HZ] [--input-desc DESC]
bids_dir output_dir
Positional Arguments#
- bids_dir
BIDS dataset root, or a derivatives tree with --input-desc.
- output_dir
Where the derived tree goes. A
cropped/subtree is created under it, so point this at a derivatives root rather than at one dataset.
Named Arguments#
- --participant-label, --participant_label
Subject ID(s) to process (default every subject of the input).
- --session-label, --session_label
Session label.
- --task-label, --task_label
Task label.
- --run-label, --run_label
Run label.
- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many subjects run at once and spare cores go to each subject’s numerics. Omit to run one subject at a time on every core.
- --skip-bids-validation, --skip_bids_validation, --skip_bids_validator
Do not check the input with bids-validator.
Default:
False- --tmin
Start time in seconds (single segment).
- --tmax
End time in seconds (single segment).
- --segments-path
TSV with onset/duration columns defining segments to keep. Each segment written to its own file is named by a
taskcolumn, which more than one segment needs unless --combine is given.- --align
Possible choices: none, trigger
t=0 for --tmin/--tmax and segment onsets: ‘none’ (default) = recording start, ‘trigger’ = first annotation named --trigger-name.
Default:
'none'- --trigger-name
Annotation description marking t=0 when --align trigger. A recording without it falls back to the recording start.
- --combine, --no-combine
Concatenate multi-segment output into one file.
Default:
False- --margin
Keep this many extra seconds on each side of every segment, and record the span that was asked for in the sidecar. ‘auto’ takes the width from --band-fmin. Off by default.
- --band-fmin
Lowest frequency the later analysis will average over, used only to resolve --margin auto. Give the same value as nirspipe-hyper --wtc-band-fmin.
- --input-desc
Cut a processed stage instead of a recording, e.g. ‘errts’ or ‘filtered’. bids_dir is then a derivatives tree. The desc- entity is kept on the output.
align#
Align multi-subject recordings by shared trigger.
nirspipe-prep align [-h] --pairs-csv PAIRS_CSV [--skip-bids-validation]
bids_dir output_dir
Positional Arguments#
- bids_dir
BIDS dataset root.
- output_dir
Where the derived tree goes. An
aligned/subtree is created under it.
Named Arguments#
- --pairs-csv
CSV with columns: group_id, subject_id, task, and optionally session, run and occasion, the table the dyad commands take.
- --skip-bids-validation, --skip_bids_validation, --skip_bids_validator
Do not check the input with bids-validator.
Default:
False
edit-markers#
Edit markers in SNIRF files.
nirspipe-prep edit-markers [-h] {export,apply} ...
Sub-commands#
export#
Export events.tsv(s) for manual editing.
nirspipe-prep edit-markers export [-h]
[--participant-label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]]
[--session-label SESSION_LABEL]
[--task-label TASK_LABEL]
[--run-label RUN_LABEL] [--nprocs N]
[--skip-bids-validation]
bids_dir out_dir
Positional Arguments#
- bids_dir
BIDS dataset root.
- out_dir
Directory to write the exported events TSV(s).
Named Arguments#
- --participant-label, --participant_label
Subject ID(s) to process (default every subject of the input).
- --session-label, --session_label
Session label.
- --task-label, --task_label
Task label.
- --run-label, --run_label
Run label.
- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many subjects run at once and spare cores go to each subject’s numerics. Omit to run one subject at a time on every core.
- --skip-bids-validation, --skip_bids_validation, --skip_bids_validator
Do not check the input with bids-validator.
Default:
False
apply#
Apply marker edits (tsv/shift/set-duration/rename).
nirspipe-prep edit-markers apply [-h]
[--participant-label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]]
[--session-label SESSION_LABEL]
[--task-label TASK_LABEL]
[--run-label RUN_LABEL] [--nprocs N]
[--skip-bids-validation] [--tsv TSV]
[--shift SECONDS] [--set-duration SECONDS]
[--rename RENAME [RENAME ...]]
bids_dir output_dir
Positional Arguments#
- bids_dir
BIDS dataset root.
- output_dir
Where the derived tree goes. A
marker_edited/subtree is created under it.
Named Arguments#
- --participant-label, --participant_label
Subject ID(s) to process (default every subject of the input).
- --session-label, --session_label
Session label.
- --task-label, --task_label
Task label.
- --run-label, --run_label
Run label.
- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many subjects run at once and spare cores go to each subject’s numerics. Omit to run one subject at a time on every core.
- --skip-bids-validation, --skip_bids_validation, --skip_bids_validator
Do not check the input with bids-validator.
Default:
False- --tsv
Edited events TSV to apply (same file applied to all subjects).
- --shift
Shift all onsets by this many seconds (negative = earlier). Clipped to 0.
- --set-duration
Set all marker durations to this value (seconds).
- --rename
Rename marker: ‘old:new’. Repeatable.
keep-spans#
Write a --keep-spans table from condition names.
nirspipe-prep keep-spans [-h]
[--participant-label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]]
[--session-label SESSION_LABEL]
[--task-label TASK_LABEL] [--run-label RUN_LABEL]
[--nprocs N] [--skip-bids-validation] --conditions
NAME [NAME ...] [--duration SEC]
bids_dir out_tsv
Positional Arguments#
- bids_dir
BIDS dataset root.
- out_tsv
The table to write, for nirspipe --keep-spans: one row per occurrence of each condition, onsets in seconds on each recording’s own time axis.
Named Arguments#
- --participant-label, --participant_label
Subject ID(s) to process (default every subject of the input).
- --session-label, --session_label
Session label.
- --task-label, --task_label
Task label.
- --run-label, --run_label
Run label.
- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many subjects run at once and spare cores go to each subject’s numerics. Omit to run one subject at a time on every core.
- --skip-bids-validation, --skip_bids_validation, --skip_bids_validator
Do not check the input with bids-validator.
Default:
False- --conditions
Annotation names whose occurrences to keep, as the recording’s markers name them. A selected recording holding none of them stops the command.
- --duration
Give every occurrence this length instead of its own, as edit-markers --set-duration does. Without it a zero-length occurrence stops the command.
nirspipe-qc#
What each report shows is in QC. Run the participant level on every subject first, then group on the same OUTPUT_DIR: the cohort pages and, with --pairs-csv, each dyad’s page, read from the members’ records rather than screened again (The raw QC tree). A flag typed at the level it does not belong to is refused. The participant level writes a run record per subject, which --config reruns; the group level takes no screening flag.
nirspipe-qc /data/bids /data/qc participant --population adult --sci-threshold 0.8
nirspipe-qc /data/bids /data/qc group --pairs-csv pairs.csv
fNIRS raw quality control as a BIDS App: one report per recording at participant level, then the cohort pages and, given a pairs table, each dyad’s page at group level, all in one tree.
usage: nirspipe-qc bids_dir output_dir {participant,group} [options]
Positional Arguments#
- bids_dir
BIDS dataset root, read only.
- output_dir
The raw QC tree: each subject’s reports under sub-<label>/, each dyad’s under group-<id>/, the cohort pages at the root.
- analysis_level
Possible choices: participant, group
participant: screen and report each recording, subjects independently and in parallel. group: after every participant run, the cohort page and, with --pairs-csv, each dyad’s page read from its members’ records, so a member keeps its own lines, band and verdict.
Named Arguments#
- --version
show program’s version number and exit
selection (both levels)#
- --participant-label, --participant_label
Subject ID(s), e.g. ‘01’. Participant level: the subjects to report, every one when omitted, one’s failure not stopping the rest. Group level: only the dyads with one of them as a member.
- --session-label, --session_label
Session label(s). At group level a group’s occasion where the pairs table has one, else its session; a row with neither is read once per listed session.
- --task-label, --task_label
Task label(s) to include.
- --roi-mapping
JSON file mapping ROI labels to lists of channel names. Groups the motion carpet’s rows by ROI and lists each region’s long channels kept; at group level the cohort page also counts the runs per region that kept none. Optional.
- --skip-bids-validation, --skip_bids_validation, --skip_bids_validator
Do not check the input with bids-validator.
Default:
False- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many jobs run at once and spare cores go to each job’s numerics. Omit to run one job at a time on every core. A job is a subject at participant level, a dyad at group level.
participant level#
- --run-label, --run_label
Run label(s) to include. Every recording gets a report of its own.
- --bids-filter-file, --bids_filter_file
JSON file with extra pybids query filters.
- --config
A raw QC run record (sub-<label>/logs/*_desc-raw.toml) or a TOML of its shape: [qc] keyed by flag name. Reruns with its settings; flags given here override it.
- --dpf
Differential pathlength factor: one value, one per wavelength, or age for one per wavelength from each participant’s age in participants.tsv (Scholkmann & Wolf 2013).
- --template
Possible choices: fsaverage, 2wk, 1mo, 2mo, 3mo, 4.5mo, 6mo, 7.5mo, 9mo, 10.5mo, 12mo, 15mo, 18mo, 2yr
Head the optodes are placed on and drawn over: fsaverage (adult) or an MNE infant template by age, 2wk to 2yr. Default fsaverage; with --dpf age, the template nearest each participant’s age, and ages over 2 and under 18 need this option.
- --population
Possible choices: infant, child, adolescent, adult, older
Age group whose values fill the four cardiac and respiration band edges, --dpf and --template where they are not given: infant (under 1 year), child (1 to 12 years), adolescent (12 to 18 years), adult (18 to 65 years), older (65 years and over). The DPF is the age equation at one age for the whole batch; infant places each participant on the template nearest their age.
- --sci-threshold
Scalp coupling index a window must reach, e.g. 0.8. Required: no default.
- --psp-threshold
Peak spectral power (QT-NIRS scale) a window must also reach. No default: SCI alone decides and PSP is only shown. 0.1 is a line for fitting the headgear; 0.075 has been used after recording.
- --min-good-frac
Share of windows a channel must pass in to be kept, 0 to 1 (default 0.75). A window passes when it clears --sci-threshold, and --psp-threshold if given. This is the criterion that rejects.
- --screen-scope
Possible choices: run, task
Which windows count toward --min-good-frac: ‘run’ (default) the whole recording, ‘task’ only the annotated task blocks. ‘task’ falls back to ‘run’ when no annotation holds two screening windows.
Default:
'run'- --cardiac-l-freq
Lower bound of cardiac band in Hz (required at participant level unless --population sets it).
- --cardiac-h-freq
Upper bound of cardiac band in Hz (required at participant level unless --population sets it).
- --resp-l-freq
Lower bound of respiration band in Hz (required at participant level unless --population sets it).
- --resp-h-freq
Upper bound of respiration band in Hz (required at participant level unless --population sets it).
- --window-length
Sliding-window length for the windowed SCI, PSP and GVTD series (default 10).
Default:
10.0- --epoch-qc
Add a per-trial section: score each event window on its own and show them as a trial x metric heatmap.
Default:
False- --epoch-tmin
Trial window start relative to event onset in s; negative pulls in a baseline. Omit to use each event’s own duration.
- --epoch-tmax
Trial window end relative to event onset in s. Given together with --epoch-tmin, or neither.
- --short-max-dist
Separation at or below which a channel is short-distance, in mm (default 10). Short channels see scalp only and are measured, and regressed, separately from the long ones.
- --long-min-dist
Separation at or above which a channel is long, in mm (default 15). A channel in the gap above --short-max-dist counts as neither short nor long.
- --long-max-dist
Separation above which a channel is too far to be long, in mm. Off by default, so any separation past --long-min-dist counts as long.
- --by-condition
Also write one report per annotated condition, beside the run’s own, as <run>_cond-<condition>_desc-raw_report.html. Their numbers are sliced out of the run’s windowed pass, on the same window grid and filter as the run. Each page’s screening verdict is that condition’s; the run’s own page carries the run’s.
Default:
False- --motion-correction
Possible choices: tddr, wavelet, tpca, spline, spline_sg, wavelet_tddr, spline_wavelet, none
The correction each recording is prepared with, written into the tree’s stages/ as nirspipe writes it, and the page shows the recording before and after it. Screening and coupling are measured before it, on the recording as delivered. Default tddr, as nirspipe. With none the recording is reported uncorrected only. The group level’s motion panel shows each member’s.
Default:
'tddr'- --motion-std-thresh
Motion detection threshold of the spline methods, in standard deviations of each channel’s first difference: a source-detector pair’s samples are marked where either wavelength changes by more than this within the detection window. Read by spline, spline_wavelet; default per method (spline 20, spline_wavelet 13). Refused with any other method.
- --wavelet-iqr
Wavelet outlier fence, in interquartile ranges beyond the quartiles: detail coefficients past it are zeroed, so a smaller value removes more of the signal. Read by wavelet, wavelet_tddr, spline_wavelet; default per method (wavelet 1.5, wavelet_tddr 1.5, spline_wavelet 0.8). Refused with any other method.
- --bad-channels
Source-detector labels to mark as bad, e.g. ‘S1_D1,S2_D3’, for every subject; or a table with a bad_channels column, rows optionally limited by participant_id, session, task, acq and run as in --keep-spans. Either wavelength marks the pair. Marked, not removed, and added to the SCI-detected bad channels. A table with a rater column holds one rater’s decisions.
- --keep-spans
Table of the stretches to use (onset and duration in s on each recording’s own time axis), rows optionally limited by participant_id, session, task, acq and run. The rest is marked BAD_unselected and left out of screening and every estimate; a recording no row matches is used whole. See --keep-spans-from.
- --keep-spans-from
Measure each --keep-spans onset from the first annotation named MARKER instead of the recording’s start, so one row serves recordings that did not start time-locked; an onset may be negative. --bad-spans stays on the recording’s own axis.
- --bad-spans
Table of corrupted stretches (motion, a loose optode) in the --keep-spans format. Each is marked BAD_manual: left out of screening and of every estimate. One rater’s, as for --bad-channels.
- --ignore
Possible choices: channel-status
Aspects to skip. ‘channel-status’: do not mark bad the channels each recording’s BIDS channels.tsv marks bad in its status column. Pass it here when the nirspipe run being checked passed it.
group level#
- --pairs-csv
CSV with columns: group_id, subject_id, task, and optionally session, run and occasion. Each unique (group_id, task, session) is one dyad page, read from its members’ records; an occasion column joins members whose session labels differ and names the group’s outputs ses-<occasion>. Omit for the cohort page alone.
- --group-id
Process only this group_id of --pairs-csv.
- --normalize, --no-normalize
Z-score each channel per subject after alignment.
Default:
False- --no-align
Skip trigger-based alignment; trim all recordings to the shortest duration.
Default:
False- --tstart
Report on this time (s) onward, on the aligned clock, where 0 is the shared trigger. Omit to start at the alignment point.
- --tend
Report up to this time (s) on the aligned clock; omit to run to the end. Narrows the synchrony metrics only, not the per-subject quality record. In
nirspipe-hyperthe window is read out of the whole-recording transform, and conditions outside it are dropped.
nirspipe-provenance#
Redraws the provenance graph of every subject and dyad in a tree from the sidecars already on disk, so it works on any past run and refreshes the image a written report points at (Outputs).
Render the file provenance graph of every subject and dyad in a tree, from the sidecars already on disk.
usage: nirspipe-provenance [-h] [--version] output_dir
Positional Arguments#
- output_dir
Any tree this package wrote.
Named Arguments#
- --version
show program’s version number and exit
nirspipe-hyper#
DERIVATIVES_DIR is the nirspipe tree and OUTPUT_DIR the dyad tree; they must differ. What each step does is in Hyperscanning.
As in nirspipe, a flag you type that the run, as set, does not read is named in a warning before the first dyad and under the dyad page’s command: --wtc-mc-count without --wtc-significance, --seed when nothing is drawn at random, --wtc-cond-pad without --wtc-cond-transform, --wtc-roi-min-channels without --roi-mapping, --wtc-arrow-min and --isc-threshold under --no-report.
Hyperscanning analysis: wavelet coherence, inter-subject correlation and the phase-scrambled null, over a derivatives tree nirspipe has already written.
usage: nirspipe-hyper derivatives_dir output_dir {group} --pairs-csv PAIRS_CSV [options]
Positional Arguments#
- derivatives_dir
BIDS derivatives directory nirspipe wrote, holding each member’s sub-<id>/nirs/ recordings.
- output_dir
Where the dyad results go. Keep it apart from the source tree so each carries its own dataset_description.json.
- analysis_level
Possible choices: group
Always
group: every metric here needs both members present.
Named Arguments#
- --version
show program’s version number and exit
dyad selection#
- --pairs-csv
CSV with columns: group_id, subject_id, task, and optionally session, run and occasion. Each unique (group_id, task, session) is processed as one group; an occasion column joins members whose session labels differ and names the group’s outputs ses-<occasion>.
- --group-id
Process only this group_id. Omit to process all groups.
- --participant-label, --participant_label
Process only the groups with at least one of these subjects as a member. The whole group still runs, partner included.
- --task-label, --task_label
Task label(s) to include, filtering the pairs table.
input#
- --desc
desc entity of the per-subject stage the inter-brain metrics read (default preproc), e.g. ‘preproc’ (Beer-Lambert output) or ‘errts’ (confound-regression residual, which is what short-channel regression leaves behind). Must be a haemoglobin stage, not an optical-density one.
Default:
'preproc'- --chromophores
Possible choices: hbo, hbr, hbt
Chromophores the coherence and the correlation run on, default hbo hbr. Each is a separate pass, never mixed, so each costs a full run. hbt, total haemoglobin, is HbO + HbR of each channel.
Default:
['hbo', 'hbr']- --bads-scope
Possible choices: run, subject
Which rejected channels are excluded: ‘run’ (default) this task’s own, ‘subject’ the union over the subject’s runs in the pairs table, so all conditions share one channel set. They differ only when conditions were cropped to separate tasks before preprocessing.
Default:
'run'- --short-max-dist
Separation at or below which a channel is short-distance, in mm (default 10). Short channels see scalp only and are measured, and regressed, separately from the long ones. An override: the bands come from each member’s record, and members prepped with different bands are refused. Use it only for records that carry none.
- --long-min-dist
Separation at or above which a channel is long, in mm (default 15). A channel in the gap above --short-max-dist counts as neither short nor long. An override: the bands come from each member’s record, and members prepped with different bands are refused. Use it only for records that carry none.
- --long-max-dist
Separation above which a channel is too far to be long, in mm. Off by default, so any separation past --long-min-dist counts as long. An override: the bands come from each member’s record, and members prepped with different bands are refused. Use it only for records that carry none.
alignment and time window#
- --normalize, --no-normalize
Z-score each channel per subject after alignment.
Default:
False- --no-align
Skip trigger-based alignment; trim all recordings to the shortest duration.
Default:
False- --tstart
Report on this time (s) onward, on the aligned clock, where 0 is the shared trigger. Omit to start at the alignment point.
- --tend
Report up to this time (s) on the aligned clock; omit to run to the end. Narrows the synchrony metrics only, not the per-subject quality record. In
nirspipe-hyperthe window is read out of the whole-recording transform, and conditions outside it are dropped.
pairings and regions#
- --roi-mapping
JSON file mapping ROI labels to lists of channel names, for ROI-level WTC. Optional.
- --wtc-roi-min-channels
Drop an ROI cell where either member contributes fewer than N channels (default 1). The default keeps a region one surviving channel stands in for; the n_ch column says how many pairings each value rests on. Each side of a crossed cell is counted on its own.
Default:
1- --channel-cross, --no-channel-cross
Cross every long channel with every channel of the other brain (default on), so n channels give n^2 values; the channel TSV gains a label2 column. --no-channel-cross pairs each channel with its counterpart only, for the ISC as for the coherence.
Default:
True
bands#
- --wtc-band-fmin
Lower bound (Hz) of the band the per-channel WTC TSV averages over. For nirspipe-hyper it defaults to --band-fmin, else --wtc-fmin, i.e. the whole computed axis; for nirspipe-hyper-band it is the new band and is required.
- --wtc-band-fmax
Upper bound (Hz) of that band. Defaults to --band-fmax, else --wtc-fmax, for nirspipe-hyper; required for nirspipe-hyper-band.
- --wtc-mask-coi, --no-wtc-mask-coi
Average each band mean only over cells outside the cone of influence, the region the edges of the record reach (default on). --no-wtc-mask-coi averages the whole band instead; the share outside the cone is reported as n_valid_frac either way.
Default:
True- --band-fmin
Low edge of the band both metrics read, the coherence averaging over it and the correlation filtering to it. --wtc-band-fmin and --isc-fmin override it for one metric.
- --band-fmax
High edge of that band. --wtc-band-fmax and --isc-fmax override it for one metric.
- --isc-fmin
Band-limit each member before the correlation, low edge (default --band-fmin). Without either, ISC reads whatever the preprocessing passband left. The run warns when the ISC band differs from the coherence band. Filtering happens on the whole recording, before a condition window is cut.
- --isc-fmax
The high edge of that band (default --band-fmax).
wavelet coherence#
- --wtc-fmin
Lower bound of the WTC frequency axis (default 0.004).
Default:
0.004- --wtc-fmax
Upper bound of the WTC frequency axis (default 0.20).
Default:
0.2- --wtc-significance
Overlay a Monte Carlo significance contour on WTC (slow: see --wtc-mc-count for how slow). This asks whether a time-frequency cell beats red noise, which is a different question from the phase-scrambled null of --wtc-phase-null.
Default:
False- --wtc-mc-count
Surrogate series behind each --wtc-significance contour (default 300). This is what the runtime is spent on and it scales linearly; lower it to preview a run, raise it to settle a contour. Ignored without --wtc-significance.
Default:
300- --wtc-arrow-min
Coherence a cell needs before its phase arrow is drawn, when no null was computed (default 0.5). Display only; --wtc-phase-null or --wtc-significance replace it with a level per frequency.
Default:
0.5- --wtc-limit-scales, --no-wtc-limit-scales
Compute only the wavelet scales inside --wtc-fmin/--wtc-fmax plus margin, instead of every scale the record length allows (default on). The coherences match the unrestricted ones. --no-wtc-limit-scales computes every scale.
Default:
True- --wtc-save-maps
Save the full time-frequency coherence maps beside each TSV as npz, so a different band can be averaged later with
nirspipe-hyper-bandinstead of a second wavelet transform. Large: one array per pair per dyad per task.Default:
False- --wtc-whiten
Prewhiten each long channel with an autoregressive model of this many seconds of order before the wavelet coherence, fitted on the whole aligned record; 0, the default, transforms the signals themselves. Phase and lag then describe the whitened signals, and the nulls follow it.
Default:
0.0
conditions#
- --wtc-window
Cut every condition into non-overlapping windows of this length and make the window the unit. Needs --by-condition; the remainder, and any condition shorter than one window, is dropped.
- --by-condition, --no-by-condition
Read the coherence out of each task annotation’s window as well as over the whole recording (default on; --no-by-condition turns it off), as rows of stat-wtc_relmat.tsv with a condition column. A trigger without a duration runs to the next; windows shorter than one cycle of --wtc-fmin are skipped.
Default:
True- --wtc-cond-cone, --no-wtc-cond-cone
Leave out each condition’s own cone of influence at its start and end, where the coherence carries the neighbouring condition (default on). A window keeps its condition’s edges. --no-wtc-cond-cone keeps those cells.
Default:
True- --wtc-cond-transform
Transform each condition on its own instead of reading it out of the whole-run transform, over a cut padded by --wtc-cond-pad. Costs one extra transform per condition per chromophore. Requires --by-condition; refused with --wtc-phase-null.
Default:
False- --wtc-cond-pad
Seconds kept on each side of a condition under --wtc-cond-transform, then windowed back off. ‘auto’ (default) is 2*sqrt(2)/--wtc-band-fmin, e.g. 47 s at 0.06 Hz. 0 cuts each condition to its own boundaries, which biases a short condition’s band mean upward.
Default:
auto
inter-subject correlation#
- --isc-threshold
Absolute |ISC| a pairing must clear for a chord in the connectivity circle. By default chords mark pairings above their own null (with --isc-phase-null) or the strongest tenth (without). Its scale moves with --desc, the passband, whitening and --isc-max-lag.
- --isc-whiten
Prewhiten each long channel with an autoregressive model of this many seconds of order before the correlation, fitted on the whole aligned record; 0, the default, correlates the signals themselves. Whitening shrinks r, so whitened and unwhitened matrices do not compare; the nulls follow it.
Default:
0.0- --isc-max-lag
Correlate at every shift within this many seconds either way and keep the strongest (default 0, no search); the shift reaches stat-isc_relmat.tsv as lag_s. A maximum over shifts is inflated under no coupling, so pair it with --isc-phase-null, which searches the same way.
Default:
0.0
nulls#
- --seed
Seed the --wtc-significance surrogates and the --wtc-phase-null and --isc-phase-null draws. Omitted with any of them on, one is drawn and written to the run record, so a --config rerun repeats them.
- --wtc-phase-null
Also write the phase-scrambled null over N iterations, each as costly as a full WTC run; omitted, no null is computed. It follows the --by-condition windows, and the maps then draw phase arrows against its level instead of --wtc-arrow-min.
- --wtc-phase-null-cross, --no-wtc-phase-null-cross
Cross the channels for the phase-scrambled null too. Unset, it follows --channel-cross. Crossing squares the pair count on every iteration. --no-wtc-phase-null-cross draws the null over the homologous pairings only, which covers the homologous rows of a crossed real table (label equal to label2).
- --isc-phase-null
Also rank each correlation against N phase-scrambled surrogates of the second member, which keep its spectrum. Adds null_abs_mean, null_abs_sd, null_abs_p95 and percentile to stat-isc_relmat.tsv, all of them magnitudes, since a correlation is two-sided. Off by default; it costs N extra correlations per chromophore per window.
Default:
0- --phase-null-shared
In each --wtc-phase-null and --isc-phase-null draw, shift all of the second member’s channels by one shared set of random phases, so they stay as correlated with each other as recorded. Off by default: each channel is scrambled on its own.
Default:
False
execution#
- --verbose
Print debug messages on the console too, each step’s timing and paths among them.
Default:
False- --no-report
Write the tables and skip the HTML report and its figures. Everything else is unchanged: the same numbers, the same files, the same npz when --wtc-save-maps is given.
Default:
False- --check-only
Load and align each dyad, print what the metrics would be computed on, and stop. Nothing is written. Use it to look over a cohort’s channel budget before committing to a long run, such as one with --wtc-phase-null.
Default:
False- --config
A dyad’s run record (logs/group-<id>_task-<task>.toml) or a file with its [hyper] section. Fills every setting the command line leaves out; the directories and --pairs-csv still come from the command line.
- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many groups run at once and spare cores go to each group’s numerics. Omit to run one group at a time on every core.
- --device
Possible choices: cpu, cuda
Where the wavelet transforms run (default cpu). cuda uses an NVIDIA card in double precision, checked against the CPU on each group’s first pairing; install with pip install “nirspipe[gpu]”.
Default:
'cpu'
nirspipe-hyper-pairnull#
Runs after nirspipe-hyper, whose tables it reads (Re-paired null).
Recomputes the coherence of one member against people they never interacted with, drawn from the other groups of the same task, and writes the null-pair tables beside the real ones. Unlike --wtc-phase-null, a re-paired partner did the same task, so the null keeps the shared task response. Needs a cohort: the number of draws is the number of other groups, which is what limits how finely the percentile can rank. In a group of three or more the first member is held and each later one replaced. Run it after nirspipe-hyper, whose tables it reads its band, its mask, its frequency range and its window off, and by default its stage, its rejection scope, its crossing and its ROI minimum.
usage: nirspipe-hyper-pairnull derivatives_dir output_dir {group} --pairs-csv PAIRS_CSV [options]
Positional Arguments#
- derivatives_dir
BIDS derivatives directory nirspipe wrote, holding each member’s sub-<id>/nirs/ recordings.
- output_dir
Where the dyad results go. Keep it apart from the source tree so each carries its own dataset_description.json.
- analysis_level
Possible choices: group
Always
group: every metric here needs both members present.
Named Arguments#
- --verbose
Print debug messages on the console too, each step’s timing and paths among them.
Default:
False- --pairs-csv
CSV with columns: group_id, subject_id, task, and optionally session, run and occasion. Each unique (group_id, task, session) is processed as one group; an occasion column joins members whose session labels differ and names the group’s outputs ses-<occasion>.
- --group-id
Process only this group_id. Omit to process all groups.
- --participant-label, --participant_label
Process only the groups with at least one of these subjects as a member. The whole group still runs, partner included.
- --task-label, --task_label
Task label(s) to include, filtering the pairs table.
- --version
show program’s version number and exit
- --desc
desc entity of the per-subject stage the null reads. Unset, it is the one the real tables recorded; a different one is refused.
- --roi-mapping
JSON file mapping ROI labels to channel names, to also write the null of the homologous ROI means and, when the null and the real tables are both crossed, of the ROI x ROI matrix. Optional.
- --bads-scope
Possible choices: run, subject
Which rejected channels are excluded, as in nirspipe-hyper. Unset, it is the scope the real tables recorded; a different one is refused. A stand-in with no quality record is refused rather than kept whole.
- --chromophores
Possible choices: hbo, hbr, hbt
Chromophores to draw the null on, coherence and correlation alike (default hbo hbr).
Default:
['hbo', 'hbr']- --wtc-pair-pool
Possible choices: position, any
Who may stand in: ‘position’ (default) only another group’s member at the same index, or in the same role where the pairs table has a role column, which keeps roles apart and is safe when one person is in several groups; ‘any’ every other group’s member, refused when anyone appears twice.
Default:
'position'- --wtc-pair-max
Stop after N draws; in a group of three or more, the same N draws for every pairing. The pool is finite, so this is a ceiling rather than a count: without it every eligible stand-in is used, which is what gives the percentile its best resolution.
- --wtc-pair-cross, --no-wtc-pair-cross
Draw the null over every channel pair rather than homologous ones only. Unset, it follows the real table: crossed when that table is. A crossed null costs one full run per channel pair, so --no-wtc-pair-cross over a crossed table draws the homologous pairings only and ranks that table’s diagonal.
- --wtc-roi-min-channels
Drop an ROI cell where either member contributes fewer than N channels. Unset, it is the value the real tables recorded; a different one is refused.
- --wtc-limit-scales, --no-wtc-limit-scales
Compute only the scales inside the frequency range plus margin (default on), as in nirspipe-hyper.
Default:
True- --no-report
Leave each dyad’s pages as nirspipe-hyper drew them. By default they are drawn again from the dyad’s run record, reading its phase null from disk, so the condition arrows read this null.
Default:
False- --nprocs, --n_cpus, --n-cpus
CPU cores to use in all. Up to this many groups run at once and spare cores go to each group’s numerics. Omit to run one group at a time on every core.
- --device
Possible choices: cpu, cuda
Where the wavelet transforms run (default cpu). cuda uses an NVIDIA card in double precision, checked against the CPU on each group’s first pairing; install with pip install “nirspipe[gpu]”.
Default:
'cpu'
nirspipe-hyper-groupnull#
Reads the null draws already written and runs no transform (Above the channel).
Averages each dyad’s channels first and ranks that mean inside a null’s draws, once per occasion and once over the cohort. It says whether the pairing beats its null, not which channel does; nirspipe-hyper-pairnull ranks each channel inside its own draws, where against n stand-ins no cell can reach a p under 1/(n+1). It reads draws already on disk and runs no transform.
usage: nirspipe-hyper-groupnull output_dir {group} --task-label TASK_LABEL [options]
Positional Arguments#
- output_dir
Where the dyad results go. Keep it apart from the source tree so each carries its own dataset_description.json.
- analysis_level
Possible choices: group
Always
group: every metric here needs both members present.
Named Arguments#
- --verbose
Print debug messages on the console too, each step’s timing and paths among them.
Default:
False- --version
show program’s version number and exit
- --task-label, --task_label
Task whose tables to read, one at a time.
- --chromophores
Possible choices: hbo, hbr, hbt
Chromophores to read, each into its own tables (default every chromophore the null’s draws hold). One the draws do not hold is refused.
- --null
Possible choices: repaired, phase
Which nulls’ draws to read, each into its own tables (default every null whose draws are on disk for the task). Both are read the same way above the cell; they differ in what a draw is, a stand-in against a scrambled partner.
- --roi-mapping
Region to channel map, as in the other stages. Given it, each region is a level of its own beside the whole brain (its homologous pairings averaged), and with a crossed null so is every ordered region pair. A region needs the real tables’ --wtc-roi-min-channels channels per member.
- --n-resample
Resamples behind the cohort null (default 20000). Each picks one stand-in per occasion, so the finest p it can express is 1/(n+1).
Default:
20000- --seed
Seed the resampling. Omitted, one is drawn and written to the cohort tables’ sidecars.
- --p-correction
Possible choices: none, fdr_bh, fdr_by, holm, bonferroni
Multiple-comparison correction, within one condition at one level (default none). The uncorrected p column is always written; a method adds a p_<method> column beside it, and the family column says how many tests it ran over.
Default:
'none'- --isc-test
Possible choices: signed, magnitude
How the correlation is tested (default signed): ‘signed’ averages Fisher z and tests either direction; ‘magnitude’ averages |Fisher z| and tests it above the null, so opposite signs do not cancel. Coherence is always tested above its null.
Default:
'signed'
nirspipe-hyper-band#
Re-averages the maps nirspipe-hyper --wtc-save-maps saved over another band.
Re-averages the maps a nirspipe-hyper --wtc-save-maps saved, so no wavelet transform runs a second time. Writes tables, not a report. --wtc-band-fmin and --wtc-band-fmax are both required here.
usage: nirspipe-hyper-band output_dir {group} [options]
Positional Arguments#
- output_dir
Where the dyad results go. Keep it apart from the source tree so each carries its own dataset_description.json.
- analysis_level
Possible choices: group
Always
group: every metric here needs both members present.
Named Arguments#
- --verbose
Print debug messages on the console too, each step’s timing and paths among them.
Default:
False- --wtc-band-fmin
Lower bound (Hz) of the band the per-channel WTC TSV averages over. For nirspipe-hyper it defaults to --band-fmin, else --wtc-fmin, i.e. the whole computed axis; for nirspipe-hyper-band it is the new band and is required.
- --wtc-band-fmax
Upper bound (Hz) of that band. Defaults to --band-fmax, else --wtc-fmax, for nirspipe-hyper; required for nirspipe-hyper-band.
- --wtc-mask-coi, --no-wtc-mask-coi
Average each band mean only over cells outside the cone of influence, the region the edges of the record reach (default on). --no-wtc-mask-coi averages the whole band instead; the share outside the cone is reported as n_valid_frac either way.
Default:
True- --version
show program’s version number and exit
- --wtc-suffix
Value of the band- entity on each output TSV, letters and digits only. Defaults to the band, e.g. 0p05to0p2 for band-0p05to0p2, so the new tables sit beside the originals rather than replacing them.
nirspipe-hyper-index#
Writes group-
usage: nirspipe-hyper-index output_dir {group} [options]
Positional Arguments#
- output_dir
Where the dyad results go. Keep it apart from the source tree so each carries its own dataset_description.json.
- analysis_level
Possible choices: group
Always
group: every metric here needs both members present.
Named Arguments#
- --verbose
Print debug messages on the console too, each step’s timing and paths among them.
Default:
False- --version
show program’s version number and exit
- --group-id
Only this dyad. Every group-* directory by default.
nirspipe-hyper-merge#
Concatenates every group-*task-**_relmat.tsv under the tree into one table per kind at its root, adding group_id and task columns, so a cohort analysis reads one file. Refuses to merge tables that disagree on the band, on mask_coi, on which null they are or on the stand-in pool, crossed with homologous tables, and matrices over different channels. A differing null iteration count only warns: n_iter is kept per row.
usage: nirspipe-hyper-merge output_dir {group} [options]
Positional Arguments#
- output_dir
Where the dyad results go. Keep it apart from the source tree so each carries its own dataset_description.json.
- analysis_level
Possible choices: group
Always
group: every metric here needs both members present.
Named Arguments#
- --verbose
Print debug messages on the console too, each step’s timing and paths among them.
Default:
False- --version
show program’s version number and exit
nirspipe-rate#
hyper takes the raw QC tree nirspipe-qc ... group wrote the dyad’s page into as OUTPUT_DIR, and writes each member’s channel decisions there, beside the member’s raw report. See Rating.
Interactive QC review for fNIRS data: rating, individual viewer, hyperscanning viewer.
usage: nirspipe-rate [-h] [--version] {rate,raw,hyper,export} ...
Positional Arguments#
- command
Possible choices: rate, raw, hyper, export
Named Arguments#
- --version
show program’s version number and exit
Sub-commands#
rate#
Launch QC rating interface.
nirspipe-rate rate [-h]
[--participant-label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]]
[--port PORT] [--rater RATER]
output_dir
Positional Arguments#
- output_dir
nirspipe output directory.
Named Arguments#
- --participant-label, --participant_label
Subject ID(s) to open. Default: all found.
- --port
Local server port. Default: 8765, or the next free port above it.
- --rater
Your name or initials, letters and digits. Your ratings go to files of your own, so raters never overwrite each other. Default: the shared files.
raw#
Launch interactive raw QC viewer: rate sections, decide channels, mark bad stretches.
nirspipe-rate raw [-h] --participant-label PARTICIPANT_LABEL
[--session-label SESSION_LABEL] [--task-label TASK_LABEL]
[--run-label RUN_LABEL] [--sci-threshold R] [--port PORT]
[--rater RATER]
output_dir
Positional Arguments#
- output_dir
nirspipe output directory.
Named Arguments#
- --participant-label, --participant_label
Subject ID to open, e.g. ‘01’. Every raw report of the subject the other labels match opens, each recording on its own page.
- --session-label, --session_label
Session label.
- --task-label, --task_label
Task label.
- --run-label, --run_label
Run label.
- --sci-threshold
A second SCI line: outline each SCI (10 s) cell below it. The red cells stay the run’s own line. Off when not given.
- --port
Local server port. Default: 5052, or the next free port above it.
- --rater
Your name or initials, letters and digits. Your ratings, channel decisions and marked stretches go to files of your own, so raters never overwrite each other. Default: the shared files.
hyper#
Launch interactive hyperscanning QC viewer.
nirspipe-rate hyper [-h] --group-id GROUP_ID --task-label TASK_LABEL
--pairs-csv PAIRS_CSV [--session-label SESSION_LABEL]
[--sci-threshold R] [--port PORT] [--rater RATER]
output_dir
Positional Arguments#
- output_dir
The tree holding the group-<id>/ raw report, as nirspipe-qc’s group level wrote it.
Named Arguments#
- --group-id
Group ID to open, e.g. ‘A’.
- --task-label, --task_label
Task label, e.g. ‘tapping’.
- --pairs-csv
CSV with columns: group_id, subject_id, task (same as nirspipe-qc’s group level). Used to look up subject IDs in this group.
- --session-label, --session_label
Session label.
- --sci-threshold
A second SCI line: outline each member’s SCI (10 s) cell below it. The red cells stay each member’s own line. Off when not given.
- --port
Local server port. Default: 5053, or the next free port above it.
- --rater
Your name or initials, letters and digits. Your ratings and channel decisions go to files of your own, so raters never overwrite each other. Default: the shared files.
export#
Export channel decisions for nirspipe --bad-channels.
nirspipe-rate export [-h] [--out-dir OUT_DIR] [--rater RATER]
trees [trees ...]
Positional Arguments#
- trees
The raw QC trees holding the decision files.
Named Arguments#
- --out-dir, --out_dir
Folder for the two tables. Default: the first tree.
- --rater
Export only this rater’s files. Default: every rater’s, named in a rater column; nirspipe takes one rater’s table.
nirspipe-gui#
Starts the GUI, a local web app, and opens it in your browser (GUI).
Local web GUI: a page per command with its form, Data Preparation for editing a recording’s events and crop, and the rating viewers.
usage: nirspipe-gui [-h] [--port PORT]
Named Arguments#
- --port
Local server port. Default: 8050, or the next free port above it.
Troubleshooting#
--verbose prints debug output, including each step’s timing and paths; the same stream goes to the subject’s live log in sub-<label>/logs/, named like its run record. Rerunning a subject overwrites its outputs, and rerunning the same selection its run record; to keep both, write to a second output directory. A rerun that changes the passband, the resampling rate or the drift basis warns before overwriting, since those files’ names do not show the change.
Message |
Cause and fix |
|---|---|
|
bids-validator found errors; the message lists them. Check |
|
MNE’s fsaverage is downloaded the first time it is needed, to place the optodes or to draw a brain figure, and this machine could not fetch it, usually for lack of internet access. Preprocessing goes on and writes |
|
Under |
|
The infant template a participant needs could not be downloaded. Fetch it on a machine with internet access with |
|
Spline correction does not support recordings sampled below 10/3 Hz; choose another |
Every channel marked bad |
The |
|
The pairs file is missing |
|
The members carry no annotation in common. Rename the markers into one scheme, or use |
|
A member lacks the |
A report with missing figures |
A figure that fails leaves a placeholder; its error is under Errors & Warnings, and the traceback in the |
A GLM with no results |
Check that exactly one of |
A rating port in use |
Pass |