.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_DataOperations/plot_neurovault_io.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 .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_01_DataOperations_plot_neurovault_io.py: Neurovault I/O ============== Data can be easily downloaded and uploaded to `neurovault `_ using `pynv `_, a python wrapper for the neurovault api. .. GENERATED FROM PYTHON SOURCE LINES 12-20 Download a Collection --------------------- Entire collections from neurovault can be downloaded along with the accompanying image metadata. You just need to know the collection ID. Data will be downloaded to the path specified in the 'data_dir' flag or '~/nilearn_data' by default. These files can then be imported into nltools as a Brain_Data() instance. .. GENERATED FROM PYTHON SOURCE LINES 20-27 .. code-block:: default from nltools.datasets import download_collection from nltools.data import Brain_Data metadata,files = download_collection(collection=2099) mask = Brain_Data(files,X=metadata) .. rst-class:: sphx-glr-script-out .. code-block:: none Dataset created in /home/runner/nilearn_data/2099 Downloading data from http://neurovault.org/media/images/2099/Neurosynth%20Parcellation_0.nii.gz ... ...done. (0 seconds, 0 min) Downloading data from http://neurovault.org/media/images/2099/Neurosynth%20Parcellation_1.nii.gz ... ...done. (0 seconds, 0 min) Downloading data from http://neurovault.org/media/images/2099/Neurosynth%20Parcellation_2.nii.gz ... ...done. (0 seconds, 0 min) .. GENERATED FROM PYTHON SOURCE LINES 28-36 Download a Single Image from the Web ------------------------------------ It's possible to load a single image from a web URL using the Brain_Data load method. The files are downloaded to a temporary directory and will eventually be erased by your computer so be sure to write it out to a file if you would like to save it. Here we plot it using nilearn's glass brain function. .. GENERATED FROM PYTHON SOURCE LINES 36-43 .. code-block:: default from nilearn.plotting import plot_glass_brain mask = Brain_Data('http://neurovault.org/media/images/2099/Neurosynth%20Parcellation_0.nii.gz') plot_glass_brain(mask.to_nifti()) .. image-sg:: /auto_examples/01_DataOperations/images/sphx_glr_plot_neurovault_io_001.png :alt: plot neurovault io :srcset: /auto_examples/01_DataOperations/images/sphx_glr_plot_neurovault_io_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-53 Upload Data to Neurovault ------------------------- There is a method to easily upload a Brain_Data() instance to `neurovault `_. This requires using your api key, which can be found under your account settings. Anything stored in data.X will be uploaded as image metadata. The required fields include collection_name, the img_type, img_modality, and analysis_level. See https://github.com/neurolearn/pyneurovault_upload for additional information about the required fields. (Don't forget to uncomment the line!) .. GENERATED FROM PYTHON SOURCE LINES 53-59 .. code-block:: default api_key = 'your_neurovault_api_key' # mask.upload_neurovault(access_token=api_key, collection_name='Neurosynth Parcellation', # img_type='Pa', img_modality='Other',analysis_level='M') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.543 seconds) .. _sphx_glr_download_auto_examples_01_DataOperations_plot_neurovault_io.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_neurovault_io.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_neurovault_io.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_