Skip to content

Commit b3a63a6

Browse files
committed
RF: rename method to get image; add scaling flag
Method was called `write` but in fact the method did not have to write an image, it could just return an image, read from disk. Add boolean flag `has_scaling` to say whether the returned image has scaling to apply to the data[, or not.
1 parent 67cae93 commit b3a63a6

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

nibabel/tests/test_parrec.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,9 @@ class TestPARRECImage(tsi.MmapImageMixin):
735735
image_class = PARRECImage
736736
check_mmap_mode = False
737737

738-
def write_image(self):
739-
return parrec.load(EG_PAR), EG_PAR
738+
def get_disk_image(self):
739+
# The example image does have image scaling to apply
740+
return parrec.load(EG_PAR), EG_PAR, True
740741

741742

742743
def test_bitpix():

nibabel/tests/test_spatialimages.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,23 +340,36 @@ class MmapImageMixin(object):
340340
#: whether to test mode of returned memory map
341341
check_mmap_mode = True
342342

343-
def write_image(self):
344-
""" Return an image and an image filname to test against
343+
def get_disk_image(self):
344+
""" Return an image and an image filname, and scaling bool to test against
345+
346+
Subclasses can do anything to return an image, including loading a
347+
pre-existing image from disk.
348+
349+
Returns
350+
-------
351+
img : class:`SpatialImage` instance
352+
fname : str
353+
Image filename
354+
has_scaling : bool
355+
True if the image array has scaling to apply to the raw image array
356+
data, False otherwise.
357+
358+
Notes
345359
"""
346360
img_klass = self.image_class
347361
shape = (3, 4, 2)
348362
data = np.arange(np.prod(shape), dtype=np.int16).reshape(shape)
349363
img = img_klass(data, None)
350364
fname = 'test' + img_klass.files_types[0][1]
351365
img.to_filename(fname)
352-
return img, fname
366+
return img, fname, False
353367

354368
def test_load_mmap(self):
355369
# Test memory mapping when loading images
356370
img_klass = self.image_class
357371
with InTemporaryDirectory():
358-
# This should have no scaling, can be mmapped
359-
img, fname = self.write_image()
372+
img, fname, has_scaling = self.get_disk_image()
360373
file_map = img.file_map.copy()
361374
for func, param1 in ((img_klass.from_filename, fname),
362375
(img_klass.load, fname),

0 commit comments

Comments
 (0)