test_cortical_parcellation_stats.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import datetime
  2. import os
  3. import pytest
  4. from conftest import SUBJECTS_DIR, assert_approx_equal
  5. from freesurfer_stats import CorticalParcellationStats
  6. @pytest.mark.parametrize(
  7. ('path', 'headers', 'hemisphere',
  8. 'whole_brain_measurements', 'structure_measurements'),
  9. [(os.path.join(SUBJECTS_DIR, 'fabian', 'stats', 'lh.aparc.DKTatlas.stats.short'),
  10. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 5, 54, tzinfo=datetime.timezone.utc),
  11. 'generating_program': 'mris_anatomical_stats',
  12. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  13. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  14. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/lh.cortex.label'
  15. ' -f ../stats/lh.aparc.DKTatlas.stats -b -a ../label/lh.aparc.DKTatlas.annot'
  16. ' -c ../label/aparc.annot.DKTatlas.ctab fabian lh white',
  17. 'sysname': 'Linux',
  18. 'hostname': 'another-hostname',
  19. 'machine': 'x86_64',
  20. 'user': 'some-username',
  21. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  22. 'anatomy_type': 'surface',
  23. 'subjectname': 'fabian',
  24. 'hemi': 'lh',
  25. 'AnnotationFile': '../label/lh.aparc.DKTatlas.annot',
  26. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 23, 5, 40)},
  27. 'left',
  28. {'White Surface Total Area': (98553, 'mm^2'),
  29. 'Mean Thickness': (2.50462, 'mm'),
  30. 'Brain Segmentation Volume': (1327432.000000, 'mm^3'),
  31. 'Brain Segmentation Volume Without Ventricles': (1316285.000000, 'mm^3'),
  32. 'Brain Segmentation Volume Without Ventricles from Surf': (1315572.548920, 'mm^3'),
  33. 'Total cortical gray matter volume': (553998.311189, 'mm^3'),
  34. 'Supratentorial volume': (1172669.548920, 'mm^3'),
  35. 'Supratentorial volume Without Ventricles': (1164180.548920, 'mm^3'),
  36. 'Estimated Total Intracranial Volume': (1670487.274486, 'mm^3')},
  37. {'caudalanteriorcingulate': {
  38. 'Structure Name': 'caudalanteriorcingulate',
  39. 'Number of Vertices': 2061,
  40. 'Surface Area': 1472.0,
  41. 'Gray Matter Volume': 4258.0,
  42. 'Average Thickness': 2.653,
  43. 'Thickness StdDev': 0.644,
  44. 'Integrated Rectified Mean Curvature': 0.135,
  45. 'Integrated Rectified Gaussian Curvature': 0.020,
  46. 'Folding Index': 27,
  47. 'Intrinsic Curvature Index': 1.6},
  48. 'caudalmiddlefrontal': {
  49. 'Structure Name': 'caudalmiddlefrontal',
  50. 'Number of Vertices': 4451,
  51. 'Surface Area': 3039.0,
  52. 'Gray Matter Volume': 8239.0,
  53. 'Average Thickness': 2.456,
  54. 'Thickness StdDev': 0.486,
  55. 'Integrated Rectified Mean Curvature': 0.116,
  56. 'Integrated Rectified Gaussian Curvature': 0.020,
  57. 'Folding Index': 42,
  58. 'Intrinsic Curvature Index': 3.7},
  59. 'insula': {
  60. 'Structure Name': 'insula',
  61. 'Number of Vertices': 3439,
  62. 'Surface Area': 2304.0,
  63. 'Gray Matter Volume': 7594.0,
  64. 'Average Thickness': 3.193,
  65. 'Thickness StdDev': 0.620,
  66. 'Integrated Rectified Mean Curvature': 0.116,
  67. 'Integrated Rectified Gaussian Curvature': 0.027,
  68. 'Folding Index': 33,
  69. 'Intrinsic Curvature Index': 3.5}}),
  70. (os.path.join(
  71. SUBJECTS_DIR, 'fabian', 'stats', 'rh.aparc.pial.stats.short'),
  72. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 3, 42, tzinfo=datetime.timezone.utc),
  73. 'generating_program': 'mris_anatomical_stats',
  74. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  75. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  76. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/rh.cortex.label'
  77. ' -f ../stats/rh.aparc.pial.stats -b -a ../label/rh.aparc.annot'
  78. ' -c ../label/aparc.annot.ctab fabian rh pial',
  79. 'sysname': 'Linux',
  80. 'hostname': 'some-hostname',
  81. 'machine': 'x86_64',
  82. 'user': 'some-username',
  83. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  84. 'anatomy_type': 'surface',
  85. 'subjectname': 'fabian',
  86. 'hemi': 'rh',
  87. 'AnnotationFile': '../label/rh.aparc.annot',
  88. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 22, 27, 28)},
  89. 'right',
  90. {'Pial Surface Total Area': (121260, 'mm^2'),
  91. 'Mean Thickness': (2.4817, 'mm'),
  92. 'Brain Segmentation Volume': (1327432.000000, 'mm^3'),
  93. 'Brain Segmentation Volume Without Ventricles': (1316285.000000, 'mm^3'),
  94. 'Brain Segmentation Volume Without Ventricles from Surf': (1315572.548920, 'mm^3'),
  95. 'Total cortical gray matter volume': (553998.311189, 'mm^3'),
  96. 'Supratentorial volume': (1172669.548920, 'mm^3'),
  97. 'Supratentorial volume Without Ventricles': (1164180.548920, 'mm^3'),
  98. 'Estimated Total Intracranial Volume': (1670487.274486, 'mm^3')},
  99. {'bankssts': {
  100. 'Structure Name': 'bankssts',
  101. 'Number of Vertices': 1344,
  102. 'Surface Area': 825.0,
  103. 'Gray Matter Volume': 2171.0,
  104. 'Average Thickness': 2.436,
  105. 'Thickness StdDev': 0.381,
  106. 'Integrated Rectified Mean Curvature': 0.115,
  107. 'Integrated Rectified Gaussian Curvature': 0.028,
  108. 'Folding Index': 19,
  109. 'Intrinsic Curvature Index': 1.7},
  110. 'transversetemporal': {
  111. 'Structure Name': 'transversetemporal',
  112. 'Number of Vertices': 651,
  113. 'Surface Area': 545.0,
  114. 'Gray Matter Volume': 1061.0,
  115. 'Average Thickness': 2.251,
  116. 'Thickness StdDev': 0.317,
  117. 'Integrated Rectified Mean Curvature': 0.110,
  118. 'Integrated Rectified Gaussian Curvature': 0.021,
  119. 'Folding Index': 3,
  120. 'Intrinsic Curvature Index': 0.6}})],
  121. )
  122. def test_read(path, headers, hemisphere, whole_brain_measurements, structure_measurements):
  123. stats = CorticalParcellationStats.read(path)
  124. assert headers == stats.headers
  125. assert hemisphere == stats.hemisphere
  126. assert_approx_equal(whole_brain_measurements,
  127. stats.whole_brain_measurements)
  128. assert stats.structure_measurement_units == {
  129. 'Structure Name': None,
  130. 'Number of Vertices': None,
  131. 'Surface Area': 'mm^2',
  132. 'Gray Matter Volume': 'mm^3',
  133. 'Average Thickness': 'mm',
  134. 'Thickness StdDev': 'mm',
  135. 'Integrated Rectified Mean Curvature': 'mm^-1',
  136. 'Integrated Rectified Gaussian Curvature': 'mm^-2',
  137. 'Folding Index': None,
  138. 'Intrinsic Curvature Index': None,
  139. }
  140. assert_approx_equal(structure_measurements, stats.structure_measurements)