from nisl import io
masker = io.NiftiMasker(smooth=1.5)
data_masked = masker.fit_transform(dataset.func[0])
// Concatenate all the subjects
//fmri_data = np.concatenate(data_masked, axis=1)
fmri_data = data_masked
// Take the mean along axis 3: the direction of time
mean_img = masker.inverse_transform(fmri_data.mean(axis=-1))
////// Apply ICA //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
from sklearn.decomposition import FastICA
n_components = 20
ica = FastICA(n_components=n_components, random_state=42)
components_masked = ica.fit_transform(data_masked)
// We normalize the estimated components, for thresholding to make sens
components_masked -= components_masked.mean(axis=0)
components_masked /= components_masked.std(axis=0)
// Threshold
components_masked[np.abs(components_masked) < .5] = 0
// Now we inverting the masking operation, to go back to a full 3D
// representation
component_img = masker.inverse_transform(components_masked)components = component_img.get_data()
// Using a masked array is important to have transparency in the figures
components = np.ma.masked_equal(components, 0, copy=False)