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(f'\ntriangle #{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
Metadata
Release files for freesurfer-surface 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| freesurfer-surface-2.0.0.tar.gz | 3.4 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| freesurfer_surface-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 3.5 MB
Release files / freesurfer-surface-2.0.0.tar.gz
| Download URL | freesurfer-surface-2.0.0.tar.gz |
|---|---|
| Size | 3.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57f9b5e986a0a2270a1140436764754a7338fc902c81c1cfe3abbb3470e9957a
|
|
BLAKE2b-256 checksum How to use checksums |
db2f06a0f2812b2894bd37094c8c2eefc7043dc504dcea78706509926f9a6493
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.4
|
Release files / freesurfer_surface-2.0.0-py3-none-any.whl
| Download URL | freesurfer_surface-2.0.0-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
57ad13e7ead5640fc309e1dff94c47d7d546b306edcd244d0232a46650e196b3
|
|
BLAKE2b-256 checksum How to use checksums |
916e83692c3af5d6421934d03703dbd1230e574474dafd1c7e30f46d4ad1f2db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.4
|