utils module

Analysis and validation functions for img2fmri python package tutorial. Tutorial and analysis found at: https://github.com/dpmlab/img2fmri Author: Maxwell Bennett mbb2176@columbia.edu

utils.conv_hrf_and_downsample(input_brain, num_TR, TR=2)

Convolve with hemodynamic response function (HRF) and downsample from movie frame timecourse to TR timecourse.

Parameters:
  • input_brain (numpy.ndarray) – 4D brain volume of shape: (x,y,z,num_frames).

  • num_TR (int) – Number of TRs to downsample to.

  • TR (int) – Temporal resolution, or, frames per second (Hz). Defaults to 2.

Returns:

4D brain volume of shape: (x,y,z,num_TRs).

Return type:

numpy.ndarray

utils.extract_frames(input_file, output_dir)

Extracts frames from an input movie at 2Hz and saves them to the output_dir.

Parameters:
  • input_file (str) – Relative path to input movie file.

  • output_dir (str) – Relative path to output directory to save movie frames.

utils.get_subj_overlap(roi_list=['EarlyVis', 'OPA', 'LOC', 'RSC', 'PPA'], threshold=0.15)

Returns the indices of an MNI brain volume comprising the union of our subjects’ ROIs, after smoothing with a sigma=1 (the default smoothing kernel of img2fmri).

Parameters:
  • roi_list (list) – List of ROIs to return indices for. Defaults to [‘EarlyVis’, ‘OPA’, ‘LOC’, ‘RSC’, ‘PPA’].

  • threshold (float) – Lowerbound threshold used to consider a voxel within the mask. Defaults to 0.15.

Returns:

3D array of boolean values, with shape of MNI brain, where voxel is true if value (post smoothing) > threshold.

Return type:

numpy.ndarray

utils.get_subj_overlap_nonsmoothed(roi_list=['EarlyVis', 'OPA', 'LOC', 'RSC', 'PPA'], threshold=0.15)

Returns the indices of an MNI brain volume comprising the union of our subjects’ ROIs, before smoothing.

Parameters:
  • roi_list (list) – List of ROIs to return indices for. Defaults to [‘EarlyVis’, ‘OPA’, ‘LOC’, ‘RSC’, ‘PPA’].

  • threshold (float) – Lowerbound threshold used to consider a voxel within the mask. Defaults to 0.15.

Returns:

3D array of boolean values, with shape of MNI brain, where voxel is true if value (pre smoothing) > threshold.

Return type:

numpy.ndarray

utils.load_frames(input_dir)

Loads predicted fMRI responses to frames in sorted order, and returns a 4D volume.

Parameters:

input_dir (str) – Relative path to directory of frames to load.

Returns:

4D brain volume of shape: (x,y,z,num_frames).

Return type:

numpy.ndarray

utils.remove_DCT(input_brain, period_cut=120)

High-pass filter brain activity (default is a period_cut of constant activity over 120s) by regressing out a discrete cosine transformation (DCT) basis set.

Parameters:
  • input_brain (numpy.ndarray) – 4D brain volume of shape: (x,y,z,num_frames).

  • period_cut (int) – threshold (seconds) of high-pass filter. Defaults to 120.

Returns:

4D brain volume of shape: (x,y,z,num_frames).

Return type:

numpy.ndarray

utils.remove_average_activity(input_brain)

Removes average (across time) activity from 4D brain volume.

Parameters:

input_brain (numpy.ndarray) – 4D brain volume of shape: (x,y,z,num_frames).

Returns:

4D brain volume of shape: (x,y,z,num_frames).

Return type:

numpy.ndarray