From 7ca53c06e3dc2355223b444e36279e101d68d3ae Mon Sep 17 00:00:00 2001 From: Emma Ai Date: Thu, 19 Dec 2024 12:26:41 +1030 Subject: [PATCH] fill nodata of bright building top as urban (#179) Co-authored-by: Emma Ai --- odc/stats/plugins/lc_level34.py | 22 ++++++++++++++++++++++ tests/test_lc_level34.py | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/odc/stats/plugins/lc_level34.py b/odc/stats/plugins/lc_level34.py index 4b17107..905f21a 100644 --- a/odc/stats/plugins/lc_level34.py +++ b/odc/stats/plugins/lc_level34.py @@ -114,6 +114,17 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset: xx, self.class_def, self.class_condition[class_col], class_col ) + # patch the bright building top, where + # level3 = nodata & artificial_surface = 215 -> artificial_surface (215) + + level3 = expr_eval( + "where((a==nodata)&(b==215), 215, a)", + {"a": level3, "b": xx.artificial_surface.data}, + name="l3_patch_building_top", + dtype="uint8", + **{"nodata": NODATA}, + ) + # apply urban mask # 215 -> 216 if urban_mask == 0 urban_mask = rasterize_vector_mask( @@ -146,6 +157,17 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset: xx, self.class_def, self.class_condition[class_col], class_col ) + # patch the bright building top, where + # level4 = nodata & level3 = 215 -> artifical_surface(93) + + level4 = expr_eval( + "where((a==nodata)&(b==215), 93, a)", + {"a": level4, "b": xx.level3.data}, + name="l4_patch_building_top", + dtype="uint8", + **{"nodata": NODATA}, + ) + data_vars = { k: xr.DataArray(v, dims=dims, attrs=attrs) for k, v in zip(self.measurements, [level3.squeeze(), level4.squeeze()]) diff --git a/tests/test_lc_level34.py b/tests/test_lc_level34.py index 81322ad..1a43801 100644 --- a/tests/test_lc_level34.py +++ b/tests/test_lc_level34.py @@ -25,7 +25,7 @@ def image_groups(): [ [210, 210, 210], [210, 210, 210], - [223, 210, 210], + [223, 255, 210], [221, 221, 221], ] ],