ashs_test.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import os
  2. import pytest
  3. from freesurfer_volume_reader.ashs import HippocampalSubfieldsVolumeFile
  4. from conftest import SUBJECTS_DIR
  5. @pytest.mark.parametrize(('volume_file_path', 'expected_attrs'), [
  6. ('ashs/final/bert_left_heur_volumes.txt',
  7. {'subject': 'bert', 'hemisphere': 'left', 'correction': None}),
  8. ('ashs/final/bert_left_corr_nogray_volumes.txt',
  9. {'subject': 'bert', 'hemisphere': 'left', 'correction': 'nogray'}),
  10. ('ashs/final/bert_left_corr_usegray_volumes.txt',
  11. {'subject': 'bert', 'hemisphere': 'left', 'correction': 'usegray'}),
  12. ('ashs/final/bert_right_heur_volumes.txt',
  13. {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
  14. ('ashs/final/bert_right_corr_nogray_volumes.txt',
  15. {'subject': 'bert', 'hemisphere': 'right', 'correction': 'nogray'}),
  16. ('ashs/final/bert_right_corr_usegray_volumes.txt',
  17. {'subject': 'bert', 'hemisphere': 'right', 'correction': 'usegray'}),
  18. ('somewhere/else/bert_right_heur_volumes.txt',
  19. {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
  20. ('somewhere/else/bert_right_corr_nogray_volumes.txt',
  21. {'subject': 'bert', 'hemisphere': 'right', 'correction': 'nogray'}),
  22. ('bert_right_heur_volumes.txt',
  23. {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
  24. ('/foo/bar/alice_20190503_right_corr_nogray_volumes.txt',
  25. {'subject': 'alice_20190503', 'hemisphere': 'right', 'correction': 'nogray'}),
  26. ])
  27. def test_hippocampal_subfields_volume_file_init(volume_file_path, expected_attrs):
  28. volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
  29. assert os.path.abspath(volume_file_path) == volume_file.absolute_path
  30. for attr, value in expected_attrs.items():
  31. assert value == getattr(volume_file, attr)
  32. @pytest.mark.parametrize('volume_file_path', [
  33. 'bert_middle_heur_volumes.txt',
  34. 'bert_right_hear_volumes.txt',
  35. 'bert_right_heur_volumes.nii',
  36. 'bert_left_lfseg_corr_usegray.nii.gz',
  37. ])
  38. def test_hippocampal_subfields_volume_file_init_invalid(volume_file_path):
  39. with pytest.raises(Exception):
  40. HippocampalSubfieldsVolumeFile(path=volume_file_path)
  41. @pytest.mark.parametrize(('volume_file_path', 'expected_volumes'), [
  42. (os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_left_corr_nogray_volumes.txt'),
  43. {'CA1': 678.901,
  44. 'CA2+3': 123.456,
  45. 'DG': 901.234,
  46. 'ERC': 678.901,
  47. 'PHC': 2345.876,
  48. 'PRC': 2345.678,
  49. 'SUB': 457.789}),
  50. ])
  51. def test_hippocampal_subfields_volume_file_read_volumes_mm3(volume_file_path, expected_volumes):
  52. volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
  53. assert expected_volumes == volume_file.read_volumes_mm3()
  54. def test_hippocampal_subfields_volume_file_read_volumes_mm3_not_found():
  55. volume_file = HippocampalSubfieldsVolumeFile(
  56. path=os.path.join(SUBJECTS_DIR, 'nobert', 'final', 'bert_left_corr_nogray_volumes.txt'))
  57. with pytest.raises(FileNotFoundError):
  58. volume_file.read_volumes_mm3()