Skip to content

Return NaN from glcm_texture angle=None when no angle has valid pairs (#1408)#1409

Merged
brendancol merged 2 commits intomainfrom
issue-1408
May 2, 2026
Merged

Return NaN from glcm_texture angle=None when no angle has valid pairs (#1408)#1409
brendancol merged 2 commits intomainfrom
issue-1408

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Fixes glcm_texture angle=None returns 0 instead of NaN for windows with no valid pairs #1408: angle=None previously returned 0.0 for windows where no angle had valid pairs (all-NaN window, 1x1 raster), which is indistinguishable from a genuine zero-texture reading
  • Switch the angle-averaging path to nanmean-style: count only angles that produced a valid value; stay NaN if none did
  • Single-angle paths already returned NaN here, so the two paths now agree

Test plan

  • pytest xrspatial/tests/test_glcm.py (35 passed)
  • Strengthened test_all_nan_raster to assert NaN for every metric and every angle setting
  • Strengthened test_single_cell to assert NaN for every angle setting
  • Added test_angle_none_partial_nan_uses_valid_angles to confirm partial-validity uses nanmean across valid angles
  • Updated test_angle_none_averages to compare against np.nanmean rather than the old zero-replace mean
  • Cross-backend tests pass (numpy, dask+numpy, cupy, dask+cupy)

brendancol added 2 commits May 1, 2026 17:40
…#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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 2, 2026
@brendancol brendancol merged commit 0451c98 into main May 2, 2026
11 checks passed
@brendancol brendancol deleted the issue-1408 branch May 4, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

glcm_texture angle=None returns 0 instead of NaN for windows with no valid pairs

1 participant