From 1a7d5321fec5e861314657f0b05960d57e449de8 Mon Sep 17 00:00:00 2001 From: Toktam Ebadi Date: Thu, 31 Oct 2024 23:27:54 +0000 Subject: [PATCH] Apply the fix to noadata issue at land cover level3 --- odc/stats/plugins/l34_utils/lc_level3.py | 27 +++++++++++++----------- odc/stats/plugins/lc_level34.py | 5 +---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/odc/stats/plugins/l34_utils/lc_level3.py b/odc/stats/plugins/l34_utils/lc_level3.py index a380b55d..796d2fde 100644 --- a/odc/stats/plugins/l34_utils/lc_level3.py +++ b/odc/stats/plugins/l34_utils/lc_level3.py @@ -8,16 +8,20 @@ def lc_level3(xx: xr.Dataset): # Cultivated pipeline applies a mask which feeds only terrestrial veg (110) to the model - # Just exclude no data (255) and apply the cultivated results + # Just exclude no data (255 or nan) and apply the cultivated results + # 255: load with product definition; nan: load without + # hence accormmodate both + res = expr_eval( - "where(a=nodata), b, a)", {"a": xx.cultivated_class.data, "b": xx.classes_l3_l4.data}, name="mask_cultivated", dtype="float32", - **{"nodata": NODATA}, + **{"nodata": xx.cultivated_class.attrs.get("nodata")}, ) # Mask urban results with bare sfc (210) + res = expr_eval( "where(a==_u, b, a)", { @@ -25,18 +29,10 @@ def lc_level3(xx: xr.Dataset): "b": xx.urban_classes.data, }, name="mark_urban", - dtype="uint8", + dtype="float32", **{"_u": 210}, ) - # Add intertidal as water - res = expr_eval( - "where((a==223)|(a==221), 220, b)", - {"a": xx.classes_l3_l4.data, "b": res}, - name="mark_urban", - dtype="uint8", - ) - # Mark nodata to 255 in case any nan res = expr_eval( "where(a==a, a, nodata)", @@ -47,5 +43,12 @@ def lc_level3(xx: xr.Dataset): dtype="uint8", **{"nodata": NODATA}, ) + # Add intertidal as water + res = expr_eval( + "where((a==223)|(a==221), 220, b)", + {"a": xx.classes_l3_l4.data, "b": res}, + name="mark_urban", + dtype="uint8", + ) return res diff --git a/odc/stats/plugins/lc_level34.py b/odc/stats/plugins/lc_level34.py index bafd6f61..8b7a6caa 100644 --- a/odc/stats/plugins/lc_level34.py +++ b/odc/stats/plugins/lc_level34.py @@ -60,9 +60,6 @@ def measurements(self) -> Tuple[str, ...]: _measurements = ["level3", "level4"] return _measurements - def native_transform(self, xx): - return xx - def fuser(self, xx): return xx @@ -114,7 +111,7 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset: attrs = xx.attrs.copy() attrs["nodata"] = NODATA dims = xx.classes_l3_l4.dims[1:] - + data_vars = { "level3": xr.DataArray(level3.squeeze(), dims=dims, attrs=attrs), "level4": xr.DataArray(level4.squeeze(), dims=dims, attrs=attrs),