-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: handle fully masked data #9285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
As min/max do not make sense for an array with no non-masked values numpy returns a singleton, `np.ma.masked`, which can not be cast to a number. In this case just treat numbers as in range (0, 1) (even though it will just be ignored due to the masking). closes #9280
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,8 +370,19 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, | |
scaled_dtype = np.float32 | ||
# old versions of numpy do not work with `np.nammin` | ||
# and `np.nanmax` as inputs | ||
a_min = np.ma.min(A).astype(scaled_dtype) | ||
a_max = np.ma.max(A).astype(scaled_dtype) | ||
a_min = np.ma.min(A) | ||
a_max = np.ma.max(A) | ||
|
||
# we need these try/except blocks to handle | ||
# fully-masked/invalid input | ||
try: | ||
a_min = a_min.astype(scaled_dtype) | ||
except AttributeError: | ||
a_min = 0 | ||
try: | ||
a_max = a_max.astype(scaled_dtype) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gee, can't leave it alone. try:
a_min = a_min.astype(scaled_dtype)
except AttributeError:
a_min, a_max = 0, 1
else:
a_max = a_max.astype(scaled_dtype) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or shorten the whole block. From the top: try:
a_min = A.min().astype(scaled_dtype)
except AttributeError:
a_min, a_max = 0, 1 # all masked, so values don't matter
else:
a_max = A.max().astype(scaled_dtype) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And taking @anntzer's suggestion: a_min = A.min().astype(scaled_dtype)
if a_min is np.ma.masked:
a_min, a_max = 0, 1 # all masked, so values don't matter
else:
a_max = A.max().astype(scaled_dtype) |
||
except AttributeError: | ||
a_min = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simpler? if np.ma.count(A) == 0:
a_min, a_max = 0, 1 # all masked, so values don't matter
else:
a_min = np.ma.min(A).astype(scaled_dtype)
a_max = np.ma.max(A).astype(scaled_dtype) |
||
# scale the input data to [.1, .9]. The Agg | ||
# interpolators clip to [0, 1] internally, use a | ||
# smaller input scale to identify which of the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And delete the 4 lines above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
details....