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

Add Level-3 and Level-4 bands for Land Cover product. #161

Merged
merged 24 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
65255b6
Added Level4 classes
tebadi Oct 17, 2024
a3d8aed
Added unit tests for cultivated terrestrial vegetation
tebadi Oct 18, 2024
6f0e1d4
Added unit tests for natural terrestrial vegetation and cultivated te…
tebadi Oct 21, 2024
ea77c14
Added unit tests for natural terrestrial vegetation and cultivated te…
tebadi Oct 21, 2024
39d4764
Added level-4 water classes
tebadi Oct 22, 2024
873a5bc
Cleaned up inconsistencies between the land cover modules
tebadi Oct 22, 2024
9ed392f
Improved class names and applied some other clean-ups.
tebadi Oct 23, 2024
3e26a67
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
e48a209
Merge branch 'develop' into lc_l34
tebadi Oct 23, 2024
83f493a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
52a9fc5
Added more improvement on level3 and level4
tebadi Oct 23, 2024
9a6c987
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
cd3b38e
Applied formatting and code improvements
tebadi Oct 24, 2024
eb5cfe8
Further modularised the level4
tebadi Oct 24, 2024
b8efeb0
Added an integration test for level 4. Also changed data types in uni…
tebadi Oct 25, 2024
e692b48
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2024
6311a8b
Applied linting and formatting
tebadi Oct 25, 2024
b35af9e
Applied fixes and improvements based on review comments
tebadi Oct 29, 2024
40ab398
Removed commented code
tebadi Oct 29, 2024
1cc0e77
Resolved a conflict
tebadi Oct 29, 2024
e8e7725
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
3c7944b
Applied formatting changes
tebadi Oct 29, 2024
e492d6e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
15f0eba
Fixed a unit test
tebadi Oct 29, 2024
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
3 changes: 2 additions & 1 deletion odc/stats/plugins/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ def import_all():

# TODO: make that more automatic
modules = [
"odc.stats.plugins.lc_treelite_cultivated.py",
"odc.stats.plugins.lc_treelite_cultivated",
"odc.stats.plugins.lc_level3",
"odc.stats.plugins.lc_treelite_woody",
"odc.stats.plugins.lc_tf_urban",
"odc.stats.plugins.lc_level34",
"odc.stats.plugins.lc_veg_class_a1",
"odc.stats.plugins.lc_fc_wo_a0",
"odc.stats.plugins.mangroves",
Expand Down
Empty file.
46 changes: 46 additions & 0 deletions odc/stats/plugins/l34_utils/l4_bare_gradation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import xarray as xr
from odc.stats._algebra import expr_eval


NODATA = 255


def bare_gradation(xx: xr.Dataset, bare_threshold, veg_cover):

# Map any data > 100 ---> 100
bs_pc_50 = expr_eval(
"where((a>100)&(a!=nodata), 100, a)",
{"a": xx.bs_pc_50.data},
name="mark_veg",
dtype="uint8",
**{"nodata": NODATA},
)

# 60% <= data --> 15
bs_mask = expr_eval(
"where((a>=m)&(a!=nodata), 15, a)",
{"a": bs_pc_50},
name="mark_veg",
dtype="uint8",
**{"m": bare_threshold[1], "nodata": NODATA},
)

# 20% <= data < 60% --> 12
bs_mask = expr_eval(
"where((a>=m)&(a<n), 12, b)",
{"a": bs_pc_50, "b": bs_mask},
name="mark_veg",
dtype="uint8",
**{"m": bare_threshold[0], "n": bare_threshold[1]},
)

# data < 20% --> 10
bs_mask = expr_eval(
"where(a<m, 10, b)",
{"a": bs_pc_50, "b": bs_mask},
name="mark_veg",
dtype="uint8",
**{"m": bare_threshold[0]},
)

return bs_mask
97 changes: 97 additions & 0 deletions odc/stats/plugins/l34_utils/l4_cultivated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from odc.stats._algebra import expr_eval

NODATA = 255


def lc_l4_cultivated(l34, level3, lifeform, veg_cover):

l4 = expr_eval(
"where((d==110)&(a==111)&(b==10)&(c==1), 9, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l34},
name="mark_cultivated",
dtype="uint8",
)

l4 = expr_eval(
"where((d==110)&(a==111)&(b==12)&(c==1), 10, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)
l4 = expr_eval(
"where((d==110)&(a==111)&(b==13)&(c==1), 11, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)
l4 = expr_eval(
"where((d==110)&(a==111)&(b==15)&(c==1), 12, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)

l4 = expr_eval(
"where((d==110)&(a==111)&(b==16)&(c==1), 13, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)

l4 = expr_eval(
"where((d==110)&(a==111)&(b==10)&(c==2), 14, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)
l4 = expr_eval(
"where((d==110)&(a==111)&(b==12)&(c==2), 15, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)
l4 = expr_eval(
"where((d==110)&(a==111)&(b==13)&(c==2), 16, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)
l4 = expr_eval(
"where((d==110)&(a==111)&(b==15)&(c==2), 17, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)

l4 = expr_eval(
"where((d==110)&(a==111)&(b==16)&(c==2), 18, d)",
{"a": level3, "b": veg_cover, "c": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)

l4 = expr_eval(
"where((d==110)&(a==111)&(b==1), 2, d)",
{"a": level3, "b": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)

l4 = expr_eval(
"where((d==110)&(a==111)&(b==2), 3, d)",
{"a": level3, "b": lifeform, "d": l4},
name="mark_cultivated",
dtype="uint8",
)

# the 4-8 classes can't happen in LC since cultivated class will not be classified if vegetation doesn't exist.
# skip these classes in level4

l4 = expr_eval(
"where((d==110)&(a==111), 1, d)",
{"a": level3, "d": l4},
name="mark_cultivated",
dtype="uint8",
)

return l4
Loading
Loading