def test_plot_stat_map_with_nans(): img = _generate_img() data = img.get_data() data[6, 5, 1] = np.nan data[1, 5, 2] = np.nan data[1, 3, 2] = np.nan data[6, 5, 2] = np.inf img = nibabel.Nifti1Image(data, mni_affine) plot_epi(img) plot_stat_map(img) plot_glass_brain(img)
def test_plot_stat_map_with_nans(testdata_3d): img = testdata_3d['img'] data = get_data(img) data[6, 5, 1] = np.nan data[1, 5, 2] = np.nan data[1, 3, 2] = np.nan data[6, 5, 2] = np.inf img = nibabel.Nifti1Image(data, mni_affine) plot_epi(img) plot_stat_map(img) plot_glass_brain(img)
### Fetch data ################################################################ from nilearn import datasets from nilearn.image.image import mean_img from nilearn.plotting.img_plotting import plot_epi, plot_roi haxby_files = datasets.fetch_haxby(n_subjects=1) ### Visualization ############################################################# import matplotlib.pyplot as plt # Compute the mean EPI: we do the mean along the axis 3, which is time mean_haxby = mean_img(haxby_files.func) plot_epi(mean_haxby) ### Extracting a brain mask ################################################### # Simple computation of a mask from the fMRI data from nilearn.masking import compute_epi_mask mask_img = compute_epi_mask(haxby_files.func[0]) plot_roi(mask_img, mean_haxby) ### Applying the mask ######################################################### from nilearn.masking import apply_mask masked_data = apply_mask(haxby_files.func[0], mask_img) # masked_data shape is (timepoints, voxels). We can plot the first 150
import matplotlib.pyplot as plt mean_func_img = mean_img(func_filename) # common cut coordinates for all plots first_plot = plot_roi(labels_img, mean_func_img, title="Ward parcellation", display_mode='xz') # labels_img is a Nifti1Image object, it can be saved to file with the # following code: labels_img.to_filename('parcellation.nii') # Display the original data plot_epi(nifti_masker.inverse_transform(fmri_masked[0]), cut_coords=first_plot.cut_coords, title='Original (%i voxels)' % fmri_masked.shape[1], display_mode='xz') # A reduced data can be create by taking the parcel-level average: # Note that, as many objects in the scikit-learn, the ward object exposes # a transform method that modifies input features. Here it reduces their # dimension fmri_reduced = ward.transform(fmri_masked) # Display the corresponding data compressed using the parcellation fmri_compressed = ward.inverse_transform(fmri_reduced) compressed_img = nifti_masker.inverse_transform(fmri_compressed[0]) plot_epi(compressed_img, cut_coords=first_plot.cut_coords, title='Compressed representation (2000 parcels)',
from nilearn.image import mean_img import matplotlib.pyplot as plt mean_func_img = mean_img(dataset.func[0]) # common cut coordinates for all plots first_plot = plot_roi(labels_img, mean_func_img, title="Ward parcellation", display_mode='xz') # labels_img is a Nifti1Image object, it can be saved to file with the # following code: labels_img.to_filename('parcellation.nii') # Display the original data plot_epi(nifti_masker.inverse_transform(fmri_masked[0]), cut_coords=first_plot.cut_coords, title='Original (%i voxels)' % fmri_masked.shape[1], display_mode='xz') # A reduced data can be create by taking the parcel-level average: # Note that, as many objects in the scikit-learn, the ward object exposes # a transform method that modifies input features. Here it reduces their # dimension fmri_reduced = ward.transform(fmri_masked) # Display the corresponding data compressed using the parcellation fmri_compressed = ward.inverse_transform(fmri_reduced) compressed_img = nifti_masker.inverse_transform(fmri_compressed[0]) plot_epi(compressed_img, cut_coords=first_plot.cut_coords, title='Compressed representation (2000 parcels)', display_mode='xz')
# print basic information on the dataset print('First anatomical nifti image (3D) located is at: %s' % haxby_dataset.anat[0]) print('First functional nifti image (4D) is located at: %s' % haxby_dataset.func[0]) ### Visualization ############################################################# import matplotlib.pyplot as plt # Compute the mean EPI: we do the mean along the axis 3, which is time func_filename = haxby_dataset.func[0] mean_haxby = mean_img(func_filename) plot_epi(mean_haxby) ### Extracting a brain mask ################################################### # Simple computation of a mask from the fMRI data from nilearn.masking import compute_epi_mask mask_img = compute_epi_mask(func_filename) plot_roi(mask_img, mean_haxby) ### Applying the mask ######################################################### from nilearn.masking import apply_mask masked_data = apply_mask(func_filename, mask_img) # masked_data shape is (timepoints, voxels). We can plot the first 150