Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 0 additions & 3 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
3 changes: 3 additions & 0 deletions tests/test_lc_l4_ctv.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50):
"cultivated_class": xr.DataArray(
da.from_array(cultivated, chunks=(1, -1, -1)),
dims=("spec", "y", "x"),
attrs={"nodata": 255},
),
"woody_cover": xr.DataArray(
da.from_array(woody, chunks=(1, -1, -1)),
Expand Down Expand Up @@ -129,12 +130,14 @@ def test_ctv_classes_woody():

stats_l4 = StatsLccsLevel4()
level3 = lc_level3.lc_level3(xx)

lifeform = lc_lifeform.lifeform(xx)
veg_cover = l4_veg_cover.canopyco_veg_con(xx, stats_l4.veg_threshold)

l4_ctv = l4_cultivated.lc_l4_cultivated(
xx.classes_l3_l4, level3, lifeform, veg_cover
)

assert (l4_ctv.compute() == expected_cultivated_classes).all()


Expand Down
8 changes: 4 additions & 4 deletions tests/test_lc_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def image_groups():
[110, 110, 210],
[124, 110, 210],
[221, 210, 210],
[223, 255, 223],
[223, np.nan, 223],
]
],
dtype="uint8",
dtype="float32",
)

urban = np.array(
Expand All @@ -48,10 +48,10 @@ def image_groups():
[111, 112, 255],
[255, 112, 255],
[255, 255, 255],
[255, 255, 255],
[255, np.nan, np.nan],
]
],
dtype="uint8",
dtype="float32",
)

tuples = [
Expand Down
Loading