test_cortical_parcellation_stats.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import datetime
  2. import os
  3. import pandas.util.testing
  4. import pytest
  5. from conftest import SUBJECTS_DIR, assert_approx_equal
  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': (98553, 'mm^2'),
  30. 'Mean Thickness': (2.50462, 'mm'),
  31. 'Brain Segmentation Volume': (1327432.000000, 'mm^3'),
  32. 'Brain Segmentation Volume Without Ventricles': (1316285.000000, 'mm^3'),
  33. 'Brain Segmentation Volume Without Ventricles from Surf': (1315572.548920, 'mm^3'),
  34. 'Total cortical gray matter volume': (553998.311189, 'mm^3'),
  35. 'Supratentorial volume': (1172669.548920, 'mm^3'),
  36. 'Supratentorial volume Without Ventricles': (1164180.548920, 'mm^3'),
  37. 'Estimated Total Intracranial Volume': (1670487.274486, 'mm^3')},
  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': (121260, 'mm^2'),
  89. 'Mean Thickness': (2.4817, 'mm'),
  90. 'Brain Segmentation Volume': (1327432.000000, 'mm^3'),
  91. 'Brain Segmentation Volume Without Ventricles': (1316285.000000, 'mm^3'),
  92. 'Brain Segmentation Volume Without Ventricles from Surf': (1315572.548920, 'mm^3'),
  93. 'Total cortical gray matter volume': (553998.311189, 'mm^3'),
  94. 'Supratentorial volume': (1172669.548920, 'mm^3'),
  95. 'Supratentorial volume Without Ventricles': (1164180.548920, 'mm^3'),
  96. 'Estimated Total Intracranial Volume': (1670487.274486, 'mm^3')},
  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. assert_approx_equal(whole_brain_measurements,
  123. stats.whole_brain_measurements)
  124. assert list(stats.structure_measurements.columns) == [
  125. 'Structure Name',
  126. 'Number of Vertices',
  127. 'Surface Area (mm^2)',
  128. 'Gray Matter Volume (mm^3)',
  129. 'Average Thickness (mm)',
  130. 'Thickness StdDev (mm)',
  131. 'Integrated Rectified Mean Curvature (mm^-1)',
  132. 'Integrated Rectified Gaussian Curvature (mm^-2)',
  133. 'Folding Index',
  134. 'Intrinsic Curvature Index',
  135. ]
  136. pandas.util.testing.assert_frame_equal(
  137. left=pandas.DataFrame(structure_measurements),
  138. right=stats.structure_measurements,
  139. check_like=True, # ignore the order of index & columns
  140. check_dtype=True,
  141. check_names=True,
  142. )