{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Example 2: Plotting volumetric data\n\nThis example shows how to project data from a NIFTI volume onto a surface, and \nthen display the result. \n\nData is a Left vs Right hand localizer contrast (t-map) for a single subject \nof the Midnight Scan Club dataset [1]_. Data is obtained from \n[Neurovault](https://neurovault.org/images/47307/) via ``nilearn`` and then \nprojected from MNI152 coordinates to fsLR surfaces using ``neuromaps``. \n\n.. [1] Gordon EM, et al. 2017. Precision Functional Mapping of Individual Human Brains. Neuron. 95:791\u2013807.e7.\n \n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Code source: Dan Gale\n# License: BSD 3 clause\n\nfrom nilearn.datasets import fetch_neurovault_ids\nfrom nilearn.plotting.cm import _cmap_d as nilearn_cmaps\nfrom neuromaps.transforms import mni152_to_fslr\nfrom neuromaps.datasets import fetch_fslr\nfrom surfplot import Plot\nfrom surfplot.utils import threshold\n\ndata = fetch_neurovault_ids(image_ids=[47307], verbose=0)\nimg = data['images'][0]\n\n# project from MNI to fslr; GIFTI surfaces are returned \ngii_lh, gii_rh = mni152_to_fslr(img)\n\n# threshold after projection to avoid interpolation artefacts\ndata_lh = threshold(gii_lh.agg_data(), 3)\ndata_rh = threshold(gii_rh.agg_data(), 3)\n\n# get surfaces + sulc maps\nsurfaces = fetch_fslr()\nlh, rh = surfaces['inflated']\nsulc_lh, sulc_rh = surfaces['sulc']\n\np = Plot(lh, rh)\np.add_layer({'left': sulc_lh, 'right': sulc_rh}, cmap='binary_r', cbar=False)\n\n# cold_hot is a common diverging colormap for neuroimaging\ncmap = nilearn_cmaps['cold_hot']\np.add_layer({'left': data_lh, 'right': data_rh}, cmap=cmap, \n            color_range=(-11, 11))\n\n# make a nice vertical colorbar on the right side of the figure\nkws = dict(location='right', draw_border=False, aspect=10, shrink=.2, \n           decimals=0, pad=0)\nfig = p.build(cbar_kws=kws)\nfig.axes[0].set_title('MSC05 Left > Right Hand', pad=-3)\nfig.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}