Skip to content

Comments

Fix reproject for masked arrays with numpy.ma.nomask#3306

Merged
sgillies merged 1 commit intorasterio:mainfrom
useyardstick:reproject-nomask
Feb 27, 2025
Merged

Fix reproject for masked arrays with numpy.ma.nomask#3306
sgillies merged 1 commit intorasterio:mainfrom
useyardstick:reproject-nomask

Conversation

@omarkhan
Copy link
Contributor

@omarkhan omarkhan commented Feb 4, 2025

Masked arrays can have their mask attribute set to numpy.ma.nomask to indicate that no values are masked. If I try to reproject such an array using rasterio.warp.reproject, I get the following error:

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 1 has 1 dimension(s)

The error comes from this line:

source_arr = np.concatenate((source.data, [mask]))

This pull request is an attempt to fix the issue by filling the alpha mask with 255 if the input array's mask is set to the numpy.ma.nomask constant.

@sgillies sgillies self-assigned this Feb 4, 2025
@sgillies sgillies added warp mask backport-1.4 To be backported to maint-1.4 labels Feb 4, 2025
Copy link
Member

@sgillies sgillies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @omarkhan !

@sgillies sgillies merged commit a1dd8a2 into rasterio:main Feb 27, 2025
22 checks passed
snowman2 pushed a commit to snowman2/rasterio that referenced this pull request Nov 6, 2025
@snowman2 snowman2 added this to the 1.4.4 milestone Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-1.4 To be backported to maint-1.4 mask warp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants