diff --git a/odc/stats/plugins/gm.py b/odc/stats/plugins/gm.py index 30981a67..f4f27e9b 100644 --- a/odc/stats/plugins/gm.py +++ b/odc/stats/plugins/gm.py @@ -5,7 +5,7 @@ import xarray as xr from odc.algo import geomedian_with_mads from ._registry import StatsPluginInterface, register -from odc.algo import enum_to_bool, erase_bad +from odc.algo import enum_to_bool, erase_bad, keep_good_only from odc.algo import mask_cleanup import logging @@ -104,7 +104,14 @@ def native_transform(self, xx: xr.Dataset) -> xr.Dataset: xx = xx.drop_vars([self._mask_band] + [self._contiguity_band]) else: xx = xx.drop_vars([self._mask_band]) + xx = erase_bad(xx, bad) + + # Remove sentinel-2 pixels valued 1 (scene edges, terrain shadow) + if self._mask_band == "SCL": + valid_data_mask = (xx > 1).to_array(dim="band").all(dim="band") + xx = keep_good_only(xx, where=valid_data_mask) + return xx def reduce(self, xx: xr.Dataset) -> xr.Dataset: