From d4a505f23fa64fe3095bbc8f738d0c498ae876d4 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Mon, 10 Jun 2019 22:47:38 +0930 Subject: [PATCH] BF,ENH: ImageWrapper and naninfrange have support for structured arrays (e.g. RGB data) --- fsl/data/imagewrapper.py | 6 ++++-- fsl/utils/naninfrange.py | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py index 2b49e4af5..9c4b549ea 100644 --- a/fsl/data/imagewrapper.py +++ b/fsl/data/imagewrapper.py @@ -303,9 +303,11 @@ class ImageWrapper(notifier.Notifier): # data range for each volume/slice/vector # # We use nan as a placeholder, so the - # dtype must be non-integral + # dtype must be non-integral. The + # len(dtype) check takes into account + # structured data (e.g. RGB) dtype = self.__image.get_data_dtype() - if np.issubdtype(dtype, np.integer): + if np.issubdtype(dtype, np.integer) or len(dtype) > 0: dtype = np.float32 self.__volRanges = np.zeros((nvols, 2), dtype=dtype) diff --git a/fsl/utils/naninfrange.py b/fsl/utils/naninfrange.py index c8437c8d9..bfb497f38 100644 --- a/fsl/utils/naninfrange.py +++ b/fsl/utils/naninfrange.py @@ -23,6 +23,12 @@ def naninfrange(data): use an alternate approach to calculating the minimum/maximum. """ + # For structured arrays, we assume that + # all fields are numeric, and we simply + # take the range across all fields + if len(data.dtype) > 0: + data = np.concatenate([data[n] for n in data.dtype.names]) + if not np.issubdtype(data.dtype, np.floating): return data.min(), data.max() -- GitLab