Hello!
I am using nilearn to extract signals from a brain parcellation and compute a correlation matrix.
I have my fMRI data and I am using the Schaefer 400 atlas to define my ROIs.
The problem I have is that some of my subjects have some missing voxels in their fMRI data, therefore the time series for the ROIs with some missing voxels in my fMRI data are NaN.
It means that the mean of all voxel-time series within the ROI is NaN because some of the voxels NaN.
Then, of course, when I try to calculate the correlation matrix I have an error:
/Users/mot/.local/lib/python3.7/site-packages/nilearn/signal.py:71: RuntimeWarning: invalid value encountered in less
std[std < np.finfo(np.float).eps] = 1. # avoid numerical problems
Traceback (most recent call last): File “ztoRunLocal_RS.py”, line 28, in
correlation_matrix = correlation_measure.fit_transform([time_series])
File “/Users/mot/.local/lib/python3.7/site-packages/nilearn/connectome/connectivity_matrices.py”, line 545, in fit_transform return self.fit_transform(X, do_fit=True, do_transform=True)
File “/Users/mot/.local/lib/python3.7/site-packages/nilearn/connectome/connectivity_matrices.py”, line 490, in fit_transform).covariance for x in X]
File “/Users/mot/.local/lib/python3.7/site-packages/nilearn/connectome/connectivity_matrices.py”, line 490, in ).covariance for x in X]
File “/Users/mot/opt/anaconda3/lib/python3.7/site packages/sklearn/covariance/_shrunk_covariance.py”, line 422, in fit X = check_array(X)
File “/Users/mot/opt/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py”, line 578, in check_array allow_nan=force_all_finite == ‘allow-nan’)
File “/Users/mot/opt/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py”, line 60, in _assert_all_finite msg_dtype if msg_dtype is not None else X.dtype)
ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’).
I explored the time series for all the voxels inside the ROIs with NaN time series to be sure that all the voxels are not NaN, and there are only few voxels missing (e.g. 10 over 112 in one ROI).
My question is: For these regions with some missing voxels, there is an option using nilearn to avoid the missing values and to calculate the mean time series within the ROI with the remaining voxels? Therefore I can have the time series for all ROIs and calculate the correlation matrix with 400 regions for all the participants.
As I am not expert in python, I explored the options in nilearn but I did not find any appropriate option.
Any suggestion? Thanks a lot!
I am using the following code:
atlas_filename = ‘/Users/mot/Desktop/PhD/data_mdl_RS/Schaefer400.nii’
fmri_filename = ‘/Users/mot/Desktop/PhD/data_mdl_RS/wdn_ts_OC_S21.nii’
masker = NiftiLabelsMasker (labels_img = atlas_filename)
time_series = masker.fit_transform (fmri_filename)
correlation_measure = ConnectivityMeasure (kind=‘correlation’)
correlation_matrix = correlation_measure.fit_transform([time_series])
Marcela