README.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. freesurfer-surface
  2. ==================
  3. .. image:: https://travis-ci.org/fphammerle/freesurfer-surface.svg?branch=master
  4. :target: https://travis-ci.org/fphammerle/freesurfer-surface
  5. .. image:: https://coveralls.io/repos/github/fphammerle/freesurfer-surface/badge.svg?branch=master
  6. :target: https://coveralls.io/github/fphammerle/freesurfer-surface?branch=master
  7. .. image:: https://img.shields.io/pypi/v/freesurfer-surface.svg
  8. :target: https://pypi.org/project/freesurfer-surface/#history
  9. .. image:: https://img.shields.io/pypi/pyversions/freesurfer-surface.svg
  10. :target: https://pypi.org/project/freesurfer-surface/
  11. .. image:: https://zenodo.org/badge/185943856.svg
  12. :target: https://zenodo.org/badge/latestdoi/185943856
  13. Python Library to Read and Write Surface Files in Freesurfer’s
  14. TriangularSurface Format
  15. Freesurfer https://surfer.nmr.mgh.harvard.edu/
  16. Install
  17. -------
  18. .. code:: sh
  19. pip3 install --user freesurfer-surface
  20. Usage
  21. -----
  22. Edit Surface File
  23. ~~~~~~~~~~~~~~~~~
  24. .. code:: python
  25. from freesurfer_surface import Surface, Vertex, Triangle
  26. surface = Surface.read_triangular('bert/surf/lh.pial'))
  27. vertex_a = surface.add_vertex(Vertex(0.0, 0.0, 0.0))
  28. vertex_b = surface.add_vertex(Vertex(1.0, 1.0, 1.0))
  29. vertex_c = surface.add_vertex(Vertex(2.0, 2.0, 2.0))
  30. surface.triangles.append(Triangle((vertex_a, vertex_b, vertex_c)))
  31. surface.write_triangular('somewhere/else/lh.pial')
  32. List Labels in Annotation File
  33. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. .. code:: python
  35. from freesurfer_surface import Annotation
  36. annotation = Annotation.read('tests/subjects/fabian/label/lh.aparc.annot')
  37. for label in annotation.labels.values():
  38. print(label.index, label.hex_color_code, label.name)
  39. or
  40. .. code:: sh
  41. $ freesurfer-annotation-labels tests/subjects/fabian/label/lh.aparc.annot
  42. index color name
  43. 0 #190519 unknown
  44. 1 #196428 bankssts
  45. 2 #7d64a0 caudalanteriorcingulate
  46. 3 #641900 caudalmiddlefrontal
  47. ...
  48. 33 #4614aa temporalpole
  49. 34 #9696c8 transversetemporal
  50. 35 #ffc020 insula
  51. Find Border of Labelled Region
  52. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. .. code:: python
  54. from freesurfer_surface import Surface
  55. surface = Surface.read_triangular('bert/surf/lh.pial'))
  56. surface.load_annotation_file('bert/label/lh.aparc.annot')
  57. region, = filter(lambda l: l.name == 'precentral',
  58. annotation.labels.values())
  59. print(surface.find_label_border_polygonal_chains(region))
  60. Tests
  61. -----
  62. .. code:: sh
  63. pip3 install --user pipenv
  64. git clone https://github.com/fphammerle/freesurfer-surface.git
  65. cd freesurfer-surface
  66. pipenv run pylint freesurfer_surface
  67. pipenv run pytest --cov=freesurfer_surface