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 Nov 21, 2024
1 parent 055cbfa commit 93dfded
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
10 changes: 5 additions & 5 deletions odc/stats/plugins/l34_utils/l4_natural_aquatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

NODATA = 255


def natural_auquatic_veg(l4, veg_cover, water_season):

# mark woody/herbaceous
Expand All @@ -19,9 +20,9 @@ def natural_auquatic_veg(l4, veg_cover, water_season):
},
name="mark_water_season",
dtype="float32",
**{"nodata": NODATA},
**{"nodata": NODATA},
)

res = expr_eval(
"where((a==124), 56, a)",
{
Expand Down Expand Up @@ -283,7 +284,7 @@ def natural_auquatic_veg(l4, veg_cover, water_season):
name="mark_final",
dtype="uint8",
)

res = expr_eval(
"where((a==251)&(b==16), 92, a)",
{
Expand All @@ -294,7 +295,7 @@ def natural_auquatic_veg(l4, veg_cover, water_season):
dtype="uint8",
)

# There are cases where a tile falls over water.
# There are cases where a tile falls over water.
# In these cases, the PC will have no data so we map back 251-254 to their corresponding classes
res = expr_eval(
"where((a>=251)&(a<=252), 57, a)",
Expand All @@ -312,6 +313,5 @@ def natural_auquatic_veg(l4, veg_cover, water_season):
name="mark_final",
dtype="uint8",
)


return res
1 change: 0 additions & 1 deletion odc/stats/plugins/l34_utils/l4_veg_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

def canopyco_veg_con(xx: xr.Dataset, veg_threshold):


# Mask NODATA
pv_pc_50 = expr_eval(
"where(a==a, a, nodata)",
Expand Down
19 changes: 8 additions & 11 deletions odc/stats/plugins/l34_utils/l4_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ def water_classification(xx, intertidal_mask, water_persistence):

# Replace nan with nodata
l4 = expr_eval(
"where((a==a), a, nodata)",
{"a": xx.level_3_4.data},
name="mark_water",
dtype="uint8",
**{"nodata": NODATA},
"where((a==a), a, nodata)",
{"a": xx.level_3_4.data},
name="mark_water",
dtype="uint8",
**{"nodata": NODATA},
)

l4 = expr_eval(
"where((a==223)|(a==221), 98, a)",
{"a": l4},
name="mark_water",
dtype="uint8"
"where((a==223)|(a==221), 98, a)", {"a": l4}, name="mark_water", dtype="uint8"
)

l4 = expr_eval(
"where((a==98)&(b!=1), 99, a)",
{"a": l4, "b": intertidal_mask},
name="mark_water",
dtype="uint8",
)

l4 = expr_eval(
"where((a==98)&(b==1), 100, a)",
{"a": l4, "b": intertidal_mask},
Expand Down
12 changes: 6 additions & 6 deletions odc/stats/plugins/lc_level34.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

NODATA = 255


class StatsLccsLevel4(StatsPluginInterface):
NAME = "ga_ls_lccs_Level34"
SHORT_NAME = NAME
Expand All @@ -48,7 +49,6 @@ def __init__(
self.watper_threshold = (
watper_threshold if watper_threshold is not None else [1, 4, 7, 10]
)


def fuser(self, xx):
return xx
Expand All @@ -59,15 +59,15 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:
water_persistence = l4_water_persistence.water_persistence(
xx, self.watper_threshold
)

intertidal_mask = lc_intertidal_mask.intertidal_mask(xx)

# #TODO WATER (99-104)
l4 = l4_water.water_classification(xx, intertidal_mask, water_persistence)

# Generate Level3 classes
level3 = lc_level3.lc_level3(xx)

# Vegetation cover
veg_cover = l4_veg_cover.canopyco_veg_con(xx, self.veg_threshold)

Expand All @@ -79,7 +79,7 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:

# Apply terrestrial vegetation classes [19-36]
l4 = l4_natural_veg.lc_l4_natural_veg(l4, level3, lifeform, veg_cover)

# Bare gradation
bare_gradation = l4_bare_gradation.bare_gradation(
xx, self.bare_threshold, veg_cover
Expand All @@ -91,7 +91,7 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:

level3 = level3.astype(np.uint8)
level4 = level4.astype(np.uint8)

attrs = xx.attrs.copy()
attrs["nodata"] = NODATA
dims = xx.level_3_4.dims[1:]
Expand All @@ -105,4 +105,4 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:
return leve34


register("lc_l3_l4", StatsLccsLevel4)
register("lc_l3_l4", StatsLccsLevel4)
2 changes: 1 addition & 1 deletion tests/test_lc_l34.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def image_groups():
def test_l4_classes(image_groups):
expected_l3 = [[216, 216, 215], [216, 216, 216], [220, 215, 215], [220, 220, 220]]

expected_l4 = [[ 95, 97, 93], [97, 96, 96], [100, 93, 93], [101, 101, 101]]
expected_l4 = [[95, 97, 93], [97, 96, 96], [100, 93, 93], [101, 101, 101]]
stats_l4 = StatsLccsLevel4(measurements=["level3", "level4"])
ds = stats_l4.reduce(image_groups)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_lc_l4_natural_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
NODATA = 255


def image_groups(l34, urban, woody, bs_pc_50, pv_pc_50, cultivated, water_frequency, water_season):
def image_groups(
l34, urban, woody, bs_pc_50, pv_pc_50, cultivated, water_frequency, water_season
):

tuples = [
(np.datetime64("2000-01-01T00"), np.datetime64("2000-01-01")),
Expand Down Expand Up @@ -70,7 +72,7 @@ def image_groups(l34, urban, woody, bs_pc_50, pv_pc_50, cultivated, water_freque
dims=("spec", "y", "x"),
attrs={"nodata": 255},
),
"water_season": xr.DataArray(
"water_season": xr.DataArray(
da.from_array(water_season, chunks=(1, -1, -1)),
dims=("spec", "y", "x"),
attrs={"nodata": 255},
Expand Down
29 changes: 18 additions & 11 deletions tests/test_lc_l4_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
NODATA = 255


def image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season):
def image_groups(
l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season
):

tuples = [
(np.datetime64("2000-01-01T00"), np.datetime64("2000-01-01")),
Expand Down Expand Up @@ -63,7 +65,7 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency, water
dims=("spec", "y", "x"),
attrs={"nodata": 255},
),
"water_season":xr.DataArray(
"water_season": xr.DataArray(
da.from_array(water_season, chunks=(1, -1, -1)),
dims=("spec", "y", "x"),
attrs={"nodata": 255},
Expand Down Expand Up @@ -148,7 +150,7 @@ def test_ntv_classes_woody_herbaceous():
],
dtype="uint8",
)

water_season = np.array(
[
[
Expand All @@ -161,7 +163,9 @@ def test_ntv_classes_woody_herbaceous():
dtype="uint8",
)

xx = image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season)
xx = image_groups(
l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season
)

stats_l4 = StatsLccsLevel4()
level3 = lc_level3.lc_level3(xx)
Expand Down Expand Up @@ -245,7 +249,6 @@ def test_ntv_herbaceous_seasonal_water_veg_cover():
]
],
dtype="uint8",

)
water_frequency = np.array(
[
Expand All @@ -258,7 +261,7 @@ def test_ntv_herbaceous_seasonal_water_veg_cover():
],
dtype="uint8",
)

water_season = np.array(
[
[
Expand All @@ -271,7 +274,9 @@ def test_ntv_herbaceous_seasonal_water_veg_cover():
dtype="uint8",
)

xx = image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season)
xx = image_groups(
l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season
)

stats_l4 = StatsLccsLevel4()
level3 = lc_level3.lc_level3(xx)
Expand All @@ -285,7 +290,7 @@ def test_ntv_herbaceous_seasonal_water_veg_cover():
l4_ctv_ntv_nav = l4_natural_aquatic.natural_auquatic_veg(
l4_ctv_ntv, veg_cover, xx.water_season
)

assert (l4_ctv_ntv_nav.compute() == expected_l4_ntv_classes).all()


Expand Down Expand Up @@ -356,7 +361,7 @@ def test_ntv_woody_seasonal_water_veg_cover():
],
dtype="uint8",
)

water_frequency = np.array(
[
[
Expand All @@ -368,7 +373,7 @@ def test_ntv_woody_seasonal_water_veg_cover():
],
dtype="uint8",
)

water_season = np.array(
[
[
Expand All @@ -380,7 +385,9 @@ def test_ntv_woody_seasonal_water_veg_cover():
],
dtype="uint8",
)
xx = image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season)
xx = image_groups(
l34, urban, cultivated, woody, pv_pc_50, water_frequency, water_season
)

stats_l4 = StatsLccsLevel4()
level3 = lc_level3.lc_level3(xx)
Expand Down
15 changes: 5 additions & 10 deletions tests/test_lc_l4_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ def image_groups(l34, urban, cultivated, woody, bs_pc_50, pv_pc_50, water_freque

def test_water_classes():
expected_water_classes = [
[
[104, 104, 104],
[103, 103, 103],
[102, 102, 101],
[99, 101, 101]
],
[[104, 104, 104], [103, 103, 103], [102, 102, 101], [99, 101, 101]],
]

l34 = np.array(
Expand Down Expand Up @@ -185,10 +180,10 @@ def test_water_classes():
def test_water_intertidal():

expected_water_classes = [
[100, 100, 100],
[100, 100, 100],
[102, 102, 101],
[101, 99, 100],
[100, 100, 100],
[100, 100, 100],
[102, 102, 101],
[101, 99, 100],
]

l34 = np.array(
Expand Down

0 comments on commit 93dfded

Please sign in to comment.