README.rst 3.3 KB

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