.. 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_path.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_surface_analyses_plot_geodesic_path.py: ======================= Plotting Geodesic Paths ======================= This will plot a geodesic path between two vertices on the cortical surface. This path is based on geodesic distances across the surface. The path starts at the given endpoint and selects the neighbor of that point in the surface map that is closest to the other endpoint. This process continues iteratilvely until the last vertex in the path is the endpoint you gave to it. All you need to do is supply a surface object and two vertices on that surface and you can find the geodesic path. This script additionally makes a plot to show all of the vertices listed in the path. .. GENERATED FROM PYTHON SOURCE LINES 16-45 .. image-sg:: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_path_001.png :alt: plot geodesic path :srcset: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_path_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /opt/hostedtoolcache/Python/3.9.12/x64/lib/python3.9/site-packages/scipy/sparse/linalg/_dsolve/linsolve.py:322: SparseEfficiencyWarning: splu requires CSC matrix format warn('splu requires CSC matrix format', SparseEfficiencyWarning) Failed to get connection ** (inkscape:5462): CRITICAL **: 01:32:15.597: dbus_g_proxy_new_for_name: assertion 'connection != NULL' failed ** (inkscape:5462): CRITICAL **: 01:32:15.597: dbus_g_proxy_call: assertion 'DBUS_IS_G_PROXY (proxy)' failed ** (inkscape:5462): CRITICAL **: 01:32:15.597: dbus_g_connection_register_g_object: assertion 'connection != NULL' failed | .. code-block:: default 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")] numl = surfs[0].pts.shape[0] # Now we need to pick the start and end points of the line we will draw pt_a = 100 pt_b = 50000 # Then we find the geodesic path between these points path = surfs[0].geodesic_path(pt_a, pt_b) # In order to plot this on the cortical surface, we need an array that is the # same size as the number of vertices in the left hemisphere path_data = np.zeros(numl) for v in path: path_data[v] = 1 # And now plot these distances onto the cortical surface path_verts = cortex.Vertex(path_data, subject, cmap="Blues_r") cortex.quickshow(path_verts, with_colorbar=False) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.814 seconds) .. _sphx_glr_download_auto_examples_surface_analyses_plot_geodesic_path.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_geodesic_path.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_geodesic_path.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_