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
Read Surface File
from freesurfer_surface import Surface
surface = Surface.read_triangular('bert/surf/lh.pial')
for vertex in surface.vertices[:3]:
print(vertex)
vertex_0 = surface.vertices[0]
print('coordinates of vertex #0:', (vertex_0.right, vertex_0.anterior, vertex_0.superior))
for triangle_index, triangle in enumerate(surface.triangles[:4]):
print('\ntriangle #{}:'.format(triangle_index))
print('vertex indices:', triangle.vertex_indices)
print('vertex coordinates:')
for vertex in surface.select_vertices(triangle.vertex_indices):
print((vertex.right, vertex.anterior, vertex.superior))
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
File details
Details for the file freesurfer-surface-1.1.1.tar.gz
.
File metadata
- Download URL: freesurfer-surface-1.1.1.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2db832255c449c535b46d78c8b2530e4e1ee6f8734a0cd05e9fa9d2962082c06 |
|
MD5 | 0375c0acd5e4eb54917697511f6c5630 |
|
BLAKE2b-256 | fd840988a46242e8c6ccc7798896bc14d9d134fc3664138ab8e4d6e0bca9577a |
Provenance
File details
Details for the file freesurfer_surface-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: freesurfer_surface-1.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3dae269f6e88d3f5f27d745e416b50a95d4f43f0c51cb92e75f34d5dbc5f7fe |
|
MD5 | 33959eb344f15cb78816366ac00f328b |
|
BLAKE2b-256 | 23d9ebaf458d4e82e88e9fe79b28612a3d58019a0ae6ee439dd7697abebfb009 |