test_cortical_parcellation_stats.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import datetime
  2. import os
  3. import pytest
  4. from conftest import SUBJECTS_DIR
  5. from freesurfer_stats import CorticalParcellationStats
  6. @pytest.mark.parametrize(('path', 'headers', 'hemisphere', 'whole_brain_measurements'), [
  7. (os.path.join(SUBJECTS_DIR, 'fabian', 'stats', 'lh.aparc.DKTatlas.stats'),
  8. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 5, 54, tzinfo=datetime.timezone.utc),
  9. 'generating_program': 'mris_anatomical_stats',
  10. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  11. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  12. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/lh.cortex.label'
  13. ' -f ../stats/lh.aparc.DKTatlas.stats -b -a ../label/lh.aparc.DKTatlas.annot'
  14. ' -c ../label/aparc.annot.DKTatlas.ctab fabian lh white',
  15. 'sysname': 'Linux',
  16. 'hostname': 'another-hostname',
  17. 'machine': 'x86_64',
  18. 'user': 'some-username',
  19. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  20. 'anatomy_type': 'surface',
  21. 'subjectname': 'fabian',
  22. 'hemi': 'lh',
  23. 'AnnotationFile': '../label/lh.aparc.DKTatlas.annot',
  24. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 23, 5, 40)},
  25. 'left',
  26. {'White Surface Total Area': (98553, 'mm^2'),
  27. 'Mean Thickness': (2.50462, 'mm'),
  28. 'Brain Segmentation Volume': (1327432.000000, 'mm^3'),
  29. 'Brain Segmentation Volume Without Ventricles': (1316285.000000, 'mm^3'),
  30. 'Brain Segmentation Volume Without Ventricles from Surf': (1315572.548920, 'mm^3'),
  31. 'Total cortical gray matter volume': (553998.311189, 'mm^3'),
  32. 'Supratentorial volume': (1172669.548920, 'mm^3'),
  33. 'Supratentorial volume Without Ventricles': (1164180.548920, 'mm^3'),
  34. 'Estimated Total Intracranial Volume': (1670487.274486, 'mm^3')}),
  35. (os.path.join(
  36. SUBJECTS_DIR, 'fabian', 'stats', 'rh.aparc.pial.stats'),
  37. {'CreationTime': datetime.datetime(2019, 5, 9, 21, 3, 42, tzinfo=datetime.timezone.utc),
  38. 'generating_program': 'mris_anatomical_stats',
  39. 'cvs_version': 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp',
  40. 'mrisurf.c-cvs_version': 'Id: mrisurf.c,v 1.781.2.6 2016/12/27 16:47:14 zkaufman Exp',
  41. 'cmdline': 'mris_anatomical_stats -th3 -mgz -cortex ../label/rh.cortex.label'
  42. ' -f ../stats/rh.aparc.pial.stats -b -a ../label/rh.aparc.annot'
  43. ' -c ../label/aparc.annot.ctab fabian rh pial',
  44. 'sysname': 'Linux',
  45. 'hostname': 'some-hostname',
  46. 'machine': 'x86_64',
  47. 'user': 'some-username',
  48. 'SUBJECTS_DIR': '/home/some-username/freesurfer-subjects',
  49. 'anatomy_type': 'surface',
  50. 'subjectname': 'fabian',
  51. 'hemi': 'rh',
  52. 'AnnotationFile': '../label/rh.aparc.annot',
  53. 'AnnotationFileTimeStamp': datetime.datetime(2019, 5, 9, 22, 27, 28)},
  54. 'right',
  55. {'Pial Surface Total Area': (121260, 'mm^2'),
  56. 'Mean Thickness': (2.4817, 'mm'),
  57. 'Brain Segmentation Volume': (1327432.000000, 'mm^3'),
  58. 'Brain Segmentation Volume Without Ventricles': (1316285.000000, 'mm^3'),
  59. 'Brain Segmentation Volume Without Ventricles from Surf': (1315572.548920, 'mm^3'),
  60. 'Total cortical gray matter volume': (553998.311189, 'mm^3'),
  61. 'Supratentorial volume': (1172669.548920, 'mm^3'),
  62. 'Supratentorial volume Without Ventricles': (1164180.548920, 'mm^3'),
  63. 'Estimated Total Intracranial Volume': (1670487.274486, 'mm^3')}),
  64. ])
  65. def test_read(path, headers, hemisphere, whole_brain_measurements):
  66. stats = CorticalParcellationStats.read(path)
  67. assert headers == stats.headers
  68. assert hemisphere == stats.hemisphere
  69. assert whole_brain_measurements.keys() == stats.whole_brain_measurements.keys()
  70. for key, expected_value_unit in whole_brain_measurements.items():
  71. expected_value, expected_unit = expected_value_unit
  72. assert expected_value \
  73. == pytest.approx(stats.whole_brain_measurements[key][0])
  74. assert expected_unit == stats.whole_brain_measurements[key][1]