-
Notifications
You must be signed in to change notification settings - Fork 539
Use mask as alpha when reprojecting a masked array #3156
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
Conversation
The tests of this PR are now only run for GDAL 3.8+ because the outputs are too variable.
crs=src_crs, | ||
copy=True) | ||
|
||
if hasattr(source, "mask"): |
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.
we have twice the if hasattr(source, "mask")
test, could those block be merged together?
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.
@vincentsarago except that the first block needs to run before the input is reshaped and the second block needs to run after the input is reshaped. It's a bit gross, but I'm inclined to let it go for now.
Background:
reproject()
can take an array and return an array. GDAL's warper requires input and output GDALDatasetH, so we construct them using the GDAL "MEM" driver, pointing at the memory location of two arrays.What this PR does is add alpha bands to those datasets when the inputs and outputs are masked arrays. For input, 3-D array masks are reduced to a 2-D array via
logical_or()
(because GDAL needs a single alpha mask channel). For output, the alpha mask band is repeated over the number of image bands.I suspect the approach could be made more efficient. Copying is required in some cases because the "MEM" driver needs a precise memory layout.
Resolves #2575.