.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_advanced/plot_neurovault_meta_analysis.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_07_advanced_plot_neurovault_meta_analysis.py: NeuroVault meta-analysis of stop-go paradigm studies ==================================================== This example shows how to download statistical maps from :term:`Neurovault`. See :func:`nilearn.datasets.fetch_neurovault_ids` documentation for more details. .. Original authors: - Ben Cipollini .. GENERATED FROM PYTHON SOURCE LINES 18-24 .. code-block:: Python import scipy from nilearn import plotting from nilearn.datasets import fetch_neurovault_ids from nilearn.image import get_data, load_img, math_img, new_img_like .. GENERATED FROM PYTHON SOURCE LINES 25-27 Fetch images for "successful stop minus go"-like protocols. ----------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-48 .. code-block:: Python # These are the images we are interested in, # in order to save time we specify their ids explicitly. stop_go_image_ids = (151, 3041, 3042, 2676, 2675, 2818, 2834) # These ids were determined by querying Neurovault like this: # from nilearn.datasets import fetch_neurovault, neurovault # # nv_data = fetch_neurovault( # max_images=7, # cognitive_paradigm_cogatlas=neurovault.Contains('stop signal'), # contrast_definition=neurovault.Contains('succ', 'stop', 'go'), # map_type='T map') # # print([meta['id'] for meta in nv_data['images_meta']]) nv_data = fetch_neurovault_ids(image_ids=stop_go_image_ids) images_meta = nv_data["images_meta"] .. rst-class:: sphx-glr-script-out .. code-block:: none Reading local neurovault data. Already fetched 1 image Already fetched 2 images Already fetched 3 images Already fetched 4 images Already fetched 5 images Already fetched 6 images Already fetched 7 images 7 images found on local disk. .. GENERATED FROM PYTHON SOURCE LINES 49-51 Visualize the data ------------------ .. GENERATED FROM PYTHON SOURCE LINES 51-60 .. code-block:: Python print("\nplotting glass brain for collected images\n") for im in images_meta: plotting.plot_glass_brain( im["absolute_path"], title=f"image {im['id']}: {im['contrast_definition']}", ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_001.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_002.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_003.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_004.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_004.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_005.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_006.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_006.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_007.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_007.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none plotting glass brain for collected images .. GENERATED FROM PYTHON SOURCE LINES 61-63 Compute statistics ------------------ .. GENERATED FROM PYTHON SOURCE LINES 63-98 .. code-block:: Python def t_to_z(t_scores, deg_of_freedom): """Convert t-scores to z-scores.""" p_values = scipy.stats.t.sf(t_scores, df=deg_of_freedom) z_values = scipy.stats.norm.isf(p_values) return z_values # Compute z values z_imgs = [] current_collection = None print("\nComputing maps...") # convert t to z for all images for this_meta in images_meta: if this_meta["collection_id"] != current_collection: print(f"\n\nCollection {this_meta['id']}:") current_collection = this_meta["collection_id"] # Load and validate the downloaded image. t_img = load_img(this_meta["absolute_path"]) deg_of_freedom = this_meta["number_of_subjects"] - 2 print( f" Image {this_meta['id']}: degrees of freedom: {deg_of_freedom}" ) # Convert data, create new image. z_img = new_img_like( t_img, t_to_z(get_data(t_img), deg_of_freedom=deg_of_freedom) ) z_imgs.append(z_img) .. rst-class:: sphx-glr-script-out .. code-block:: none Computing maps... Collection 2675: Image 2675: degrees of freedom: 6 Image 2676: degrees of freedom: 6 Collection 2834: Image 2834: degrees of freedom: 18 Image 2818: degrees of freedom: 18 Collection 151: Image 151: degrees of freedom: 13 Image 3041: degrees of freedom: 13 Collection 3042: Image 3042: degrees of freedom: 22 .. GENERATED FROM PYTHON SOURCE LINES 99-101 Plot the combined z maps ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 101-116 .. code-block:: Python cut_coords = [-15, -8, 6, 30, 46, 62] meta_analysis_img = math_img( "np.sum(z_imgs, axis=3) / np.sqrt(z_imgs.shape[3])", z_imgs=z_imgs ) plotting.plot_stat_map( meta_analysis_img, display_mode="z", threshold=6, cut_coords=cut_coords, vmax=12, ) plotting.show() .. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_008.png :alt: plot neurovault meta analysis :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_neurovault_meta_analysis_008.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 14.937 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_auto_examples_07_advanced_plot_neurovault_meta_analysis.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/nilearn/nilearn/0.10.4?urlpath=lab/tree/notebooks/auto_examples/07_advanced/plot_neurovault_meta_analysis.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_neurovault_meta_analysis.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_neurovault_meta_analysis.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_