Skip to content

Commit

Permalink
Improve mask reduction (h/t Chuck 🎉)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceholden committed Dec 16, 2024
1 parent 6df930e commit ad12a50
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions hls_vi/generate_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit ad12a50

Please sign in to comment.