Skip to content

Commit

Permalink
Changed the band names to match the config files. Also updated vegeta…
Browse files Browse the repository at this point in the history
…tion , lifeform and water seasonality to correctly replace nodata
  • Loading branch information
tebadi committed Nov 15, 2024
1 parent 9ecc309 commit b32c962
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions odc/stats/plugins/l34_utils/l4_veg_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)

Expand Down
4 changes: 2 additions & 2 deletions odc/stats/plugins/l34_utils/lc_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion odc/stats/plugins/l34_utils/lc_lifeform.py
Original file line number Diff line number Diff line change
@@ -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",
)
Expand Down
8 changes: 4 additions & 4 deletions odc/stats/plugins/l34_utils/lc_water_seasonality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lc_l34.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
5 changes: 3 additions & 2 deletions tests/test_lc_l4_ctv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions tests/test_lc_l4_natural_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lc_l4_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lc_l4_ntv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lc_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit b32c962

Please sign in to comment.