test_cortical_parcellation_stats.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import datetime
  2. import os
  3. import pandas.util.testing
  4. import pytest
  5. from conftest import SUBJECTS_DIR
  6. from freesurfer_stats import CorticalParcellationStats
  7. @pytest.mark.parametrize(
  8. ('path', 'headers', 'hemisphere',
  9. 'whole_brain_measurements', 'structure_measurements'),
  10. [(os.path.join(SUBJECTS_DIR, 'fabian', 'stats', 'lh.aparc.DKTatlas.stats.short'),
  11. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 5, 54, tzinfo=datetime.timezone.utc),
  12. 'generating_program': 'mris_anatomical_stats',
  13. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  14. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  15. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/lh.cortex.label'
  16. ' -f ../stats/lh.aparc.DKTatlas.stats -b -a ../label/lh.aparc.DKTatlas.annot'
  17. ' -c ../label/aparc.annot.DKTatlas.ctab fabian lh white',
  18. 'sysname': 'Linux',
  19. 'hostname': 'another-hostname',
  20. 'machine': 'x86_64',
  21. 'user': 'some-username',
  22. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  23. 'anatomy_type': 'surface',
  24. 'subjectname': 'fabian',
  25. 'hemi': 'lh',
  26. 'AnnotationFile': '../label/lh.aparc.DKTatlas.annot',
  27. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 23, 5, 40)},
  28. 'left',
  29. {'white_surface_total_area_mm^2': 98553,
  30. 'mean_thickness_mm': 2.50462,
  31. 'brain_segmentation_volume_mm^3': 1327432.000000,
  32. 'brain_segmentation_volume_without_ventricles_mm^3': 1316285.000000,
  33. 'brain_segmentation_volume_without_ventricles_from_surf_mm^3': 1315572.548920,
  34. 'total_cortical_gray_matter_volume_mm^3': 553998.311189,
  35. 'supratentorial_volume_mm^3': 1172669.548920,
  36. 'supratentorial_volume_without_ventricles_mm^3': 1164180.548920,
  37. 'estimated_total_intracranial_volume_mm^3': 1670487.274486},
  38. [{'structure_name': 'caudalanteriorcingulate',
  39. 'number_of_vertices': 2061,
  40. 'surface_area_mm^2': 1472,
  41. 'gray_matter_volume_mm^3': 4258,
  42. 'average_thickness_mm': 2.653,
  43. 'thickness_stddev_mm': 0.644,
  44. 'integrated_rectified_mean_curvature_mm^-1': 0.135,
  45. 'integrated_rectified_gaussian_curvature_mm^-2': 0.020,
  46. 'folding_index': 27,
  47. 'intrinsic_curvature_index': 1.6},
  48. {'structure_name': 'caudalmiddlefrontal',
  49. 'number_of_vertices': 4451,
  50. 'surface_area_mm^2': 3039,
  51. 'gray_matter_volume_mm^3': 8239,
  52. 'average_thickness_mm': 2.456,
  53. 'thickness_stddev_mm': 0.486,
  54. 'integrated_rectified_mean_curvature_mm^-1': 0.116,
  55. 'integrated_rectified_gaussian_curvature_mm^-2': 0.020,
  56. 'folding_index': 42,
  57. 'intrinsic_curvature_index': 3.7},
  58. {'structure_name': 'insula',
  59. 'number_of_vertices': 3439,
  60. 'surface_area_mm^2': 2304,
  61. 'gray_matter_volume_mm^3': 7594,
  62. 'average_thickness_mm': 3.193,
  63. 'thickness_stddev_mm': 0.620,
  64. 'integrated_rectified_mean_curvature_mm^-1': 0.116,
  65. 'integrated_rectified_gaussian_curvature_mm^-2': 0.027,
  66. 'folding_index': 33,
  67. 'intrinsic_curvature_index': 3.5}]),
  68. (os.path.join(
  69. SUBJECTS_DIR, 'fabian', 'stats', 'rh.aparc.pial.stats.short'),
  70. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 3, 42, tzinfo=datetime.timezone.utc),
  71. 'generating_program': 'mris_anatomical_stats',
  72. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  73. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  74. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/rh.cortex.label'
  75. ' -f ../stats/rh.aparc.pial.stats -b -a ../label/rh.aparc.annot'
  76. ' -c ../label/aparc.annot.ctab fabian rh pial',
  77. 'sysname': 'Linux',
  78. 'hostname': 'some-hostname',
  79. 'machine': 'x86_64',
  80. 'user': 'some-username',
  81. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  82. 'anatomy_type': 'surface',
  83. 'subjectname': 'fabian',
  84. 'hemi': 'rh',
  85. 'AnnotationFile': '../label/rh.aparc.annot',
  86. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 22, 27, 28)},
  87. 'right',
  88. {'pial_surface_total_area_mm^2': 121260,
  89. 'mean_thickness_mm': 2.4817,
  90. 'brain_segmentation_volume_mm^3': 1327432.000000,
  91. 'brain_segmentation_volume_without_ventricles_mm^3': 1316285.000000,
  92. 'brain_segmentation_volume_without_ventricles_from_surf_mm^3': 1315572.548920,
  93. 'total_cortical_gray_matter_volume_mm^3': 553998.311189,
  94. 'supratentorial_volume_mm^3': 1172669.548920,
  95. 'supratentorial_volume_without_ventricles_mm^3': 1164180.548920,
  96. 'estimated_total_intracranial_volume_mm^3': 1670487.274486},
  97. [{'structure_name': 'bankssts',
  98. 'number_of_vertices': 1344,
  99. 'surface_area_mm^2': 825,
  100. 'gray_matter_volume_mm^3': 2171,
  101. 'average_thickness_mm': 2.436,
  102. 'thickness_stddev_mm': 0.381,
  103. 'integrated_rectified_mean_curvature_mm^-1': 0.115,
  104. 'integrated_rectified_gaussian_curvature_mm^-2': 0.028,
  105. 'folding_index': 19,
  106. 'intrinsic_curvature_index': 1.7},
  107. {'structure_name': 'transversetemporal',
  108. 'number_of_vertices': 651,
  109. 'surface_area_mm^2': 545,
  110. 'gray_matter_volume_mm^3': 1061,
  111. 'average_thickness_mm': 2.251,
  112. 'thickness_stddev_mm': 0.317,
  113. 'integrated_rectified_mean_curvature_mm^-1': 0.110,
  114. 'integrated_rectified_gaussian_curvature_mm^-2': 0.021,
  115. 'folding_index': 3,
  116. 'intrinsic_curvature_index': 0.6}])],
  117. )
  118. def test_read(path, headers, hemisphere, whole_brain_measurements, structure_measurements):
  119. stats = CorticalParcellationStats.read(path)
  120. assert headers == stats.headers
  121. assert hemisphere == stats.hemisphere
  122. pandas.util.testing.assert_frame_equal(
  123. left=pandas.DataFrame([whole_brain_measurements]),
  124. right=stats.whole_brain_measurements,
  125. check_like=True, # ignore the order of index & columns
  126. check_dtype=True,
  127. check_names=True,
  128. )
  129. assert list(stats.structure_measurements.columns) == [
  130. 'structure_name',
  131. 'number_of_vertices',
  132. 'surface_area_mm^2',
  133. 'gray_matter_volume_mm^3',
  134. 'average_thickness_mm',
  135. 'thickness_stddev_mm',
  136. 'integrated_rectified_mean_curvature_mm^-1',
  137. 'integrated_rectified_gaussian_curvature_mm^-2',
  138. 'folding_index',
  139. 'intrinsic_curvature_index',
  140. ]
  141. pandas.util.testing.assert_frame_equal(
  142. left=pandas.DataFrame(structure_measurements),
  143. right=stats.structure_measurements,
  144. check_like=True, # ignore the order of index & columns
  145. check_dtype=True,
  146. check_names=True,
  147. )