Skip to content
Snippets Groups Projects
Commit 5404594b authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

TEST: Test saving mem-mapped images

parent 10f4b70f
No related branches found
No related tags found
No related merge requests found
...@@ -994,29 +994,29 @@ def _test_Image_save(imgtype): ...@@ -994,29 +994,29 @@ def _test_Image_save(imgtype):
make_image(filename, imgtype) make_image(filename, imgtype)
# Using mmap can cause a "Bus error" # Save to original location, and
# under docker. No idea why. # to a different location. And
img = fslimage.Image(filename, mmap=False) # test both with and without mmap
targets = [None, filename, filename2]
mmaps = [False, True]
randvoxes = randvoxes(5) for target, mmap in it.product(targets, mmaps):
randvals = [np.random.random() for i in range(5)]
for (x, y, z), v in zip(randvoxes, randvals): img = fslimage.Image(filename, mmap=mmap)
img[x, y, z] = v
if imgtype > 0: rvoxs = randvoxes(5)
img.voxToWorldMat = xform rvals = [np.random.random() for i in range(5)]
# Save to original location, and for (x, y, z), v in zip(rvoxs, rvals):
# to a different location img[x, y, z] = v
targets = [None, filename, filename2]
for t in targets: if imgtype > 0:
img.voxToWorldMat = xform
img.save(t) img.save(target)
if t is None: expDataSource = filename if target is None: expDataSource = filename
else: expDataSource = t else: expDataSource = target
assert img.saveState assert img.saveState
assert img.dataSource == expDataSource assert img.dataSource == expDataSource
...@@ -1024,7 +1024,7 @@ def _test_Image_save(imgtype): ...@@ -1024,7 +1024,7 @@ def _test_Image_save(imgtype):
if imgtype > 0: if imgtype > 0:
assert np.all(np.isclose(img.voxToWorldMat, xform)) assert np.all(np.isclose(img.voxToWorldMat, xform))
for (x, y, z), v in zip(randvoxes, randvals): for (x, y, z), v in zip(rvoxs, rvals):
assert np.isclose(img[x, y, z], v) assert np.isclose(img[x, y, z], v)
# Load the image back in # Load the image back in
...@@ -1036,7 +1036,7 @@ def _test_Image_save(imgtype): ...@@ -1036,7 +1036,7 @@ def _test_Image_save(imgtype):
if imgtype > 0: if imgtype > 0:
assert np.all(np.isclose(img.voxToWorldMat, xform)) assert np.all(np.isclose(img.voxToWorldMat, xform))
for (x, y, z), v in zip(randvoxes, randvals): for (x, y, z), v in zip(rvoxs, rvals):
assert np.isclose(img[x, y, z], v) assert np.isclose(img[x, y, z], v)
img2 = None img2 = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment