-
Notifications
You must be signed in to change notification settings - Fork 265
ENH: Add write_morph_data to freesurfer.io #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
62d1e52
61345e1
df0b9bb
2a3a0b2
d684b01
1566d9b
02eec3b
949768a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"""Reading functions for freesurfer files | ||
""" | ||
|
||
from .io import read_geometry, read_morph_data, \ | ||
from .io import read_geometry, read_morph_data, write_morph_data, \ | ||
read_annot, read_label, write_geometry, write_annot | ||
from .mghformat import load, save, MGHImage |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,13 @@ | |
|
||
from nose.tools import assert_true | ||
import numpy as np | ||
from numpy.testing import assert_equal, dec | ||
from numpy.testing import assert_equal, assert_raises, dec | ||
|
||
from .. import (read_geometry, read_morph_data, read_annot, read_label, | ||
write_geometry, write_annot) | ||
write_geometry, write_morph_data, write_annot) | ||
|
||
from ...tests.nibabel_data import get_nibabel_data | ||
from ...fileslice import strided_scalar | ||
|
||
|
||
DATA_SDIR = 'fsaverage' | ||
|
@@ -92,6 +93,33 @@ def test_morph_data(): | |
curv = read_morph_data(curv_path) | ||
assert_true(-1.0 < curv.min() < 0) | ||
assert_true(0 < curv.max() < 1.0) | ||
with InTemporaryDirectory(): | ||
new_path = 'test' | ||
write_morph_data(new_path, curv) | ||
curv2 = read_morph_data(new_path) | ||
assert_equal(curv2, curv) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a test reading an existing curv data file from freesurfer examples, re-writing and reading again? E.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what this modification does. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry - yes I see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for errors for too-large array and array > 1D? |
||
|
||
def test_write_morph_data(): | ||
"""Test write_morph_data edge cases""" | ||
values = np.arange(20, dtype='>f4') | ||
okay_shapes = [(20,), (20, 1), (20, 1, 1), (1, 20)] | ||
bad_shapes = [(10, 2), (1, 1, 20, 1, 1)] | ||
big_num = np.iinfo('i4').max + 1 | ||
with InTemporaryDirectory(): | ||
for shape in okay_shapes: | ||
write_morph_data('test.curv', values.reshape(shape)) | ||
# Check ordering is preserved, regardless of shape | ||
assert_equal(values, read_morph_data('test.curv')) | ||
assert_raises(ValueError, write_morph_data, 'test.curv', | ||
np.zeros(shape), big_num) | ||
# Windows 32-bit overflows Python int | ||
if np.dtype(np.int) != np.dtype(np.int32): | ||
assert_raises(ValueError, write_morph_data, 'test.curv', | ||
strided_scalar((big_num,))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatives, if this is ugly:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem to capture the case for PYTHON_VERSION=2.7, PYTHON_ARCH=32. |
||
for shape in bad_shapes: | ||
assert_raises(ValueError, write_morph_data, 'test.curv', | ||
values.reshape(shape)) | ||
|
||
|
||
@freesurfer_test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.