Skip to content

Commit

Permalink
Merge branch 'develop' into fix_veg_water
Browse files Browse the repository at this point in the history
  • Loading branch information
emmaai authored Dec 17, 2024
2 parents 00fdfd9 + 78d8c62 commit 9764122
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
19 changes: 14 additions & 5 deletions odc/stats/plugins/lc_fc_wo_a0.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def native_transform(self, xx):
# clear wet pixels not mask against bit 2: low solar angle
wet = (xx["water"].data & ~(1 << 2)) == 128

# get "valid" wo pixels, both dry and wet used in veg_frequency
wet_valid = expr_eval(
"where(a|b, a, _nan)",
{"a": wet, "b": valid},
name="get_valid_pixels",
dtype="float32",
**{"_nan": np.nan},
)

# clear dry pixels
clear = xx["water"].data == 0

Expand All @@ -72,9 +81,9 @@ def native_transform(self, xx):
raw_mask = mask_cleanup(
raw_mask, mask_filters=self.cloud_filters.get(key)
)
valid = expr_eval(
"where(b>0, 0, a)",
{"a": valid, "b": raw_mask.data},
wet_valid = expr_eval(
"where(b>0, _nan, a)",
{"a": wet_valid, "b": raw_mask.data},
name="get_valid_pixels",
dtype="bool",
)
Expand Down Expand Up @@ -114,9 +123,9 @@ def native_transform(self, xx):

# Pick out the fc pixels that have an unmixing error of less than the threshold
valid = expr_eval(
"where(b<_v, a, 0)",
"where((b>=_v)&(a<=0)|(a!=a), 0, 1)",
{"a": valid, "b": xx["ue"].data},
name="get_low_ue",
name="get_low_ue_wet",
dtype="bool",
**{"_v": self.ue_threshold},
)
Expand Down
57 changes: 43 additions & 14 deletions tests/test_landcover_plugin_a0.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,40 @@ def test_native_transform(fc_wo_dataset, bits):
assert (a == b).all()

result = np.where(out_xx["pv"].data == out_xx["pv"].data)
# fmt: off
expected_valid = (
np.array([0, 0, 2, 3, 3, 3]),
np.array([1, 5, 2, 0, 2, 3]),
np.array([0, 1, 4, 0, 4, 2]),
np.array(
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3,
]
),
np.array(
[
1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 1, 1,
2, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4,
4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 0, 0, 0, 1,
1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5,
5, 5, 6, 6, 6, 6, 6,
]
),
np.array(
[
0, 3, 4, 0, 6, 1, 2, 4, 6, 3, 6, 1, 4, 6, 1, 3, 5, 6,
5, 4, 0, 1, 2, 4, 5, 0, 2, 6, 3, 6, 0, 3, 4, 5, 6, 0,
1, 3, 4, 5, 6, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 0, 1,
3, 4, 6, 1, 2, 4, 5, 0, 1, 2, 3, 4, 5, 6, 0, 2, 5, 1,
3, 4, 5, 6, 0, 2, 3, 4, 1, 2, 5, 6, 0, 1, 3, 5, 0, 1,
3, 4, 0, 1, 2, 3, 5,
]
),
)
# fmt: on

for a, b in zip(expected_valid, result):
assert (a == b).all()
Expand All @@ -352,9 +381,9 @@ def test_fusing(fc_wo_dataset):
np.array([1, 5, 0, 2, 3]),
np.array([0, 1, 0, 4, 2]),
)
pv_valid = np.array([20, 77, 17, 38, 89])
npv_valid = np.array([85, 47, 63, 64, 19])
bs_valid = np.array([10, 46, 37, 25, 43])
pv_valid = np.array([20, 77, 21, 38, 52])
npv_valid = np.array([85, 47, 73, 64, 10])
bs_valid = np.array([10, 46, 48, 25, 56])
i = 0
for idx in zip(*valid_index):
assert xx.pv.data[idx] == pv_valid[i]
Expand All @@ -375,7 +404,7 @@ def test_veg_or_not(fc_wo_dataset):
np.array([1, 5, 0, 2, 3]),
np.array([0, 1, 0, 4, 2]),
)
expected_value = np.array([1, 1, 1, 1, 1])
expected_value = np.array([1, 1, 1, 1, 0])
i = 0
for idx in zip(*valid_index):
assert yy[idx] == expected_value[i]
Expand Down Expand Up @@ -408,13 +437,13 @@ def test_reduce(fc_wo_dataset):
xx = stats_veg.reduce(xx).compute()
expected_value = np.array(
[
[2, 255, 255, 255, 255, 255, 255],
[2, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 2, 255, 255],
[255, 255, 2, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255],
[255, 2, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255],
[2, 255, 2, 2, 2, 2, 2],
[2, 2, 255, 2, 2, 0, 2],
[2, 255, 2, 2, 2, 2, 2],
[255, 2, 2, 2, 3, 2, 2],
[2, 2, 2, 2, 2, 2, 2],
[2, 2, 0, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2, 2],
],
dtype="uint8",
)
Expand Down

0 comments on commit 9764122

Please sign in to comment.