nirspipe.pipeline.crop#

SNIRF cropping: single-segment and multi-segment to BIDS derivatives.

Crops a raw recording, or with input_desc a pipeline stage inside a derivatives tree.

Module Contents#

Functions#

crop_snirf_from_path

Crop a SNIRF given its path directly (no BIDS layout lookup).

crop_snirf

Crop a SNIRF via BIDS layout lookup and write to derivatives/cropped/.

Data#

API#

nirspipe.pipeline.crop.logger = 'get_logger(...)'#
nirspipe.pipeline.crop.crop_snirf_from_path(snirf_path: pathlib.Path, derivatives_dir: pathlib.Path, sub: str, ses: str | None = None, *, tmin: float | None = None, tmax: float | None = None, segments_df: pandas.DataFrame | None = None, combine: bool = False, align: str = 'none', trigger_name: str | None = None, derivative: bool = False, margin_s: float = 0.0) → list[pathlib.Path]#

Crop a SNIRF given its path directly (no BIDS layout lookup).

Public entry point shared by the interface. derivative says the input is a pipeline stage rather than a recording, which changes how the output’s sidecar is written. margin_s widens every cut by that many seconds on each side and records the unwidened span in the sidecar. Returns list of written SNIRF paths.

nirspipe.pipeline.crop.crop_snirf(bids_dir: pathlib.Path, derivatives_dir: pathlib.Path, sub: str, ses: str | None = None, task: str | None = None, run: str | None = None, *, tmin: float | None = None, tmax: float | None = None, segments_path: pathlib.Path | None = None, combine: bool = False, align: str = 'none', trigger_name: str | None = None, validate: bool = False, input_desc: str | None = None, margin_s: float = 0.0) → list[pathlib.Path]#

Crop a SNIRF via BIDS layout lookup and write to derivatives/cropped/.

Single segment: use tmin/tmax. Multi-segment: use segments_path (table with onset/duration columns). A task column names each segment, and its output takes that task entity. More than one segment without it is refused unless combine=True, which concatenates them into one file.

align=”trigger” measures tmin/tmax (and every segment onset) from the first annotation named trigger_name rather than from the recording start, so one window selects the same stretch of task in subjects whose recordings started at different moments.

margin_s keeps that many extra seconds on each side of every segment and records the span that was asked for as crop_analysis_windows_s. A segment cut to its own boundaries cannot be analysed at those boundaries by anything that convolves, which is every wavelet method; the margin is what a later stage windows back off. See cone_margin_s() for the width that suffices.

input_desc cuts a pipeline stage instead of a recording: bids_dir is then a derivatives tree and the file carrying that desc- entity is the input, e.g. “errts” for the residual. The desc- entity is kept on the output, so a cut of the residual is …_task-baseline_desc-errts_nirs.snirf.

Returns list of written SNIRF paths.