Skip to content

Commit

Permalink
Revert "fix nodata ring along the water (#177)"
Browse files Browse the repository at this point in the history
This reverts commit 78d8c62.
  • Loading branch information
Emma Ai committed Dec 17, 2024
1 parent 78d8c62 commit 2bf85c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 62 deletions.
26 changes: 7 additions & 19 deletions odc/stats/plugins/lc_fc_wo_a0.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ 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 @@ -90,13 +81,12 @@ def native_transform(self, xx):
raw_mask = mask_cleanup(
raw_mask, mask_filters=self.cloud_filters.get(key)
)
wet_valid = expr_eval(
"where(b>0, _nan, a)",
{"a": wet_valid, "b": raw_mask.data},
valid = expr_eval(
"where(b>0, 0, a)",
{"a": valid, "b": raw_mask.data},
name="get_valid_pixels",
dtype="float32",
dtype="uint8",
)

wet_clear = expr_eval(
"where(b>0, _nan, a)",
{"a": wet_clear, "b": raw_mask.data},
Expand All @@ -107,13 +97,11 @@ def native_transform(self, xx):

xx = xx.drop_vars(["water"])

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

result = np.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for a, b in zip(expected_valid, result):
assert (a == b).all()
Expand All @@ -377,9 +348,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, 21, 38, 52])
npv_valid = np.array([85, 47, 73, 64, 10])
bs_valid = np.array([10, 46, 48, 25, 56])
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])
i = 0
for idx in zip(*valid_index):
assert xx.pv.data[idx] == pv_valid[i]
Expand All @@ -398,7 +369,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, 0])
expected_value = np.array([1, 1, 1, 1, 1])
i = 0
for idx in zip(*valid_index):
assert yy[idx] == expected_value[i]
Expand Down Expand Up @@ -429,13 +400,13 @@ def test_reduce(fc_wo_dataset):
xx = stats_veg.reduce(xx).compute()
expected_value = np.array(
[
[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],
[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],
],
dtype="uint8",
)
Expand Down

0 comments on commit 2bf85c4

Please sign in to comment.