Skip to content

Commit

Permalink
Apply the fix to noadata issue at land cover level3
Browse files Browse the repository at this point in the history
  • Loading branch information
tebadi committed Oct 31, 2024
1 parent 182de0d commit 1a7d532
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
27 changes: 15 additions & 12 deletions odc/stats/plugins/l34_utils/lc_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,31 @@
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, a, b)",
"where((a!=a)|(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)",
{
"a": res,
"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)",
Expand All @@ -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
5 changes: 1 addition & 4 deletions odc/stats/plugins/lc_level34.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 1a7d532

Please sign in to comment.