nirspipe.pipeline.post_pipeline#

Postprocessing pipeline: mode-driven, parameter-configured.

Parameters come from PostConfig, which can be populated from CLI flags or a TOML file. All steps within a mode are still individually controllable via PostConfig fields.

Module Contents#

Classes#

Functions#

resolve_short_channel

config with short_channel = "auto" decided on raw’s montage; any other value as it is.

auto_drift_cutoff

--drift-high-pass auto’s cutoff from each condition’s longest repeat: (Hz, condition, bound).

resolve_drift_high_pass

config with drift_high_pass = "auto" set from the run’s events; any other value as it is.

run_post

Run post-processing pipeline.

final_stage

The desc of the series a run ends on, the one FC reads; None when that is the run’s input.

write_combined_runs

Join one task’s runs after postprocessing and compute FC on the joined series.

mean_filled

A copy whose BAD_ frames hold each channel’s mean over its kept frames, stamped meanfilled.

Data#

API#

nirspipe.pipeline.post_pipeline.logger = 'get_logger(...)'#
nirspipe.pipeline.post_pipeline.Mode = None#
nirspipe.pipeline.post_pipeline.SHORT_CHANNEL_AUTO = 'auto'#
nirspipe.pipeline.post_pipeline.DRIFT_HIGH_PASS_AUTO = 'auto'#
nirspipe.pipeline.post_pipeline.DRIFT_AUTO_CAP = 0.01#
class nirspipe.pipeline.post_pipeline.PostConfig#
subject: str = None#
cardiac_l_freq: float = None#
cardiac_h_freq: float = None#
resp_l_freq: float = None#
resp_h_freq: float = None#
session: str | None = None#
high_pass: float | None = None#
low_pass: float | None = None#
filter_method: str = None#
filter_order: int = None#
censor_fill: str = None#
roi_map: dict | None = None#
roi_map_name: str = 'custom'#
resample_sfreq: float | None = None#
stim_dur: float | dict[str, float] | None = None#
hrf_model: str | None = None#
noise_model: str = 'auto'#
drift_model: str | None = None#
drift_high_pass: float | str | None = None#
drift_high_pass_auto: dict | None = None#
drift_order: int | None = None#
fir_delays: tuple[int, ...] | None = None#
short_channel: bool | str | None = None#
short_channel_auto: bool = False#
aux: bool = False#
aux_channels: list[str] | None = None#
events_path: str | None = None#
contrast_def: dict[str, Any] | None = None#
fc: bool = False#
min_time: float = 0.0#
export_mean_filled: bool = False#
short_max_dist: float | None = None#
long_min_dist: float | None = None#
long_max_dist: float | None = None#
combine_runs: bool | None = None#
chromophores: tuple[str, ...] = None#
p_correction: str = 'none'#
nirspipe.pipeline.post_pipeline.resolve_short_channel(config: nirspipe.pipeline.post_pipeline.PostConfig, raw: mne.io.Raw) → nirspipe.pipeline.post_pipeline.PostConfig#

config with short_channel = "auto" decided on raw’s montage; any other value as it is.

e.g. a montage with an 8 mm channel gets "pca", one with only 30 mm channels None.

nirspipe.pipeline.post_pipeline.auto_drift_cutoff(intervals: dict[str, float], high_pass: float | None = None) → tuple[float, str, str | None]#

--drift-high-pass auto’s cutoff from each condition’s longest repeat: (Hz, condition, bound).

1/(2 x the slowest condition’s gap), capped at DRIFT_AUTO_CAP and raised to the data’s high-pass, bound naming which of the two moved it. e.g. {"a": 100.0} -> 0.005 Hz. A gap of zero, a doubled annotation, repeats nothing.

nirspipe.pipeline.post_pipeline.resolve_drift_high_pass(config: nirspipe.pipeline.post_pipeline.PostConfig, raw: mne.io.Raw, events: pandas.DataFrame | None = None) → nirspipe.pipeline.post_pipeline.PostConfig#

config with drift_high_pass = "auto" set from the run’s events; any other value as it is.

1/(2 x the longest gap between two trials of one condition), the slowest condition deciding, capped at DRIFT_AUTO_CAP and raised to the data’s own high-pass, which the basis has to cover. e.g. trials of a at most 100 s apart give 0.005 Hz.

nirspipe.pipeline.post_pipeline.run_post(raw_haemo: mne.io.Raw, config: nirspipe.pipeline.post_pipeline.PostConfig, output_dir: pathlib.Path, mode: nirspipe.pipeline.post_pipeline.Mode = 'denoise', source_entities: dict[str, str] | None = None, source_path: pathlib.Path | None = None, epoch_tmin: float | None = None, epoch_tmax: float | None = None, epoch_chunk_duration: float | None = None) → tuple#

Run post-processing pipeline.

Returns (result, glm_est, design_matrix, alff_df, fc, fc_seed, fc_roi). glm_est / design_matrix are None only when no regression ran; denoise and rest return them too, fitted on empty events, so the design holds confound columns and no condition. alff_df is None outside rest mode. The FC products are written by rest mode, and by glm and denoise mode under config.fc. fc, fc_seed and fc_roi are {chromophore: frame}, the last two empty without --roi-mapping.

nirspipe.pipeline.post_pipeline.final_stage(config: nirspipe.pipeline.post_pipeline.PostConfig, mode: nirspipe.pipeline.post_pipeline.Mode) → str | None#

The desc of the series a run ends on, the one FC reads; None when that is the run’s input.

nirspipe.pipeline.post_pipeline.write_combined_runs(config: nirspipe.pipeline.post_pipeline.PostConfig, output_dir: pathlib.Path, mode: nirspipe.pipeline.post_pipeline.Mode, runs: list[dict[str, str]]) → Path | None#

Join one task’s runs after postprocessing and compute FC on the joined series.

runs holds the source entities of each run of one subject, session and task, in run order. Each run’s final series (final_stage()) is z-scored per channel over its kept frames and the runs are joined (join_runs()), a channel taking part only in the runs where it is good and NaN in the others; ROIs are averaged per run over that run’s good members before the z-score. The joined series is written without the run entity, its sidecar’s combined_runs naming each run and its onset and channel_runs the runs each channel took part in; it is bad only where every run marked it. The FC products the mode writes are computed on it, each pair over the kept frames both channels have. ALFF and the GLM’s tables stay per run. A run under --min-time is left out, and fewer than two runs left join nothing. Returns the joined file, or None.

nirspipe.pipeline.post_pipeline.MEAN_FILLED_DESCRIPTION = "The final residual with every frame inside a BAD_ span set to its channel's mean over the frames out..."#
nirspipe.pipeline.post_pipeline.mean_filled(raw: mne.io.Raw) → mne.io.Raw#

A copy whose BAD_ frames hold each channel’s mean over its kept frames, stamped meanfilled.

kept 1, 3 around a BAD_ frame  ->  1, 2, 3