Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 29, 2024
1 parent 1cc0e77 commit e8e7725
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
7 changes: 3 additions & 4 deletions odc/stats/plugins/l34_utils/l4_bare_gradation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

NODATA = 255


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

# Map any data > 100 ---> 100
Expand All @@ -27,8 +28,7 @@ def bare_gradation(xx: xr.Dataset, bare_threshold, veg_cover):
# 20% <= data < 60% --> 12
bs_mask = expr_eval(
"where((a>=m)&(a<n), 12, b)",
{"a": bs_pc_50,
"b": bs_mask},
{"a": bs_pc_50, "b": bs_mask},
name="mark_veg",
dtype="uint8",
**{"m": bare_threshold[0], "n": bare_threshold[1]},
Expand All @@ -37,8 +37,7 @@ def bare_gradation(xx: xr.Dataset, bare_threshold, veg_cover):
# data < 20% --> 10
bs_mask = expr_eval(
"where(a<m, 10, b)",
{"a": bs_pc_50,
"b": bs_mask},
{"a": bs_pc_50, "b": bs_mask},
name="mark_veg",
dtype="uint8",
**{"m": bare_threshold[0]},
Expand Down
40 changes: 27 additions & 13 deletions odc/stats/plugins/l34_utils/l4_veg_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ def canopyco_veg_con(xx: xr.Dataset, veg_threshold):
# Map any data > 100 ---> 100
pv_pc_50 = expr_eval(
"where((a>100) & (a!=nodata), 100, a)",
{"a": pv_pc_50,},
{
"a": pv_pc_50,
},
name="mark_veg",
dtype="uint8",
**{"nodata": NODATA},
)

# ## data < 1 ---> 0
veg_mask = expr_eval(
"where(a<m, 0, a)",
{"a": pv_pc_50,},
{
"a": pv_pc_50,
},
name="mark_veg",
dtype="uint8",
**{"m": veg_threshold[0]},
Expand All @@ -37,8 +41,10 @@ def canopyco_veg_con(xx: xr.Dataset, veg_threshold):
# [1-4) --> 16
veg_mask = expr_eval(
"where((a>=m)&(a<n), 16, b)",
{"a": pv_pc_50,
"b": veg_mask,},
{
"a": pv_pc_50,
"b": veg_mask,
},
name="mark_veg",
dtype="uint8",
**{"m": veg_threshold[0], "n": veg_threshold[1]},
Expand All @@ -47,8 +53,10 @@ def canopyco_veg_con(xx: xr.Dataset, veg_threshold):
# [4-15) --> 15
veg_mask = expr_eval(
"where((a>=m)&(a<n), 15, b)",
{"a": pv_pc_50,
"b": veg_mask,},
{
"a": pv_pc_50,
"b": veg_mask,
},
name="mark_veg",
dtype="uint8",
**{"m": veg_threshold[1], "n": veg_threshold[2]},
Expand All @@ -57,8 +65,10 @@ def canopyco_veg_con(xx: xr.Dataset, veg_threshold):
# [15-40) --> 13
veg_mask = expr_eval(
"where((a>=m)&(a<n), 13, b)",
{"a": pv_pc_50,
"b": veg_mask,},
{
"a": pv_pc_50,
"b": veg_mask,
},
name="mark_veg",
dtype="uint8",
**{"m": veg_threshold[2], "n": veg_threshold[3]},
Expand All @@ -67,8 +77,10 @@ def canopyco_veg_con(xx: xr.Dataset, veg_threshold):
# [40-65) --> 12
veg_mask = expr_eval(
"where((a>=m)&(a<n), 12, b)",
{"a": pv_pc_50,
"b": veg_mask,},
{
"a": pv_pc_50,
"b": veg_mask,
},
name="mark_veg",
dtype="uint8",
**{"m": veg_threshold[3], "n": veg_threshold[4]},
Expand All @@ -77,8 +89,10 @@ def canopyco_veg_con(xx: xr.Dataset, veg_threshold):
# 65-100 --> 10
veg_mask = expr_eval(
"where((a>=m)&(a<n), 10, b)",
{"a": pv_pc_50,
"b": veg_mask,},
{
"a": pv_pc_50,
"b": veg_mask,
},
name="mark_veg",
dtype="uint8",
**{"m": veg_threshold[4], "n": veg_threshold[5]},
Expand Down
18 changes: 10 additions & 8 deletions odc/stats/plugins/l34_utils/l4_water_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
NODATA = 255
WATRE_FREQ_NODATA = -999


def water_persistence(xx: xr.Dataset, watper_threshold):

# Apply nodata
Expand All @@ -14,9 +15,13 @@ def water_persistence(xx: xr.Dataset, watper_threshold):
{"a": xx.water_frequency.data},
name="mark_water",
dtype="uint8",
**{"m": watper_threshold[3], "nodata": NODATA, "water_freq_nodata": WATRE_FREQ_NODATA},
**{
"m": watper_threshold[3],
"nodata": NODATA,
"water_freq_nodata": WATRE_FREQ_NODATA,
},
)

# 10 <= water_frequency < 1 --> 1
water_mask = expr_eval(
"where((a>=m)&(a!=nodata), 1, a)",
Expand All @@ -29,8 +34,7 @@ def water_persistence(xx: xr.Dataset, watper_threshold):
# 7 <= water_frequency < 10 --> 7
water_mask = expr_eval(
"where((a>=m)&(a<n), 7, b)",
{"a": water_frequency,
"b": water_mask},
{"a": water_frequency, "b": water_mask},
name="mark_water",
dtype="uint8",
**{"m": watper_threshold[2], "n": watper_threshold[3]},
Expand All @@ -39,8 +43,7 @@ def water_persistence(xx: xr.Dataset, watper_threshold):
# 4 <= water_frequency < 7 --> 8
water_mask = expr_eval(
"where((a>=m)&(a<n), 8, b)",
{"a": water_frequency,
"b": water_mask},
{"a": water_frequency, "b": water_mask},
name="mark_water",
dtype="uint8",
**{"m": watper_threshold[1], "n": watper_threshold[2]},
Expand All @@ -49,8 +52,7 @@ def water_persistence(xx: xr.Dataset, watper_threshold):
# 1 <= water_frequency < 4 --> 9
water_mask = expr_eval(
"where((a>=m)&(a<n), 9, b)",
{"a": water_frequency,
"b": water_mask},
{"a": water_frequency, "b": water_mask},
name="mark_water",
dtype="uint8",
**{"m": watper_threshold[0], "n": watper_threshold[1]},
Expand Down
11 changes: 3 additions & 8 deletions odc/stats/plugins/l34_utils/lc_water_seasonality.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@ def water_seasonality(xx: xr.Dataset, water_seasonality_threshold):
{"a": xx.water_frequency.data},
name="mark_water_season",
dtype="uint8",
**{
"watersea_nodata": WATER_FREQ_NODATA,
"nodata": NODATA
},
**{"watersea_nodata": WATER_FREQ_NODATA, "nodata": NODATA},
)

water_season_mask = expr_eval(
"where((a>watseas_trh)&(a<=12), 1, a)",
{"a": water_frequency},
name="mark_water_season",
dtype="uint8",
**{"watseas_trh": water_seasonality_threshold,
"nodata": NODATA},
**{"watseas_trh": water_seasonality_threshold, "nodata": NODATA},
)
water_season_mask = expr_eval(
"where((a<=watseas_trh)&(a<=12), 2, b)",
{"a": water_frequency,
"b": water_season_mask},
{"a": water_frequency, "b": water_season_mask},
name="mark_water_season",
dtype="uint8",
**{"watseas_trh": water_seasonality_threshold},
Expand Down

0 comments on commit e8e7725

Please sign in to comment.