Plot Vertex Data

This plots example vertex data onto an example subject, S1, onto a flatmap using quickflat. In order for this to run, you have to have a flatmap for this subject in the pycortex filestore.

The cortex.Vertex object is instantiated with a numpy array of the same size as the total number of vertices in that subject’s flatmap. Each pixel is colored according to the value given for the nearest vertex in the flatmap.

Instead of the random test data, you can replace this with any array that is the length of all of the vertices in the subject.

Additionally, if you create a Vertex object using only the number of vertices that exists in the left hemisphere of the brain, the right hemisphere is filled in with zeros.

  • plot vertex
  • plot vertex

Out:

Failed to get connection
** (inkscape:5153): CRITICAL **: 01:27:09.888: dbus_g_proxy_new_for_name: assertion 'connection != NULL' failed
** (inkscape:5153): CRITICAL **: 01:27:09.888: dbus_g_proxy_call: assertion 'DBUS_IS_G_PROXY (proxy)' failed
** (inkscape:5153): CRITICAL **: 01:27:09.888: dbus_g_connection_register_g_object: assertion 'connection != NULL' failed
Failed to get connection
** (inkscape:5156): CRITICAL **: 01:27:10.878: dbus_g_proxy_new_for_name: assertion 'connection != NULL' failed
** (inkscape:5156): CRITICAL **: 01:27:10.878: dbus_g_proxy_call: assertion 'DBUS_IS_G_PROXY (proxy)' failed
** (inkscape:5156): CRITICAL **: 01:27:10.878: dbus_g_connection_register_g_object: assertion 'connection != NULL' failed

import cortex
import cortex.polyutils
import numpy as np
np.random.seed(1234)
import matplotlib.pyplot as plt

subject = 'S1'

# In order to get the number of vertices in this subject's cortical surface
# we have to load in their surfaces and get the number of points in each
surfs = [cortex.polyutils.Surface(*d)
         for d in cortex.db.get_surf(subject, "fiducial")]

# This is the total number of vertices in both hemispheres combined
num_verts = surfs[0].pts.shape[0] + surfs[1].pts.shape[0]

# Creating a random dataset with one entry for each vertex
test_data = np.random.randn(num_verts)

# This creates a Vertex object for our subject and test dataset
vertex_data = cortex.Vertex(test_data, subject)
# And now we can display it on a flatmap
cortex.quickshow(vertex_data)
plt.show()

# We can also plot just the left hemisphere data
numl = surfs[0].pts.shape[0]
# This creates a Vertex object with an array only as long as the number of
# vertices in the left hemisphere, and the right hemisphere will be filled
# in with zeros
vertex_data_left = cortex.Vertex(test_data[:numl], subject)
cortex.quickshow(vertex_data_left)
plt.show()

Total running time of the script: ( 0 minutes 4.388 seconds)

Gallery generated by Sphinx-Gallery