nirspipe.pipeline.censor_fill#

Corrupted BAD_ spans filled before the continuous steps (bandpass, resample, regression).

Only corrupted spans are filled; BAD_unselected is real data and stays as measured. The filled samples remain under their spans, so every estimate still leaves them out. Frames at either end that measured no light are held and marked here too, before any OD conversion.

Module Contents#

Functions#

corrupted_mask

Per sample, whether it lies under a corrupted BAD_ span.

fill_values

Replace the samples under gap from the samples outside it, channel by channel.

fill_corrupted

Fill the corrupted spans of raw in place, every channel; the annotations stay.

dark_edge_frames

How many frames at the start and at the end measured no light in most channels.

repair_dark_edges

raw with its dark edge frames held at the nearest lit frame and marked BAD_edge.

Data#

API#

nirspipe.pipeline.censor_fill.logger = 'get_logger(...)'#
nirspipe.pipeline.censor_fill.FILL_METHODS = ('linear', 'spline', 'lomb')#
nirspipe.pipeline.censor_fill.DEFAULT_CENSOR_FILL = 'linear'#
nirspipe.pipeline.censor_fill.LOMB_FMAX_HZ = 0.25#
nirspipe.pipeline.censor_fill.LOMB_OVERSAMPLE = 4#
nirspipe.pipeline.censor_fill.corrupted_mask(raw: mne.io.BaseRaw) → numpy.ndarray#

Per sample, whether it lies under a corrupted BAD_ span.

10 Hz, BAD_gvtd 1.0-1.3 s, BAD_unselected 0-0.5 s  ->  True at samples 10, 11, 12 only
nirspipe.pipeline.censor_fill.fill_values(data: numpy.ndarray, gap: numpy.ndarray, method: str, sfreq: float) → numpy.ndarray#

Replace the samples under gap from the samples outside it, channel by channel.

Parameters:
  • data (ndarray, shape (n_channels, n_times)) -- The signal, measured everywhere including under the gap.

  • gap (ndarray of bool, shape (n_times,)) -- True where a sample is to be replaced. At least one sample must be False.

  • method ({"linear", "spline", "lomb"}) -- "linear" joins the kept samples either side of each gap with a straight line. "spline" runs one cubic spline through every kept sample and reads it inside the gaps. "lomb" rebuilds the gaps from a Lomb-Scargle fit to the kept samples (sinusoids up to LOMB_FMAX_HZ at LOMB_OVERSAMPLE times oversampling, scaled to the kept samples’ SD). Under "linear" and "spline" a gap at either end of the recording takes the nearest kept value; nothing is extrapolated.

  • sfreq (float) -- Sampling rate in Hz, which sets the Lomb-Scargle frequency grid.

Returns:

A copy of data with only the gap samples changed; every kept sample is returned bit for bit.

Return type:

ndarray, shape (n_channels, n_times)

nirspipe.pipeline.censor_fill.fill_corrupted(raw: mne.io.BaseRaw, method: str = DEFAULT_CENSOR_FILL) → mne.io.BaseRaw#

Fill the corrupted spans of raw in place, every channel; the annotations stay.

haemo with BAD_gvtd 120-123 s, method "linear"
->  the same haemo, 120-123 s a straight line between 119.9 s and 123.0 s, stamped "filled"

A recording with no corrupted span comes back untouched and unstamped. One whose corrupted spans cover every sample is refused.

nirspipe.pipeline.censor_fill.dark_edge_frames(raw: mne.io.BaseRaw) → tuple[int, int]#

How many frames at the start and at the end measured no light in most channels.

nirspipe.pipeline.censor_fill.repair_dark_edges(raw: mne.io.BaseRaw) → tuple[mne.io.BaseRaw, tuple[int, int]]#

raw with its dark edge frames held at the nearest lit frame and marked BAD_edge.