.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/hcp/plot_hcp_fs_lr.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_hcp_plot_hcp_fs_lr.py: ================================================================== Visualize HCP fs_LR data on the HCP template and on fsaverage ================================================================== This example shows how to: a) visualize data defined on the HCP fs_LR 32k surface directly on the HCP template (the ``32k_fs_LR`` pycortex subject), and b) resample that data to fsaverage6 with :mod:`cortex.hcp` and visualize it as a flatmap. Both steps produce a flatmap. Notes ----- * The first time you run this, the ``32k_fs_LR`` and ``fsaverage`` subjects are downloaded into your pycortex filestore. * The resampling matrix is built from the HCP standard-mesh spheres, which are downloaded on demand (no Connectome Workbench needed). * fsaverage6 is not itself a renderable pycortex subject, so the fsaverage6 result is upsampled to the full ``fsaverage`` surface for display using :func:`cortex.freesurfer.upsample_to_fsaverage`. The fsaverage5/6 upsampling tables ship with pycortex, so no FreeSurfer installation is needed. .. GENERATED FROM PYTHON SOURCE LINES 27-78 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/hcp/images/sphx_glr_plot_hcp_fs_lr_001.png :alt: HCP fs_LR 32k (native) :srcset: /auto_examples/hcp/images/sphx_glr_plot_hcp_fs_lr_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/hcp/images/sphx_glr_plot_hcp_fs_lr_002.png :alt: Resampled to fsaverage6 (shown on fsaverage) :srcset: /auto_examples/hcp/images/sphx_glr_plot_hcp_fs_lr_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading from: https://ndownloader.figshare.com/files/66442049 Downloading subject 32k_fs_LR to /tmp/tmpiv2uan66 Done downloading to /tmp/tmpiv2uan66/32k_fs_LR.tar.gz Extracting subject 32k_fs_LR to /home/runner/work/pycortex/pycortex/filestore/db Generating a flatmap cache fsaverage6 data shape: (81924,) Downloading from: https://ndownloader.figshare.com/files/17827577?private_link=4871247dce31e188e758 Downloading subject fsaverage to /tmp/tmpqarb9ukr Done downloading to /tmp/tmpqarb9ukr/fsaverage.tar.gz Extracting subject fsaverage to /home/runner/work/pycortex/pycortex/filestore/db Generating a flatmap cache | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import cortex import cortex.hcp # --------------------------------------------------------------------------- # a) Visualize data on the HCP fs_LR 32k template # --------------------------------------------------------------------------- hcp_subject = "32k_fs_LR" # Make sure the HCP template is in the pycortex filestore, downloading if not. if hcp_subject not in cortex.db.subjects: cortex.hcp.download_fs_lr() # Create some smooth demo data on the full fs_LR 32k surface (64984 vertices, # both hemispheres, medial wall included). Here we use the anterior-posterior # (y) coordinate of the inflated surface as a smooth gradient. For real HCP # data stored as CIFTI grayordinates, expand it to the full surface first with # ``cortex.hcp.cifti_to_surface`` (or go straight to fsaverage with # ``cortex.hcp.to_fsaverage``). pts, _ = cortex.db.get_surf(hcp_subject, "inflated", merge=True) data_fslr = pts[:, 1].astype(float) vmin, vmax = np.percentile(data_fslr, [1, 99]) # Visualize on the HCP template just like any other vertex dataset. vtx_hcp = cortex.Vertex(data_fslr, hcp_subject, vmin=vmin, vmax=vmax, cmap="turbo") cortex.quickshow(vtx_hcp, with_curvature=True, with_rois=False, with_labels=False) plt.gcf().suptitle("HCP fs_LR 32k (native)") # --------------------------------------------------------------------------- # b) Resample the same data to fsaverage6 and visualize it # --------------------------------------------------------------------------- # Project fs_LR 32k -> fsaverage6 (81924 vertices, both hemispheres). data_fs6 = cortex.hcp.project_fslr_to_fsaverage(data_fslr, target="fsaverage6") print("fsaverage6 data shape:", data_fs6.shape) # fsaverage6 is not a renderable pycortex subject, so upsample the fsaverage6 # result to the full fsaverage surface for the flatmap. if "fsaverage" not in cortex.db.subjects: cortex.download_subject("fsaverage") data_fs = cortex.freesurfer.upsample_to_fsaverage(np.nan_to_num(data_fs6), "fsaverage6") vtx_fs = cortex.Vertex(data_fs, "fsaverage", vmin=vmin, vmax=vmax, cmap="turbo") cortex.quickshow(vtx_fs, with_curvature=True, with_rois=False, with_labels=False) plt.gcf().suptitle("Resampled to fsaverage6 (shown on fsaverage)") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 27.056 seconds) .. _sphx_glr_download_auto_examples_hcp_plot_hcp_fs_lr.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hcp_fs_lr.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hcp_fs_lr.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_hcp_fs_lr.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_