Return NaN from glcm_texture angle=None when no angle has valid pairs (#1408)#1409
Merged
brendancol merged 2 commits intomainfrom May 2, 2026
Merged
Return NaN from glcm_texture angle=None when no angle has valid pairs (#1408)#1409brendancol merged 2 commits intomainfrom
brendancol merged 2 commits intomainfrom
Conversation
…#1408) The angle=None path averaged per-angle results by replacing NaN with 0 and dividing by 4. For pixels where every angle produced NaN (all-NaN window, 1x1 raster, isolated valid pixel), the output was 0.0 -- a finite value indistinguishable from "metric is genuinely 0". Switch to nanmean-style averaging: only count angles that produced a valid value; if none did, the output stays NaN. The single-angle path already returned NaN in this case, so the two paths now agree. Updated test_all_nan_raster, test_single_cell, and test_angle_none_averages to assert the new behaviour, and added test_angle_none_partial_nan_uses_valid_angles to cover the partial-validity case.
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.
Summary
Test plan
pytest xrspatial/tests/test_glcm.py(35 passed)test_all_nan_rasterto assert NaN for every metric and every angle settingtest_single_cellto assert NaN for every angle settingtest_angle_none_partial_nan_uses_valid_anglesto confirm partial-validity uses nanmean across valid anglestest_angle_none_averagesto compare againstnp.nanmeanrather than the old zero-replace mean