.. _sphx_glr_auto_examples_03_connectivity_plot_ica.py: ICA on mouse ============ Independent components analysis on 5 mice. Retrieve the fMRI data ---------------------- .. code-block:: python from sammba import data_fetchers retest = data_fetchers.fetch_zurich_test_retest(subjects=range(5), correct_headers=True) Load the template and its brain mask ------------------------------------ .. code-block:: python dorr = data_fetchers.fetch_atlas_dorr_2008(downsample='100') dorr_masks = data_fetchers.fetch_masks_dorr_2008(downsample='100') print('Path to template is {} and to the brain mask is {}'.format(dorr.t2, dorr_masks.brain)) .. rst-class:: sphx-glr-script-out Out:: Path to template is /home/salma/nilearn_data/dorr_2008/Dorr_2008_average_100um.nii.gz and to the brain mask is /home/salma/nilearn_data/dorr_2008/dorr_2008_brain_mask_100.nii.gz Register to the template ------------------------ .. code-block:: python import os from sammba.registration import TemplateRegistrator registrator = TemplateRegistrator(brain_volume=400, caching=True, template=dorr.t2, use_rats_tool=False, template_brain_mask=dorr_masks.brain, registration_kind='affine') registered_funcs = [] for anat, func in zip(retest.anat, retest.func): animal_id = os.path.basename(os.path.dirname(anat)) registrator.output_dir = os.path.join('ica', animal_id) registrator.fit_anat(anat) registrator.fit_modality(func, 'func', t_r=1., voxel_size=(.3, .3, .3), prior_rigid_body_registration=True) registered_funcs.append(registrator.registered_func_) Run ICA ------- .. code-block:: python from nilearn.decomposition import CanICA canica = CanICA(n_components=30, smoothing_fwhm=.3, n_jobs=-1) canica.fit(registered_funcs) Retrieve the independent components in brain space. .. code-block:: python components_img = canica.masker_.inverse_transform(canica.components_) Visualize the components ------------------------ We can plot the outline of all components on one figure. .. code-block:: python from nilearn import plotting plotting.plot_prob_atlas(components_img, bg_img=registrator.template_brain_, display_mode='z', title='All ICA components') .. image:: /auto_examples/03_connectivity/images/sphx_glr_plot_ica_001.png :align: center **Total running time of the script:** ( 8 minutes 31.678 seconds) .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: plot_ica.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_ica.ipynb ` .. rst-class:: sphx-glr-signature `Generated by Sphinx-Gallery `_