Skip to main content

For calculating exact geodesic distances on cortical surface meshes

Project description

surfdist

Build Status

Calculate the exact geodesic distance on a triangular surface mesh using the gdist package, which is based on the c++ library.

Installation

pip install surfdist

Example

import nibabel as nib
import numpy as np
import matplotlib.pyplot as plt
import os
import surfdist as sd
from surfdist import viz, load, utils, surfdist

# calculate and display distance from central sulcus at each node:
cmap='coolwarm'
base_dir = '/Applications/freesurfer/subjects/'
surf = nib.freesurfer.read_geometry(os.path.join(base_dir, 'bert/surf/lh.pial'))
cort = np.sort(nib.freesurfer.read_label(os.path.join(base_dir, 'bert/label/lh.cortex.label')))
sulc=nib.freesurfer.read_morph_data(os.path.join(base_dir, 'bert/surf/lh.sulc'))

# load central sulcus nodes
src  = sd.load.load_freesurfer_label(os.path.join(base_dir, 'bert/label/lh.aparc.a2009s.annot'), 'S_central', cort)

# calculate distance
dist = sd.surfdist.dist_calc(surf, cort, src)

# visualize
plot_med = sd.viz.viz(surf[0], surf[1], dist, bg_map=sulc, bg_on_stat=True, cmap=cmap)
plot_lat = sd.viz.viz(surf[0], surf[1], dist, azim=180, bg_map=sulc, bg_on_stat=True, cmap=cmap)

# Calculate distances on native surface and display on fsaverage
fsa4 = nib.freesurfer.read_geometry(os.path.join(base_dir,'fsaverage4/surf/lh.sphere.reg'))[0]
fsa4_sulc=nib.freesurfer.read_morph_data(os.path.join(base_dir, 'fsaverage4/surf/lh.sulc'))
native = nib.freesurfer.read_geometry(os.path.join(base_dir, 'bert/surf/lh.sphere.reg'))[0]
idx_fsa4_to_native = sd.utils.find_node_match(fsa4, native)[0]

surf_fsa4 = nib.freesurfer.read_geometry(os.path.join(base_dir, 'fsaverage4/surf/lh.pial'))
plot_fsa4_med = sd.viz.viz(surf_fsa4[0], surf_fsa4[1], dist[idx_fsa4_to_native], bg_map=fsa4_sulc, bg_on_stat=True, cmap=cmap)
plot_fsa4_lat = sd.viz.viz(surf_fsa4[0], surf_fsa4[1], dist[idx_fsa4_to_native], azim=180, bg_map=fsa4_sulc, bg_on_stat=True, cmap=cmap)

plt.show()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

surfdist-0.15.4.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

surfdist-0.15.4-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file surfdist-0.15.4.tar.gz.

File metadata

  • Download URL: surfdist-0.15.4.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

File hashes

Hashes for surfdist-0.15.4.tar.gz
Algorithm Hash digest
SHA256 dc3d7c170ba2c922b60a92823579e62dc20ea29c549b433a29836a5d05c2aa1b
MD5 c17014066cc88d3969f2c1ae831e1d77
BLAKE2b-256 4d237e81ab7973b7798060f9a53c042fb64cc3d0bccb4be43f87317812c89c43

See more details on using hashes here.

File details

Details for the file surfdist-0.15.4-py3-none-any.whl.

File metadata

  • Download URL: surfdist-0.15.4-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

File hashes

Hashes for surfdist-0.15.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f152df149b481274c0adb651318f691f8182ecadfa0b59ef7f8d2009845d966a
MD5 fdac083fa0be0ce92ec0acdb490b86f1
BLAKE2b-256 5b245026082a941242c452a374848fd272d9ee612a170f1963ebfd761e8bb275

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page