README.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. Read Surface File
  23. ~~~~~~~~~~~~~~~~~
  24. .. code:: python
  25. from freesurfer_surface import Surface
  26. surface = Surface.read_triangular('bert/surf/lh.pial')
  27. for vertex in surface.vertices[:3]:
  28. print(vertex)
  29. vertex_0 = surface.vertices[0]
  30. print('coordinates of vertex #0:', (vertex_0.right, vertex_0.anterior, vertex_0.superior))
  31. for triangle_index, triangle in enumerate(surface.triangles[:4]):
  32. print('\ntriangle #{}:'.format(triangle_index))
  33. print('vertex indices:', triangle.vertex_indices)
  34. print('vertex coordinates:')
  35. for vertex in surface.select_vertices(triangle.vertex_indices):
  36. print((vertex.right, vertex.anterior, vertex.superior))
  37. Edit Surface File
  38. ~~~~~~~~~~~~~~~~~
  39. .. code:: python
  40. from freesurfer_surface import Surface, Vertex, Triangle
  41. surface = Surface.read_triangular('bert/surf/lh.pial'))
  42. vertex_a = surface.add_vertex(Vertex(0.0, 0.0, 0.0))
  43. vertex_b = surface.add_vertex(Vertex(1.0, 1.0, 1.0))
  44. vertex_c = surface.add_vertex(Vertex(2.0, 2.0, 2.0))
  45. surface.triangles.append(Triangle((vertex_a, vertex_b, vertex_c)))
  46. surface.write_triangular('somewhere/else/lh.pial')
  47. List Labels in Annotation File
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. .. code:: python
  50. from freesurfer_surface import Annotation
  51. annotation = Annotation.read('tests/subjects/fabian/label/lh.aparc.annot')
  52. for label in annotation.labels.values():
  53. print(label.index, label.hex_color_code, label.name)
  54. or
  55. .. code:: sh
  56. $ freesurfer-annotation-labels tests/subjects/fabian/label/lh.aparc.annot
  57. index color name
  58. 0 #190519 unknown
  59. 1 #196428 bankssts
  60. 2 #7d64a0 caudalanteriorcingulate
  61. 3 #641900 caudalmiddlefrontal
  62. ...
  63. 33 #4614aa temporalpole
  64. 34 #9696c8 transversetemporal
  65. 35 #ffc020 insula
  66. Find Border of Labelled Region
  67. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. .. code:: python
  69. from freesurfer_surface import Surface
  70. surface = Surface.read_triangular('bert/surf/lh.pial'))
  71. surface.load_annotation_file('bert/label/lh.aparc.annot')
  72. region, = filter(lambda l: l.name == 'precentral',
  73. annotation.labels.values())
  74. print(surface.find_label_border_polygonal_chains(region))
  75. Tests
  76. -----
  77. .. code:: sh
  78. pip3 install --user pipenv
  79. git clone https://github.com/fphammerle/freesurfer-surface.git
  80. cd freesurfer-surface
  81. pipenv run pylint freesurfer_surface
  82. pipenv run pytest --cov=freesurfer_surface