From ad12a50269c1288b3f5c0250ca0ba3f694ec934e Mon Sep 17 00:00:00 2001 From: Chris Holden Date: Mon, 16 Dec 2024 11:19:03 -0500 Subject: [PATCH] Improve mask reduction (h/t Chuck :tada:) --- hls_vi/generate_indices.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hls_vi/generate_indices.py b/hls_vi/generate_indices.py index cc35fd7..415084e 100644 --- a/hls_vi/generate_indices.py +++ b/hls_vi/generate_indices.py @@ -210,17 +210,15 @@ def apply_union_of_masks(bands: List[np.ma.masked_array]) -> List[np.ma.masked_a Reference: https://github.com/NASA-IMPACT/hls-vi/issues/44 """ - if not bands: - return [] - # NB - numpy masked arrays "true" is a masked value, "false" is unmasked # so bitwise "or" will mask if "any" band has a masked value for that pixel - mask = bands[0].mask.copy() - for band in bands[1:]: - mask |= band.mask + mask = np.ma.nomask + for band in bands: + mask = np.ma.mask_or(mask, band.mask) for band in bands: band.mask = mask + return bands