Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the band names and fix the nodata in a few LC modules. #169

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
379 changes: 130 additions & 249 deletions odc/stats/plugins/l34_utils/l4_natural_aquatic.py

Large diffs are not rendered by default.

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
6 changes: 3 additions & 3 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},
dtype="float32",
**{"nodata": NODATA, "watersea_nodata": WATER_FREQ_NODATA},
)

water_season_mask = expr_eval(
Expand Down
4 changes: 1 addition & 3 deletions odc/stats/plugins/lc_level34.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions odc/stats/plugins/lc_veg_class_a1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"],
},
)

Expand Down
11 changes: 7 additions & 4 deletions tests/test_landcover_plugin_a1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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],
Expand All @@ -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,
Expand Down Expand Up @@ -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,
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
6 changes: 3 additions & 3 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 Expand Up @@ -188,7 +188,7 @@ def test_ns():
xx, stats_l4.water_seasonality_threshold
)
l4_ctv_ntv_nav = l4_natural_aquatic.natural_auquatic_veg(
l4_ctv_ntv, lifeform, veg_cover, water_seasonality
l4_ctv_ntv, veg_cover, water_seasonality
)

# Bare gradation
Expand Down
Loading
Loading