-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use correct dtype for RGB image alpha channel #1893
Conversation
Thanks @Zac-HD ! Again (and sorry for the hassle ;), this needs a regression test. Also, could you change the rasterio example in the docs and see if your change indeed makes the normalisation obsolete? (https://github.com/pydata/xarray/blob/master/doc/gallery/plot_rasterio_rgb.py#L27) |
doc/gallery/plot_rasterio_rgb.py
Outdated
# The data is in UTM projection. We have to set it manually until | ||
# https://github.com/SciTools/cartopy/issues/813 is implemented | ||
# https://github.com/SciTools/cartopy/issues/813 is implemented, so that | ||
# the coastlines are drawn in the same coordinate system as the image. |
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 is not exactly what I meant. Right now we can draw the coastlines in the same coordinate system as the image. What we need SciTools/cartopy#813 for is a tool to convert the PROJ4 string (available as attribute da.crs
) to a cartopy.Proj
instance (see SciTools/cartopy#813 (comment)). To be honest I don't understand why Cartopy made the choice to create their own new projection classes with their own kwargs instead of relying on an existing system, but this is another topic...
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.
Right, I've just reverted this comment - I don't understand it well enough to improve the explanation, and it's not really part of this PR.
Appart from the comment in the gallery example and the flake8 error, this looks good to me! Thanks @Zac-HD ! |
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.
Thanks! I'll leave this open for a couple more days in case someone wants to chime in.
xarray/plot/plot.py
Outdated
alpha = np.ma.ones(z.shape[:2] + (1,), dtype=z.dtype) | ||
if np.issubdtype(z.dtype, np.integer): | ||
alpha *= 255 | ||
z = np.ma.concatenate((z, alpha), 2) |
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.
nit: can you use axis=2
here, for clarity? (I loathe undocumented literals)
The failing tests in appveyor should be fixed by #1904 |
Thanks @Zac-HD ! |
The cause of the bug in #1880 was that I had forgotten to specify the dtype when creating an alpha channel, and therefore concatenating it cast the all the data to float64. I've fixed that, corrected the alpha value for integer arrays, and avoided a pointless copy to save memory.