.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/surface_analyses/plot_geodesic_distance.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_surface_analyses_plot_geodesic_distance.py: =========================== Plotting Geodesic Distances =========================== This plots the distances (in mm) between a vertex or set of vertices and all other vertices on a surface. These two operations take the exact same amount of time to run. To look at the distance to a single point, just supply the index of that vertex. To look at the distance to a set of points, supply a numpy array of all of the vertices in the area. In the case of a set of points, the geodesic distance measure will return the minimum distance to the set of points as a whole. The two hemispheres must be run separately. .. GENERATED FROM PYTHON SOURCE LINES 18-56 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_distance_001.png :alt: plot geodesic distance :srcset: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_distance_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_distance_002.png :alt: plot geodesic distance :srcset: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_distance_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none ** (inkscape:5101): WARNING **: 21:56:21.288: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function. ** (inkscape:5114): WARNING **: 21:56:25.504: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function. | .. code-block:: Python import cortex import cortex.polyutils import numpy as np import matplotlib.pyplot as plt subject = "S1" # First we need to import the surfaces for this subject surfs = [cortex.polyutils.Surface(*d) for d in cortex.db.get_surf(subject, "fiducial")] # Then we will pick one vertex in each hemisphere to find distances to vert = 10000 dists = [s.geodesic_distance(vert) for s in surfs] # Now we can plot these distances onto a flatmap all_dists = np.hstack((dists[0], dists[1])) dist_map = cortex.Vertex(all_dists, subject, cmap="hot") cortex.quickshow(dist_map) plt.show() # Alternatively, you can find the minimum distance from a set of points to the # surface # Here, we use an example of an ROI all_eba = cortex.utils.get_roi_verts(subject, "EBA")["EBA"] # We have to then separate these vertices by hemisphere numl = surfs[0].pts.shape[0] eba_verts = [all_eba[all_eba < numl], all_eba[all_eba >= numl] - numl] # Now look at geodesic distances for each hemisphere separately dists = [s.geodesic_distance(verts) for s, verts in zip(surfs, eba_verts)] all_dists = np.hstack((dists[0], dists[1])) # And now plot these distances onto the cortical surface dist_map = cortex.Vertex(all_dists, subject, cmap="hot") cortex.quickshow(dist_map) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 13.402 seconds) .. _sphx_glr_download_auto_examples_surface_analyses_plot_geodesic_distance.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_geodesic_distance.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_geodesic_distance.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_geodesic_distance.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_