rsatoolbox.io.spm module¶
Handeling SPM (Statistical Parametric Mapping) fMRI data
Utility object that helps to extract time series data, beta coefficients, and residuals from a GLM stored in a SPM.mat file.
## Usage
`
spm = SpmGlm('path/to/spm')
spm.get_info_from_spm_mat()
[residuals, beta, info] = spm.get_residuals('my_ROI_Mask.nii')
`
- class rsatoolbox.io.spm.SpmGlm(path: str, nitoolsMock=None)[source]¶
Bases:
objectclass for handling first-levels GLMs estimated in SPM
- Variables:
path (str) – paths to directory containing SPM files
- get_betas(mask: Nifti1Image | NDArray | str) Tuple[NDArray, NDArray, Dict][source]¶
Samples the beta images of an estimated SPM GLM at the mask locations also returns the ResMS values, and the obseration descriptors (run and condition) name
- Parameters:
mask (ndarray or nibabel nifti1image) – Indicates which voxels to extract Could be a binary 3d-array or a nifti image of the same size as the data Or a 3xP array of coordinates to extract (in mm space)
- Returns:
N x P array of beta coefficients resms (ndarray): 1d array of ResMS values obs_descriptors (dict): with lists reg_name and run_number (N long)
- Return type:
data (ndarray)
- get_info_from_spm_mat() None[source]¶
Initializes information for SPM.mat file
- Parameters:
spm_mat_path (str) – _description_
- get_residuals(mask: Nifti1Image | NDArray | str) Tuple[NDArray, NDArray, Dict][source]¶
Collects 3d images of a range of GLM residuals (typical SPM GLM results) and corresponding metadata (scan number + run info) into respective lists
- Parameters:
res_range (range) – range of to be saved residual images per run
- relocate_file(fpath: str) str[source]¶
SPM file entries to current project directory and OS.
These are file paths suffixed with two spaces and an index number. They are stored as absolute paths on the computer where it is generated, meaning the project directory, as well as OS-dependent path separator may have changed. This method fixes these.
- Parameters:
fpath (str) – SPM-style file path and number from unknown OS
- Returns:
SPM-style file path
- Return type:
str