rtcog.preproc.helpers package

Submodules

rtcog.preproc.helpers.iglm module

class rtcog.preproc.helpers.iglm.iGLM[source]

Bases: object

Incremental Generalized Linear Model for detrending and removal of nuisance regressors in real time.

regress_vol(n, Yn, Fn)[source]

Apply real-time regression to fMRI data.

Parameters:
  • n (int) – Current volume number.

  • Yn (np.ndarray, shape (Nvoxels, 1)) – The current fMRI data point (masked).

  • Fn (np.ndarray, shape (Nregressors, 1)) – The current regressor values.

Returns:

  • Yn_d (np.ndarray, shape (Nvoxels, 1)) – The residual (detrended) fMRI data.

  • Bn (np.ndarray, shape (Nvoxels, Nregressors, 1)) – The regression coefficient estimates.

rtcog.preproc.helpers.kalman_filter module

class rtcog.preproc.helpers.kalman_filter.KalmanFilter(mask_Nv, n_cores, pool)[source]

Bases: object

Kalman filter for low pass filtering, spike removal, and signal smoothing.

initialize_kalman_pool()[source]

Initialize pool up front to avoid delay later

initialize_pool()[source]
static kalman_filter_mv(input_dict)[source]
run_volume(n, data)[source]

Run Kalman filter on a single volume. Parallelizes via pools.

update_welford(k, x)[source]

rtcog.preproc.helpers.preproc_utils module

class rtcog.preproc.helpers.preproc_utils.CircularBuffer(Nv, size)[source]

Bases: object

Circular buffer for storing recent fMRI volumes for windowed operations.

Parameters:
  • Nv (int) – Number of voxels in each volume.

  • size (int) – Size of the circular buffer (number of volumes to store).

buffer

The circular buffer storing the recent volumes.

Type:

np.ndarray, shape (Nv, size)

insert_idx

Current insertion index in the buffer.

Type:

int

size

Size of the buffer.

Type:

int

full

Whether the buffer has been filled at least once.

Type:

bool

update(data)[source]
rtcog.preproc.helpers.preproc_utils.calculate_spc(current_signal, baseline_signal, mean_removed)[source]

Calculate signal percent change (SPC) for a given timepoint.

The SPC is computed voxel-wise as either: - 100 * (s / s̄) if the mean has already been removed (e.g. via EMA) - 100 * ((s - s̄) / s̄) otherwise

Parameters:
  • current_signal (np.ndarray, shape (Nvoxels,)) – The current volume’s voxel intensities after prior preprocessing.

  • baseline_signal (np.ndarray, shape (Nvoxels,)) – The voxel-wise mean signal computed from the baseline period.

  • mean_removed (bool) – Whether the signal mean has already been removed (e.g., via EMA). If True, use multiplicative SPC; if False, use standard SPC.

Returns:

The normalized signal.

Return type:

np.ndarray, shape (Nvoxels, 1)

rtcog.preproc.helpers.preproc_utils.gen_polort_regressors(polort, nt)[source]

Generate Legendre polynomials of a given order for nuisance regression purposes.

Parameters:
  • polort (int) – Maximum polynomial order to generate.

  • nt (int) – Number of data points.

Returns:

out – Legendre polynomial regressors.

Return type:

np.ndarray, shape (nt, polort)

rtcog.preproc.helpers.preproc_utils.rt_smooth_vol(data_arr, mask_img, fwhm=4)[source]

Apply smoothing to fMRI data volumes.

Parameters:
  • data_arr (np.ndarray, shape (Nvoxels, 1)) – The input fMRI data array to be processed.

  • mask_img (nibabel.Nifti1Image) – A binary mask image.

  • fwhm (float, optional) – The full width at half maximum (FWHM) value used to define the smoothing kernel. The default is 4 mm.

Returns:

The smoothed fMRI data.

Return type:

np.ndarray, shape (Nvoxels, 1)

rtcog.preproc.helpers.preproc_utils.welford(k, x, M, S)[source]

Module contents