test_annotation.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # freesurfer-surface - Read and Write Surface Files in Freesurfer’s TriangularSurface Format
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. from conftest import ANNOTATION_FILE_PATH
  18. from freesurfer_surface import Annotation
  19. def test_load_annotation():
  20. annotation = Annotation.read(ANNOTATION_FILE_PATH)
  21. assert len(annotation.vertex_label_index) == 155622
  22. assert annotation.vertex_label_index[64290] == 22
  23. assert annotation.vertex_label_index[72160] == 22
  24. assert annotation.vertex_label_index[84028] == 24
  25. assert annotation.vertex_label_index[97356] == 24
  26. assert annotation.vertex_label_index[123173] == 27
  27. assert annotation.vertex_label_index[140727] == 27
  28. assert annotation.vertex_label_index[93859] == 28
  29. assert annotation.vertex_label_index[78572] == 0
  30. assert annotation.vertex_label_index[120377] == 0
  31. assert (
  32. annotation.colortable_path == b"/autofs/space/tanha_002/users/greve"
  33. b"/fsdev.build/average/colortable_desikan_killiany.txt"
  34. )
  35. assert len(annotation.labels) == 36
  36. assert vars(annotation.labels[0]) == {
  37. "index": 0,
  38. "name": "unknown",
  39. "red": 25,
  40. "green": 5,
  41. "blue": 25,
  42. "transparency": 0,
  43. }
  44. assert vars(annotation.labels[28]) == {
  45. "index": 28,
  46. "name": "superiorfrontal",
  47. "red": 20,
  48. "green": 220,
  49. "blue": 160,
  50. "transparency": 0,
  51. }
  52. (precentral,) = filter(lambda l: l.name == "precentral", annotation.labels.values())
  53. (postcentral,) = filter(
  54. lambda l: l.name == "postcentral", annotation.labels.values()
  55. )
  56. assert vars(precentral) == {
  57. "index": 24,
  58. "name": "precentral",
  59. "red": 60,
  60. "green": 20,
  61. "blue": 220,
  62. "transparency": 0,
  63. }
  64. assert vars(postcentral) == {
  65. "index": 22,
  66. "name": "postcentral",
  67. "red": 220,
  68. "green": 20,
  69. "blue": 20,
  70. "transparency": 0,
  71. }
  72. (superiorfrontal,) = filter(
  73. lambda l: l.color_code == 10542100, annotation.labels.values()
  74. )
  75. assert superiorfrontal.name == "superiorfrontal"