Skip to content
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

Update data_as_image to return masked values #635

Merged
merged 2 commits into from
Aug 21, 2023

Conversation

JackDunnNZ
Copy link
Contributor

Prior to this change, the raw data array was being returned, which could include nodata values, throwing off an automatic image color scale. In the following example, the nodata value used is -9999 (for all oceans), which causes the image to basically appear as a land mask:

from matplotlib.pyplot import imshow
from rio_tiler.io.rasterio import Reader

with Reader("https://data.chc.ucsb.edu/products/CHIRPS-2.0/global_daily/cogs/p05/2023/chirps-v2.0.2023.02.01.cog") as r:
    img = r.read(nodata=-9999)
    
imshow(img.data_as_image())

image

If instead we use the masked array values, the automatic color scale is scoped to just the valid data values:

imshow(img.array[0, :, :])

image

@vincentsarago
Copy link
Member

@JackDunnNZ will imshow(img.data_as_image()) still work event if the return type is a Numpy Masked array?

@JackDunnNZ
Copy link
Contributor Author

Yes it seems to, the second example above is passing a masked array to imshow. I also get the same result running imshow(img.data_as_image()) on this branch

@vincentsarago
Copy link
Member

@JackDunnNZ can you add something in the changelog 🙏

@vincentsarago vincentsarago merged commit 322533c into cogeotiff:main Aug 21, 2023
@vincentsarago
Copy link
Member

🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants