diff --git a/odc/stats/plugins/l34_utils/l4_natural_aquatic.py b/odc/stats/plugins/l34_utils/l4_natural_aquatic.py index 0036ae43..fbf29b26 100644 --- a/odc/stats/plugins/l34_utils/l4_natural_aquatic.py +++ b/odc/stats/plugins/l34_utils/l4_natural_aquatic.py @@ -5,400 +5,282 @@ from odc.stats._algebra import expr_eval -def natural_auquatic_veg(l4, lifeform, veg_cover, water_seasonality): +def natural_auquatic_veg(l4, veg_cover, water_seasonality): - l4 = expr_eval( - "where((a==124)&(b==10)&(c==1)&(d==1), 64, a)", + # mark woody/herbaceous + # mangroves -> woody + # everything else -> herbaceous + res = expr_eval( + "where((a==124), 56, a)", { "a": l4, - "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_woody", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==10)&(c==1)&(d==2), 65, a)", + + res = expr_eval( + "where((a==125), 57, a)", { - "a": l4, - "b": veg_cover, - "c": lifeform, - "d": water_seasonality, + "a": res, }, - name="mark_cultivated", + name="mark_herbaceous", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==12)&(c==1)&(d==1), 67, a)", + res = expr_eval( + "where((a!=124)|(a!=125), 255, a)", { - "a": l4, - "b": veg_cover, - "c": lifeform, - "d": water_seasonality, + "a": res, }, - name="mark_cultivated", + name="mark_nodata", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==12)&(c==1)&(d==2), 68, a)", + # mark water season + # use some value not used in final class + res = expr_eval( + "where((a==56)&(b==1), 254, a)", { - "a": l4, - "b": veg_cover, - "c": lifeform, - "d": water_seasonality, + "a": res, + "b": water_seasonality, }, - name="mark_cultivated", + name="mark_water_season", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==13)&(c==1)&(d==1), 70, a)", + res = expr_eval( + "where((a==56)&(b==2), 253, a)", { - "a": l4, - "b": veg_cover, - "c": lifeform, - "d": water_seasonality, + "a": res, + "b": water_seasonality, }, - name="mark_cultivated", + name="mark_water_season", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==13)&(c==1)&(d==2), 71, a)", + res = expr_eval( + "where((a==57)&(b==1), 252, a)", { - "a": l4, - "b": veg_cover, - "c": lifeform, - "d": water_seasonality, + "a": res, + "b": water_seasonality, }, - name="mark_cultivated", + name="mark_water_season", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==15)&(c==1)&(d==1), 73, a)", + res = expr_eval( + "where((a==57)&(b==2), 251, a)", { - "a": l4, - "b": veg_cover, - "c": lifeform, - "d": water_seasonality, + "a": res, + "b": water_seasonality, }, - name="mark_cultivated", + name="mark_water_season", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==15)&(c==1)&(d==2), 74, a)", + # mark final + + res = expr_eval( + "where((a==254)&(b==10), 64, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==16)&(c==1)&(d==1), 76, a)", + res = expr_eval( + "where((a==253)&(b==10), 65, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==16)&(c==1)&(d==2), 77, a)", + res = expr_eval( + "where((a==252)&(b==10), 80, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==10)&(c==2)&(d==1), 79, a)", + res = expr_eval( + "where((a==251)&(b==10), 81, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==10)&(c==2)&(d==2), 80, a)", + ######################################### + res = expr_eval( + "where((a==254)&(b==12), 67, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==12)&(c==2)&(d==1), 82, a)", + res = expr_eval( + "where((a==253)&(b==12), 68, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==12)&(c==2)&(d==2), 83, a)", + res = expr_eval( + "where((a==252)&(b==12), 82, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==13)&(c==2)&(d==1), 85, a)", + res = expr_eval( + "where((a==251)&(b==12), 83, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - - l4 = expr_eval( - "where((a==124)&(b==13)&(c==2)&(d==2), 86, a)", + ########################################## + res = expr_eval( + "where((a==254)&(b==13), 70, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==15)&(c==2)&(d==1), 88, a)", + res = expr_eval( + "where((a==253)&(b==13), 71, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==15)&(c==2)&(d==2), 89, a)", + res = expr_eval( + "where((a==252)&(b==13), 85, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==16)&(c==2)&(d==1), 91, a)", + res = expr_eval( + "where((a==251)&(b==13), 86, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) + ######################################### - l4 = expr_eval( - "where((a==124)&(b==16)&(c==2)&(d==2), 92, a)", + res = expr_eval( + "where((a==254)&(b==15), 73, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, - "d": water_seasonality, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==15)&(c==1), 72, a)", + res = expr_eval( + "where((a==253)&(b==15), 74, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==16)&(c==1), 75, a)", + res = expr_eval( + "where((a==252)&(b==15), 88, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==10)&(c==2), 78, a)", + + res = expr_eval( + "where((a==251)&(b==15), 89, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==12)&(c==2), 81, a)", + ########################################## + res = expr_eval( + "where((a==254)&(b==16), 76, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, }, - name="mark_cultivated", - dtype="uint8", - ) - l4 = expr_eval( - "where((a==124)&(b==13)&(c==2), 84, a)", - { - "a": l4, - "b": veg_cover, - "c": lifeform, - }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==15)&(c==2), 87, a)", + res = expr_eval( + "where((a==253)&(b==16), 77, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==16)&(c==2), 90, a)", + res = expr_eval( + "where((a==252)&(b==16), 91, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==10)&(c==1), 63, a)", + res = expr_eval( + "where((a==251)&(b==16), 92, a)", { - "a": l4, + "a": res, "b": veg_cover, - "c": lifeform, }, - name="mark_cultivated", + name="mark_final", dtype="uint8", ) - l4 = expr_eval( - "where((a==124)&(b==12)&(c==1), 66, a)", - { - "a": l4, - "b": veg_cover, - "c": lifeform, - }, - name="mark_cultivated", - dtype="uint8", - ) - l4 = expr_eval( - "where((a==124)&(b==13)&(c==1), 69, a)", - { - "a": l4, - "b": veg_cover, - "c": lifeform, - }, - name="mark_cultivated", - dtype="uint8", - ) - - l4 = expr_eval( - "where((a==124)&(b==1), 56, a)", - {"a": l4, "b": lifeform}, - name="mark_cultivated", - dtype="uint8", - ) - - l4 = expr_eval( - "where((a==124)&(c==2), 57, a)", - {"a": l4, "c": lifeform}, - name="mark_cultivated", - dtype="uint8", - ) - - l4 = expr_eval( - "where((a==124)&(b==10), 58, a)", - {"a": l4, "b": veg_cover}, - name="mark_cultivated", - dtype="uint8", - ) - l4 = expr_eval( - "where((a==124)&(b==12), 59, a)", - {"a": l4, "b": veg_cover}, - name="mark_cultivated", - dtype="uint8", - ) - - l4 = expr_eval( - "where((a==124)&(b==13), 60, a)", - {"a": l4, "b": veg_cover}, - name="mark_cultivated", - dtype="uint8", - ) - - l4 = expr_eval( - "where((a==124)&(b==15), 61, a)", - {"a": l4, "b": veg_cover}, - name="mark_cultivated", - dtype="uint8", - ) - l4 = expr_eval( - "where((a==124)&(b==16), 62, a)", - {"a": l4, "b": veg_cover}, - name="mark_cultivated", - dtype="uint8", - ) - l4 = expr_eval( - "where((a==124), 55, a)", {"a": l4}, name="mark_mangroves", dtype="uint8" - ) - return l4 + return res diff --git a/odc/stats/plugins/lc_level34.py b/odc/stats/plugins/lc_level34.py index 72fa6145..5fe958a3 100644 --- a/odc/stats/plugins/lc_level34.py +++ b/odc/stats/plugins/lc_level34.py @@ -94,9 +94,7 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset: xx, self.bare_threshold, veg_cover ) - l4 = l4_natural_aquatic.natural_auquatic_veg( - l4, lifeform, veg_cover, water_seasonality - ) + l4 = l4_natural_aquatic.natural_auquatic_veg(l4, veg_cover, water_seasonality) level4 = l4_surface.lc_l4_surface(l4, level3, bare_gradation) diff --git a/odc/stats/plugins/lc_veg_class_a1.py b/odc/stats/plugins/lc_veg_class_a1.py index 15186703..00cbdc3f 100644 --- a/odc/stats/plugins/lc_veg_class_a1.py +++ b/odc/stats/plugins/lc_veg_class_a1.py @@ -149,7 +149,7 @@ def l3_class(self, xx: xr.Dataset): {"a": data, "b": l3_mask}, name="intertidal_veg", dtype="uint8", - **{"m": self.output_classes["aquatic_veg"]}, + **{"m": self.output_classes["aquatic_veg_herb"]}, ) elif b == "canopy_cover_class": # aquatic_veg: (mangroves > 0) & (mangroves != nodata) @@ -161,7 +161,7 @@ def l3_class(self, xx: xr.Dataset): dtype="uint8", **{ "nodata": xx[b].attrs["nodata"], - "m": self.output_classes["aquatic_veg"], + "m": self.output_classes["aquatic_veg_wood"], }, ) diff --git a/tests/test_landcover_plugin_a1.py b/tests/test_landcover_plugin_a1.py index 233da316..04b14963 100644 --- a/tests/test_landcover_plugin_a1.py +++ b/tests/test_landcover_plugin_a1.py @@ -128,7 +128,8 @@ def dataset(): def test_l3_classes(dataset): stats_l3 = StatsVegClassL1( output_classes={ - "aquatic_veg": 124, + "aquatic_veg_wood": 124, + "aquatic_veg_herb": 125, "terrestrial_veg": 110, "water": 221, "intertidal": 223, @@ -141,7 +142,7 @@ def test_l3_classes(dataset): expected_res = np.array( [ [ - [223, 221, 210, 124], + [223, 221, 210, 125], [223, 223, 223, 210], [223, 221, 223, 223], [221, 223, 223, 223], @@ -157,7 +158,8 @@ def test_l3_classes(dataset): def test_l4_water_seasonality(dataset): stats_l3 = StatsVegClassL1( output_classes={ - "aquatic_veg": 124, + "aquatic_veg_wood": 124, + "aquatic_veg_herb": 125, "terrestrial_veg": 110, "water": 221, "intertidal": 223, @@ -203,7 +205,8 @@ def test_l4_water_seasonality(dataset): def test_reduce(dataset): stats_l3 = StatsVegClassL1( output_classes={ - "aquatic_veg": 124, + "aquatic_veg_wood": 124, + "aquatic_veg_herb": 125, "terrestrial_veg": 110, "water": 221, "intertidal": 223,