Skip to main content

Python Library to Read and Write Surface Files in Freesurfer's TriangularSurface Format

Project description

https://travis-ci.org/fphammerle/freesurfer-surface.svg?branch=master https://coveralls.io/repos/github/fphammerle/freesurfer-surface/badge.svg?branch=master https://img.shields.io/pypi/v/freesurfer-surface.svg https://img.shields.io/pypi/pyversions/freesurfer-surface.svg https://zenodo.org/badge/185943856.svg

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


Download files

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

Source Distribution

freesurfer-surface-1.1.0.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

freesurfer_surface-1.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file freesurfer-surface-1.1.0.tar.gz.

File metadata

  • Download URL: freesurfer-surface-1.1.0.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.7

File hashes

Hashes for freesurfer-surface-1.1.0.tar.gz
Algorithm Hash digest
SHA256 02203b7d54a1aa191e489a178c50a76dd19d44f005b72171063daf4a39a82f04
MD5 1889791b44f1ce45ace018ab7986f271
BLAKE2b-256 509b1c9189c707ad1022819fadcaff81437dd92872fd489c29d91e0a6fb3246d

See more details on using hashes here.

Provenance

File details

Details for the file freesurfer_surface-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: freesurfer_surface-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.7

File hashes

Hashes for freesurfer_surface-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb4c0d9fb771ebdbe6723edada99c9409120ad8736390f34b9ea6093d51c0e9
MD5 04b642bfd1e76783cfe8dec7bf6f4eb1
BLAKE2b-256 31d68cb4fe71028726f912f1d1736a1082d7e6fb18ef9eb956f14ebca9f21445

See more details on using hashes here.

Provenance

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