test_cortical_parcellation_stats.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. """
  2. freesurfer-stats, a Python Library to Read FreeSurfer's Cortical Parcellation Anatomical Statistics
  3. Copyright (C) 2019 Fabian Peter Hammerle <fabian@hammerle.me>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. """
  15. import datetime
  16. import os
  17. import pandas.util.testing
  18. import pytest
  19. from conftest import SUBJECTS_DIR
  20. from freesurfer_stats import CorticalParcellationStats
  21. @pytest.mark.parametrize(
  22. ('path', 'headers', 'hemisphere',
  23. 'whole_brain_measurements', 'structural_measurements'),
  24. [(os.path.join(SUBJECTS_DIR, 'fabian', 'stats', 'lh.aparc.DKTatlas.stats.short'),
  25. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 5, 54, tzinfo=datetime.timezone.utc),
  26. 'generating_program': 'mris_anatomical_stats',
  27. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  28. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  29. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/lh.cortex.label'
  30. ' -f ../stats/lh.aparc.DKTatlas.stats -b -a ../label/lh.aparc.DKTatlas.annot'
  31. ' -c ../label/aparc.annot.DKTatlas.ctab fabian lh white',
  32. 'sysname': 'Linux',
  33. 'hostname': 'another-hostname',
  34. 'machine': 'x86_64',
  35. 'user': 'some-username',
  36. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  37. 'anatomy_type': 'surface',
  38. 'subjectname': 'fabian',
  39. 'hemi': 'lh',
  40. 'AnnotationFile': '../label/lh.aparc.DKTatlas.annot',
  41. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 23, 5, 40)},
  42. 'left',
  43. {'white_surface_total_area_mm^2': 98553,
  44. 'mean_thickness_mm': 2.50462,
  45. 'brain_segmentation_volume_mm^3': 1327432.000000,
  46. 'brain_segmentation_volume_without_ventricles_mm^3': 1316285.000000,
  47. 'brain_segmentation_volume_without_ventricles_from_surf_mm^3': 1315572.548920,
  48. 'total_cortical_gray_matter_volume_mm^3': 553998.311189,
  49. 'supratentorial_volume_mm^3': 1172669.548920,
  50. 'supratentorial_volume_without_ventricles_mm^3': 1164180.548920,
  51. 'estimated_total_intracranial_volume_mm^3': 1670487.274486},
  52. [{'structure_name': 'caudalanteriorcingulate',
  53. 'number_of_vertices': 2061,
  54. 'surface_area_mm^2': 1472,
  55. 'gray_matter_volume_mm^3': 4258,
  56. 'average_thickness_mm': 2.653,
  57. 'thickness_stddev_mm': 0.644,
  58. 'integrated_rectified_mean_curvature_mm^-1': 0.135,
  59. 'integrated_rectified_gaussian_curvature_mm^-2': 0.020,
  60. 'folding_index': 27,
  61. 'intrinsic_curvature_index': 1.6},
  62. {'structure_name': 'caudalmiddlefrontal',
  63. 'number_of_vertices': 4451,
  64. 'surface_area_mm^2': 3039,
  65. 'gray_matter_volume_mm^3': 8239,
  66. 'average_thickness_mm': 2.456,
  67. 'thickness_stddev_mm': 0.486,
  68. 'integrated_rectified_mean_curvature_mm^-1': 0.116,
  69. 'integrated_rectified_gaussian_curvature_mm^-2': 0.020,
  70. 'folding_index': 42,
  71. 'intrinsic_curvature_index': 3.7},
  72. {'structure_name': 'insula',
  73. 'number_of_vertices': 3439,
  74. 'surface_area_mm^2': 2304,
  75. 'gray_matter_volume_mm^3': 7594,
  76. 'average_thickness_mm': 3.193,
  77. 'thickness_stddev_mm': 0.620,
  78. 'integrated_rectified_mean_curvature_mm^-1': 0.116,
  79. 'integrated_rectified_gaussian_curvature_mm^-2': 0.027,
  80. 'folding_index': 33,
  81. 'intrinsic_curvature_index': 3.5}]),
  82. (os.path.join(
  83. SUBJECTS_DIR, 'fabian', 'stats', 'rh.aparc.pial.stats.short'),
  84. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 3, 42, tzinfo=datetime.timezone.utc),
  85. 'generating_program': 'mris_anatomical_stats',
  86. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  87. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  88. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/rh.cortex.label'
  89. ' -f ../stats/rh.aparc.pial.stats -b -a ../label/rh.aparc.annot'
  90. ' -c ../label/aparc.annot.ctab fabian rh pial',
  91. 'sysname': 'Linux',
  92. 'hostname': 'some-hostname',
  93. 'machine': 'x86_64',
  94. 'user': 'some-username',
  95. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  96. 'anatomy_type': 'surface',
  97. 'subjectname': 'fabian',
  98. 'hemi': 'rh',
  99. 'AnnotationFile': '../label/rh.aparc.annot',
  100. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 22, 27, 28)},
  101. 'right',
  102. {'pial_surface_total_area_mm^2': 121260,
  103. 'mean_thickness_mm': 2.4817,
  104. 'brain_segmentation_volume_mm^3': 1327432.000000,
  105. 'brain_segmentation_volume_without_ventricles_mm^3': 1316285.000000,
  106. 'brain_segmentation_volume_without_ventricles_from_surf_mm^3': 1315572.548920,
  107. 'total_cortical_gray_matter_volume_mm^3': 553998.311189,
  108. 'supratentorial_volume_mm^3': 1172669.548920,
  109. 'supratentorial_volume_without_ventricles_mm^3': 1164180.548920,
  110. 'estimated_total_intracranial_volume_mm^3': 1670487.274486},
  111. [{'structure_name': 'bankssts',
  112. 'number_of_vertices': 1344,
  113. 'surface_area_mm^2': 825,
  114. 'gray_matter_volume_mm^3': 2171,
  115. 'average_thickness_mm': 2.436,
  116. 'thickness_stddev_mm': 0.381,
  117. 'integrated_rectified_mean_curvature_mm^-1': 0.115,
  118. 'integrated_rectified_gaussian_curvature_mm^-2': 0.028,
  119. 'folding_index': 19,
  120. 'intrinsic_curvature_index': 1.7},
  121. {'structure_name': 'transversetemporal',
  122. 'number_of_vertices': 651,
  123. 'surface_area_mm^2': 545,
  124. 'gray_matter_volume_mm^3': 1061,
  125. 'average_thickness_mm': 2.251,
  126. 'thickness_stddev_mm': 0.317,
  127. 'integrated_rectified_mean_curvature_mm^-1': 0.110,
  128. 'integrated_rectified_gaussian_curvature_mm^-2': 0.021,
  129. 'folding_index': 3,
  130. 'intrinsic_curvature_index': 0.6}])],
  131. )
  132. def test_read(path, headers, hemisphere, whole_brain_measurements, structural_measurements):
  133. stats = CorticalParcellationStats.read(path)
  134. assert headers == stats.headers
  135. assert hemisphere == stats.hemisphere
  136. pandas.util.testing.assert_frame_equal(
  137. left=pandas.DataFrame([whole_brain_measurements]),
  138. right=stats.whole_brain_measurements,
  139. check_like=True, # ignore the order of index & columns
  140. check_dtype=True,
  141. check_names=True,
  142. )
  143. assert list(stats.structural_measurements.columns) == [
  144. 'structure_name',
  145. 'number_of_vertices',
  146. 'surface_area_mm^2',
  147. 'gray_matter_volume_mm^3',
  148. 'average_thickness_mm',
  149. 'thickness_stddev_mm',
  150. 'integrated_rectified_mean_curvature_mm^-1',
  151. 'integrated_rectified_gaussian_curvature_mm^-2',
  152. 'folding_index',
  153. 'intrinsic_curvature_index',
  154. ]
  155. pandas.util.testing.assert_frame_equal(
  156. left=pandas.DataFrame(structural_measurements),
  157. right=stats.structural_measurements,
  158. check_like=True, # ignore the order of index & columns
  159. check_dtype=True,
  160. check_names=True,
  161. )