From f59ec99f40b0e41cbcb816422a4e380ecc810b1e Mon Sep 17 00:00:00 2001 From: vikineema Date: Mon, 8 May 2023 16:54:24 +0000 Subject: [PATCH 1/3] Add mask for sentinel-2 pixels valued 1 to StatsGM --- odc/stats/plugins/gm.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/odc/stats/plugins/gm.py b/odc/stats/plugins/gm.py index 30981a67..1e7f4392 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]) + + # Remove sentinel-2 pixels valued 1 (scene edges, terrain shadow) + if self._mask_band == "SCL": + edges_shadow_mask = (xx <= 1).to_array(dim="band").all(dim="band") + bad = edges_shadow_mask | bad + xx = erase_bad(xx, bad) + return xx def reduce(self, xx: xr.Dataset) -> xr.Dataset: From 1247a8c34f9e0701a2c7786aadab252dae311762 Mon Sep 17 00:00:00 2001 From: vikineema Date: Mon, 8 May 2023 16:54:24 +0000 Subject: [PATCH 2/3] Add mask for sentinel-2 pixels valued 1 to StatsGM --- odc/stats/plugins/gm.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/odc/stats/plugins/gm.py b/odc/stats/plugins/gm.py index 30981a67..43f2f3f2 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: From 57ee9638457a0b6a07f5fc4c53e039b98aef5d14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 May 2023 09:21:39 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- odc/stats/plugins/gm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/odc/stats/plugins/gm.py b/odc/stats/plugins/gm.py index 3939fecf..f4f27e9b 100644 --- a/odc/stats/plugins/gm.py +++ b/odc/stats/plugins/gm.py @@ -104,14 +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: