-
Notifications
You must be signed in to change notification settings - Fork 153
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
Render nans as 'bad' in mpl cmaps when mode='colormap' #2427
Conversation
@@ -137,7 +138,8 @@ def __call__(self, bounds=None): | |||
data = interval(array) | |||
data = contrast_bias(data, out=data) | |||
data = stretch(data, out=data) | |||
data[np.isnan(data)] = 0 | |||
if self._set_nans_to_zero: | |||
data[np.isnan(data)] = 0 |
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.
This was only introduced in fa60bf1 for compatibility with Astropy; if we can reproduce what the issue with Astropy was, preserving NaN may perhaps be made the default again.
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.
@astrofrog Any memory/tips of what we should check? Thanks!
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.
I think it was actually that astropy did not preserve NaNs and then started to so it's not an issue with astropy as such - but more that when you do color compositing you don't really have the option to give NaN values their own color since each channel has only one color assigned to it. So I think it's as I mentioned on the call - for multi-color compositing we should always set NaNs to 0 and for the colormap we could never set it to zero.
d85b0ee
to
e01db76
Compare
As of e01db76, nans are forced to zero when |
It looks like some tests will need to be updated |
e01db76
to
670aa34
Compare
@astrofrog All fixed! |
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.
Looks good, thanks!
Description
By default, image viewers cast NaNs to zero before applying a colormap. This prevents the use of the matplotlib "bad" feature. For each colormap, values above or below the colormap vmin/vmax are rendered with an optionally specified value, and "bad" values (usually nans) are rendered by a third value:
By default,
bad
iscolor='k', alpha=0
, but this can be changed with:which allows users to clearly visualize nans efficiently and without special handling.
Glue currently forces nans to zero before they are converted to colors by the colormap:
glue/glue/viewers/image/composite_array.py
Line 140 in 0f83a03
which prevents the user from ever making use of the
bad
functionality.This PR allows the user to set a private attribute on the
CompositeArray
class called_set_nans_to_zero
. When True, the behavior is unchanged. When set to False by a user, nans are not forced to zero, and thebad
values are rendered as described by the mpl colormap. An example is shown below using Imviz from jdaviz: