Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
added ashs.IntracranialVolumeFile.read_volume_series()
Browse files Browse the repository at this point in the history
  • Loading branch information
fphammerle committed Aug 7, 2019
1 parent 61180f2 commit b008080
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions freesurfer_volume_reader/ashs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def read_volume_mm3(self) -> float:
assert subject == self.subject, (subject, self.subject)
return float(icv)

def read_volume_series(self) -> pandas.Series:
return pandas.Series(
data=[self.read_volume_mm3()],
name='volume_mm^3',
index=pandas.Index(
data=[self.subject],
name='subject',
),
)


class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile):

Expand Down
54 changes: 54 additions & 0 deletions tests/ashs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,60 @@ def test_intracranial_volume_file_read_volume_mm3_not_found(volume_file_path):
volume_file.read_volume_mm3()


@pytest.mark.parametrize(('volume_file_path', 'expected_series'), [
(os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'),
pandas.Series(
data=[1234560.0],
name='volume_mm^3',
index=pandas.Index(data=['bert'], name='subject'),
)),
(os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt'),
pandas.Series(
data=[1543200.0],
name='volume_mm^3',
index=pandas.Index(data=['alice'], name='subject'),
)),
])
def test_intracranial_volume_file_read_volume_series_single(volume_file_path, expected_series):
volume_file = IntracranialVolumeFile(path=volume_file_path)
pandas.testing.assert_series_equal(
left=expected_series,
right=volume_file.read_volume_series(),
check_dtype=True,
check_names=True,
)


@pytest.mark.parametrize(('volume_file_paths', 'expected_series'), [
([os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'),
os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt')],
pandas.Series(
data=[1234560.0, 1543200.0],
name='volume_mm^3',
index=pandas.Index(data=['bert', 'alice'], name='subject'),
)),
])
def test_intracranial_volume_file_read_volume_series_concat(volume_file_paths, expected_series):
volume_series = pandas.concat(
IntracranialVolumeFile(path=p).read_volume_series()
for p in volume_file_paths)
pandas.testing.assert_series_equal(
left=expected_series,
right=volume_series,
check_dtype=True,
check_names=True,
)


@pytest.mark.parametrize('volume_file_path', [
os.path.join(SUBJECTS_DIR, 'bert', 'final', 'BERT_icv.txt'),
])
def test_intracranial_volume_file_read_volume_series_not_found(volume_file_path):
volume_file = IntracranialVolumeFile(path=volume_file_path)
with pytest.raises(FileNotFoundError):
volume_file.read_volume_series()


@pytest.mark.parametrize(('volume_file_path', 'expected_attrs'), [
('ashs/final/bert_left_heur_volumes.txt',
{'subject': 'bert', 'hemisphere': 'left', 'correction': None}),
Expand Down

0 comments on commit b008080

Please sign in to comment.