nirspipe.qc.metrics.motion#

Motion measured per channel: spikes, and what a correction repaired.

Two things GVTD does not answer. Spikes are a per-channel MAD outlier count in the motion band, so a single flailing optode is visible where a global index averages it away. The correction footprint compares optical density either side of the motion step and flags the samples the correction actually moved, which is the closest thing to a scrubbing record for a continuous corrector like TDDR. Both are experimental, and both overlap GVTD by design.

Module Contents#

Functions#

motion_correction_metrics

Experimental: motion-correction footprint, the timepoints a correction repaired.

motion_corrected_segments

Time spans where motion correction touched >= ch_frac of channels (for plotting).

spike_segments

Time spans where >= ch_frac of channels show a motion-band OD spike (for plotting).

Data#

API#

nirspipe.qc.metrics.motion.SPIKE_CH_FRAC = 0.1#
nirspipe.qc.metrics.motion.motion_correction_metrics(raw_before: mne.io.Raw, raw_after: mne.io.Raw, rel_thresh: float = 1.0, ch_frac: float = SPIKE_CH_FRAC) → dict[str, Any]#

Experimental: motion-correction footprint, the timepoints a correction repaired.

Per channel a sample is a correction event when the frame-to-frame rate of correction exceeds rel_thresh times the channel’s sample-to-sample noise. A timepoint is flagged globally when at least ch_frac of channels have an event there, giving FD-style scrubbing scalars (num/pct/segments) on top of the per-channel fractions.

Parameters:
  • raw_before (mne.io.Raw) -- Optical density immediately before and after the motion-correction step.

  • raw_after (mne.io.Raw) -- Optical density immediately before and after the motion-correction step.

  • rel_thresh (float, optional) -- Correction rate, as a multiple of the channel’s sample-to-sample noise, above which a sample counts as a correction event.

  • ch_frac (float, optional) -- Fraction of channels that must be corrected at a timepoint for it to count as a globally corrected (scrubbed) timepoint.

Returns:

motion_corrected_frac_mean / _frac_per_channel (per-channel burden) and the FD-analog global scalars motion_corrected_num / _pct / _n_segments.

Return type:

dict

Notes

Experimental and correction-agnostic: it measures the footprint of whatever correction ran (e.g. TDDR repairs only the < 0.5 Hz component), not a new correction. Overlaps GVTD (both track motion); it measures correction burden.

nirspipe.qc.metrics.motion.motion_corrected_segments(raw_before: mne.io.Raw, raw_after: mne.io.Raw, rel_thresh: float = 1.0, ch_frac: float = SPIKE_CH_FRAC) → list[tuple[float, float]]#

Time spans where motion correction touched >= ch_frac of channels (for plotting).

nirspipe.qc.metrics.motion.spike_segments(raw_intensity: mne.io.Raw, ch_frac: float = SPIKE_CH_FRAC) → list[tuple[float, float]]#

Time spans where >= ch_frac of channels show a motion-band OD spike (for plotting).