Fix plot_rgb stretch failure with masked NaN arrays - #960
Open
xiangcheng1112 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IMPORTANT: DO NOT USE THIS REPO TO PRACTICE PULL REQUESTS AND LEARN GITHUB!
Earth Lab -- Pull Request Template
Welcome to EarthPy!
Before submitting a Pull Request please be sure to submit an issue that describes what the contents of the PR addresses.
IMPORTANT: Please do not use this repository as a practice activity to learn how to use GitHub! Only submit a PR after:
Description
Fixes #675
_stretch_im() uses np.nanpercentile() which does not handle masked arrays correctly.
When a band is a masked array (e.g., raster loaded by rioxarray), it returns NaN
values, causing rescale_intensity to produce a black image.
Added a check: if band is masked, use np.percentile(band.compressed(), ...) instead.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Testing
Test A - Existing test suite
python -m pytest earthpy/tests/test_plot_rgb.py -v
All 12 tests passed, including
test_stretch_image_nanandtest_masked_im.No regressions.
Test B - Reproduction of issue #675