diff --git a/odc/stats/plugins/l34_utils/l4_veg_cover.py b/odc/stats/plugins/l34_utils/l4_veg_cover.py index b2837491..7f194444 100644 --- a/odc/stats/plugins/l34_utils/l4_veg_cover.py +++ b/odc/stats/plugins/l34_utils/l4_veg_cover.py @@ -9,10 +9,10 @@ def canopyco_veg_con(xx: xr.Dataset, veg_threshold): # Mask NODATA pv_pc_50 = expr_eval( - "where(a!=nodata, a, nodata)", + "where(a==a, a, nodata)", {"a": xx.pv_pc_50.data}, name="mark_nodata", - dtype="uint8", + dtype="float32", **{"nodata": NODATA}, ) diff --git a/odc/stats/plugins/l34_utils/lc_level3.py b/odc/stats/plugins/l34_utils/lc_level3.py index 796d2fde..146a64fc 100644 --- a/odc/stats/plugins/l34_utils/lc_level3.py +++ b/odc/stats/plugins/l34_utils/lc_level3.py @@ -14,10 +14,10 @@ def lc_level3(xx: xr.Dataset): res = expr_eval( "where((a!=a)|(a>=nodata), b, a)", - {"a": xx.cultivated_class.data, "b": xx.classes_l3_l4.data}, + {"a": xx.cultivated.data, "b": xx.classes_l3_l4.data}, name="mask_cultivated", dtype="float32", - **{"nodata": xx.cultivated_class.attrs.get("nodata")}, + **{"nodata": xx.cultivated.attrs.get("nodata")}, ) # Mask urban results with bare sfc (210) diff --git a/odc/stats/plugins/l34_utils/lc_lifeform.py b/odc/stats/plugins/l34_utils/lc_lifeform.py index 152ad968..53378be1 100644 --- a/odc/stats/plugins/l34_utils/lc_lifeform.py +++ b/odc/stats/plugins/l34_utils/lc_lifeform.py @@ -1,14 +1,25 @@ from odc.stats._algebra import expr_eval import xarray as xr +NODATA = 255 + def lifeform(xx: xr.Dataset): # 113 ----> 1 woody # 114 ----> 2 herbaceous + + lifeform_mask = expr_eval( + "where((a!=a)|(a>=nodata), nodata, a)", + {"a": xx.woody.data}, + name="mark_lifeform", + dtype="float32", + **{"nodata": NODATA}, + ) + lifeform_mask = expr_eval( "where(a==113, 1, a)", - {"a": xx.woody_cover.data}, + {"a": lifeform_mask}, name="mark_lifeform", dtype="uint8", ) diff --git a/odc/stats/plugins/l34_utils/lc_water_seasonality.py b/odc/stats/plugins/l34_utils/lc_water_seasonality.py index b727831d..23db8922 100644 --- a/odc/stats/plugins/l34_utils/lc_water_seasonality.py +++ b/odc/stats/plugins/l34_utils/lc_water_seasonality.py @@ -12,11 +12,11 @@ def water_seasonality(xx: xr.Dataset, water_seasonality_threshold): # Apply nodata water_frequency = expr_eval( - "where((a==watersea_nodata), nodata, a)", + "where((a!=a)|(a==watersea_nodata), nodata, a)", {"a": xx.water_frequency.data}, - name="mark_water_season", - dtype="uint8", - **{"watersea_nodata": WATER_FREQ_NODATA, "nodata": NODATA}, + name="mark_lifeform", + dtype="float32", + **{"nodata": NODATA, "watersea_nodata": WATER_FREQ_NODATA}, ) water_season_mask = expr_eval( diff --git a/tests/test_lc_l34.py b/tests/test_lc_l34.py index 96f1f278..4fba2fb5 100644 --- a/tests/test_lc_l34.py +++ b/tests/test_lc_l34.py @@ -116,12 +116,12 @@ def image_groups(): dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "cultivated_class": xr.DataArray( + "cultivated": xr.DataArray( da.from_array(cultivated, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "woody_cover": xr.DataArray( + "woody": xr.DataArray( da.from_array(woody, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, diff --git a/tests/test_lc_l4_ctv.py b/tests/test_lc_l4_ctv.py index b005b71a..6e160220 100644 --- a/tests/test_lc_l4_ctv.py +++ b/tests/test_lc_l4_ctv.py @@ -37,12 +37,12 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50): dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "cultivated_class": xr.DataArray( + "cultivated": xr.DataArray( da.from_array(cultivated, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "woody_cover": xr.DataArray( + "woody": xr.DataArray( da.from_array(woody, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, @@ -300,6 +300,7 @@ def test_ctv_classes_woody_herbaceous(): l4_ctv = l4_cultivated.lc_l4_cultivated( xx.classes_l3_l4, level3, lifeform, veg_cover ) + assert (l4_ctv.compute() == expected_cultivated_classes).all() diff --git a/tests/test_lc_l4_natural_surface.py b/tests/test_lc_l4_natural_surface.py index e8b3d528..be48c7d2 100644 --- a/tests/test_lc_l4_natural_surface.py +++ b/tests/test_lc_l4_natural_surface.py @@ -46,12 +46,12 @@ def image_groups(l34, urban, woody, bs_pc_50, pv_pc_50, cultivated, water_freque dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "cultivated_class": xr.DataArray( + "cultivated": xr.DataArray( da.from_array(cultivated, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "woody_cover": xr.DataArray( + "woody": xr.DataArray( da.from_array(woody, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, diff --git a/tests/test_lc_l4_nav.py b/tests/test_lc_l4_nav.py index 2d883ae2..c8debe17 100644 --- a/tests/test_lc_l4_nav.py +++ b/tests/test_lc_l4_nav.py @@ -44,12 +44,12 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency): dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "cultivated_class": xr.DataArray( + "cultivated": xr.DataArray( da.from_array(cultivated, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "woody_cover": xr.DataArray( + "woody": xr.DataArray( da.from_array(woody, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, diff --git a/tests/test_lc_l4_ntv.py b/tests/test_lc_l4_ntv.py index 2154e73b..e4761908 100644 --- a/tests/test_lc_l4_ntv.py +++ b/tests/test_lc_l4_ntv.py @@ -41,12 +41,12 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50): dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "cultivated_class": xr.DataArray( + "cultivated": xr.DataArray( da.from_array(cultivated, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "woody_cover": xr.DataArray( + "woody": xr.DataArray( da.from_array(woody, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255}, diff --git a/tests/test_lc_level3.py b/tests/test_lc_level3.py index c46f8935..1906c758 100644 --- a/tests/test_lc_level3.py +++ b/tests/test_lc_level3.py @@ -74,7 +74,7 @@ def image_groups(): dims=("spec", "y", "x"), attrs={"nodata": 255}, ), - "cultivated_class": xr.DataArray( + "cultivated": xr.DataArray( da.from_array(cultivated, chunks=(1, -1, -1)), dims=("spec", "y", "x"), attrs={"nodata": 255},