Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
cfbbd146
Commit
cfbbd146
authored
May 27, 2022
by
Paul McCarthy
🚵
Browse files
Merge branch 'rf/force-load' into 'master'
Rf/force load See merge request fsl/fslpy!341
parents
432d73be
f86d5d96
Pipeline
#14480
canceled with stages
in 7 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.rst
View file @
cfbbd146
...
...
@@ -2,6 +2,20 @@ This document contains the ``fslpy`` release history in reverse chronological
order.
3.9.4 (Friday 27th May 2022)
----------------------------
Changed
^^^^^^^
* Changed the behaviour of :meth:`.Image.__getitem__` so that, if image
data is accessed with a boolean mask array (e.g. ``image[mask > 0]``),
the image data is loaded into memory (!341).
* Fixed an issue in the :func:`.func_to_cmd` function (!339).
3.9.3 (Friday 27th May 2022)
----------------------------
...
...
fsl/data/image.py
View file @
cfbbd146
...
...
@@ -1068,7 +1068,7 @@ class Image(Nifti):
Internally, the image data is managed using one of the following methods:
1. For read-only access, the ``Image`` class delegates
entirely
to the
1. For read-only access, the ``Image`` class delegates to the
underlying ``nibabel.Nifti1Image`` instance, accessing the data
via the ``Nifti1Image.dataobj`` attribute. Refer to
https://nipy.org/nibabel/nibabel_images.html#the-image-data-array for
...
...
@@ -1081,7 +1081,13 @@ class Image(Nifti):
the underlying ``nibabel.Nifti1Image`` object (refer to
https://nipy.org/nibabel/images_and_memory.html)
3. For more complicated requirements, a :class:`DataManager`,
3. The ``nibabel.Nifti1Image`` class does not support indexing of image
data with boolean mask arrays (e.g. ``image[mask > 0]``). If an
attempt is made to access image data in this way, the ``Image`` class
will be loaded into memory in the same way as described in point 2
above.
4. For more complicated requirements, a :class:`DataManager`,
implementing custom data access management logic, can be provided when
an ``Image`` is created. If a ``DataManager``is provided, an
internal reference to the data (see 2 above) will **not** be created or
...
...
@@ -1603,6 +1609,17 @@ class Image(Nifti):
expNdims
,
expShape
=
expectedShape
(
slc
,
shape
)
slc
=
canonicalSliceObj
(
slc
,
realShape
)
# The nibabel arrayproxy does not support
# boolean mask-based (a.k.a. "fancy")
# indexing. If we are given a mask, we
# force-load the image data into memory.
if
all
((
fancy
,
self
.
__dataMgr
is
None
,
self
.
__data
is
None
)):
log
.
debug
(
'Fancy slice detected - force-loading image '
'data into memory (%s)'
,
self
.
name
)
self
.
data
if
self
.
__dataMgr
is
not
None
:
data
=
self
.
__dataMgr
[
slc
]
elif
self
.
__data
is
not
None
:
data
=
self
.
__data
[
slc
]
else
:
data
=
self
.
__nibImage
.
dataobj
[
slc
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment