From b1bf0229ff076a7c0138fbae006fc53bc0f65bdf Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Mon, 13 Jun 2016 17:12:12 +0100 Subject: [PATCH] Logic for updating coverage previously in updateDataRangeOnRead moved into a separate method, as it will probably come in handy for write support. --- fsl/data/imagewrapper.py | 52 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py index 69868992c..9126bdc5d 100644 --- a/fsl/data/imagewrapper.py +++ b/fsl/data/imagewrapper.py @@ -228,28 +228,12 @@ class ImageWrapper(notifier.Notifier): shape = self.__image.shape slices = zip([0] * len(shape), shape) return sliceCovered(slices, self.__coverage) - - def __updateDataRangeOnRead(self, slices, data): - """Called by :meth:`__getitem__`. Calculates the minimum/maximum - values of the given data (which has been extracted from the portion of - the image specified by ``slices``), and updates the known data range - of the image. - :arg slices: A tuple of tuples, each tuple being a ``(low, high)`` - index pair, one for each dimension in the image. - - :arg data: The image data at the given ``slices`` (as a ``numpy`` - array). + def __expandCoverage(self, slices): + """Expands the current image data range and coverage to encompass the + given ``slices``. """ - - log.debug('Updating image {} data range (current range: ' - '[{}, {}]; current coverage: {})'.format( - self.__name, - self.__range[0], - self.__range[1], - self.__coverage)) - volumes, expansions = calcExpansion(slices, self.__coverage) oldmin, oldmax = self.__range @@ -280,7 +264,35 @@ class ImageWrapper(notifier.Notifier): oldmax, newmin, newmax)) - self.notify() + self.notify() + + + def __updateDataRangeOnRead(self, slices, data): + """Called by :meth:`__getitem__`. Calculates the minimum/maximum + values of the given data (which has been extracted from the portion of + the image specified by ``slices``), and updates the known data range + of the image. + + :arg slices: A tuple of tuples, each tuple being a ``(low, high)`` + index pair, one for each dimension in the image. + + :arg data: The image data at the given ``slices`` (as a ``numpy`` + array). + """ + + log.debug('Updating image {} data range (current range: ' + '[{}, {}]; current coverage: {})'.format( + self.__name, + self.__range[0], + self.__range[1], + self.__coverage)) + + # TODO You could do something with + # the provided data to avoid + # reading it in again. + + self.__expandCoverage(slices) + def __getitem__(self, sliceobj): -- GitLab