Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 6 commits into from
Aug 30, 2024
Merged

Use mask as alpha when reprojecting a masked array #3156

merged 6 commits into from
Aug 30, 2024

Conversation

sgillies
Copy link
Member

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.

@sgillies sgillies added this to the 1.4.0 milestone Aug 29, 2024
@sgillies sgillies self-assigned this Aug 29, 2024
crs=src_crs,
copy=True)

if hasattr(source, "mask"):
Copy link
Member

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?

Copy link
Member Author

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.

@sgillies sgillies merged commit 1ac101d into main Aug 30, 2024
20 checks passed
@sgillies sgillies deleted the issue2575 branch August 30, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

warp.reproject does not handle masked arrays properly
2 participants