Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
cc702436
Commit
cc702436
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
deprecated imagewrapper.naninfrange
parent
8721da08
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/data/imagewrapper.py
+13
-44
13 additions, 44 deletions
fsl/data/imagewrapper.py
with
13 additions
and
44 deletions
fsl/data/imagewrapper.py
+
13
−
44
View file @
cc702436
...
@@ -41,11 +41,14 @@ import logging
...
@@ -41,11 +41,14 @@ import logging
import
collections
import
collections
import
itertools
as
it
import
itertools
as
it
import
deprecation
import
numpy
as
np
import
numpy
as
np
import
nibabel
as
nib
import
nibabel
as
nib
import
fsl.utils.notifier
as
notifier
import
fsl.utils.notifier
as
notifier
import
fsl.utils.idle
as
idle
import
fsl.utils.naninfrange
as
nir
import
fsl.utils.idle
as
idle
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -137,7 +140,6 @@ class ImageWrapper(notifier.Notifier):
...
@@ -137,7 +140,6 @@ class ImageWrapper(notifier.Notifier):
.. autosummary::
.. autosummary::
:nosignatures:
:nosignatures:
naninfrange
isValidFancySliceObj
isValidFancySliceObj
canonicalSliceObj
canonicalSliceObj
sliceObjToSliceTuple
sliceObjToSliceTuple
...
@@ -469,7 +471,7 @@ class ImageWrapper(notifier.Notifier):
...
@@ -469,7 +471,7 @@ class ImageWrapper(notifier.Notifier):
oldvlo
,
oldvhi
=
self
.
__volRanges
[
vol
,
:]
oldvlo
,
oldvhi
=
self
.
__volRanges
[
vol
,
:]
voldata
=
data
[...,
vi
]
voldata
=
data
[...,
vi
]
newvlo
,
newvhi
=
naninfrange
(
voldata
)
newvlo
,
newvhi
=
nir
.
naninfrange
(
voldata
)
if
np
.
isnan
(
newvlo
)
or
\
if
np
.
isnan
(
newvlo
)
or
\
(
not
np
.
isnan
(
oldvlo
)
and
oldvlo
<
newvlo
):
(
not
np
.
isnan
(
oldvlo
)
and
oldvlo
<
newvlo
):
...
@@ -487,7 +489,7 @@ class ImageWrapper(notifier.Notifier):
...
@@ -487,7 +489,7 @@ class ImageWrapper(notifier.Notifier):
# Calculate the new known data
# Calculate the new known data
# range over the entire image
# range over the entire image
# (i.e. over all volumes).
# (i.e. over all volumes).
newmin
,
newmax
=
naninfrange
(
self
.
__volRanges
)
newmin
,
newmax
=
nir
.
naninfrange
(
self
.
__volRanges
)
oldmin
,
oldmax
=
self
.
__range
oldmin
,
oldmax
=
self
.
__range
self
.
__range
=
(
newmin
,
newmax
)
self
.
__range
=
(
newmin
,
newmax
)
...
@@ -713,47 +715,14 @@ class ImageWrapper(notifier.Notifier):
...
@@ -713,47 +715,14 @@ class ImageWrapper(notifier.Notifier):
self
.
__updateDataRangeOnWrite
(
slices
,
values
)
self
.
__updateDataRangeOnWrite
(
slices
,
values
)
@deprecation.deprecated
(
deprecated_in
=
'
1.7.0
'
,
removed_in
=
'
2.0.0
'
,
details
=
'
Moved to fsl.utils.naninfrange
'
)
def
naninfrange
(
data
):
def
naninfrange
(
data
):
"""
Returns the minimum and maximum values in the given ``numpy`` array,
"""
Deprecated - moved to :mod:`fsl.utils.naninfrange`.
"""
ignoring ``nan`` and ``inf`` values.
The ``numpy.nanmin``/``numpy.nanmax`` functions do not handle
positive/negative infinity, so if such values are in the data, we need to
use an alternate approach to calculating the minimum/maximum.
"""
if
not
np
.
issubdtype
(
data
.
dtype
,
np
.
floating
):
from
fsl.utils.naninfrange
import
naninfrange
return
data
.
min
(),
data
.
max
()
return
naninfrange
(
data
)
# But np.nanmin/nanmax are substantially
# faster than the alternate, so we try it
# first.
dmin
=
np
.
nanmin
(
data
)
dmax
=
np
.
nanmax
(
data
)
# If there are no nans/infs in the data,
# we can just use nanmin/nanmax
if
np
.
isfinite
(
dmin
)
and
np
.
isfinite
(
dmax
):
return
dmin
,
dmax
# The entire array contains nans
if
np
.
isnan
(
dmin
):
return
dmin
,
dmin
# Otherwise we need to calculate min/max
# only on finite values. This is the slow
# option.
# Find all finite values
finite
=
np
.
isfinite
(
data
)
# Try to calculate min/max on those values.
# An error will be raised if there are no
# finite values in the array
try
:
return
data
[
finite
].
min
(),
data
[
finite
].
max
()
except
Exception
:
return
np
.
nan
,
np
.
nan
def
isValidFancySliceObj
(
sliceobj
,
shape
):
def
isValidFancySliceObj
(
sliceobj
,
shape
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment