Python Library to Read and Write Surface Files in Freesurfer's TriangularSurface Format
Project description
Python Library to Read and Write Surface Files in Freesurfer’s TriangularSurface Format
Freesurfer https://surfer.nmr.mgh.harvard.edu/
Install
pip3 install --user freesurfer-surface
Usage
Edit Surface File
from freesurfer_surface import Surface, Vertex, Triangle
surface = Surface.read_triangular('bert/surf/lh.pial'))
vertex_a = surface.add_vertex(Vertex(0.0, 0.0, 0.0))
vertex_b = surface.add_vertex(Vertex(1.0, 1.0, 1.0))
vertex_c = surface.add_vertex(Vertex(2.0, 2.0, 2.0))
surface.triangles.append(Triangle((vertex_a, vertex_b, vertex_c)))
surface.write_triangular('somewhere/else/lh.pial')
List Labels in Annotation File
from freesurfer_surface import Annotation
annotation = Annotation.read('tests/subjects/fabian/label/lh.aparc.annot')
for label in annotation.labels.values():
print(label.index, label.hex_color_code, label.name)
or
$ freesurfer-annotation-labels tests/subjects/fabian/label/lh.aparc.annot
index color name
0 #190519 unknown
1 #196428 bankssts
2 #7d64a0 caudalanteriorcingulate
3 #641900 caudalmiddlefrontal
...
33 #4614aa temporalpole
34 #9696c8 transversetemporal
35 #ffc020 insula
Find Border of Labelled Region
from freesurfer_surface import Surface
surface = Surface.read_triangular('bert/surf/lh.pial'))
surface.load_annotation_file('bert/label/lh.aparc.annot')
region, = filter(lambda l: l.name == 'precentral',
annotation.labels.values())
print(surface.find_label_border_polygonal_chains(region))
Tests
pip3 install --user pipenv
git clone https://github.com/fphammerle/freesurfer-surface.git
cd freesurfer-surface
pipenv run pylint freesurfer_surface
pipenv run pytest --cov=freesurfer_surface
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for freesurfer_surface-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 751aea631fec54ae7515c3dc1fa57ef7dc6afa66cf5e02950ea7713332a56886 |
|
MD5 | f22c66a82fe6e5ae9befe582af37e245 |
|
BLAKE2b-256 | 8bb00bca6f6456fc4ef2369952d4ae0afdc59644061135adbf24d82d8881fc66 |