Skip to content

Commit 4ee77e7

Browse files
manugvsoxofaan
authored andcommitted
Implemented suggested changes.
1 parent 00ab659 commit 4ee77e7

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

openeo/testing/results.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,15 @@ def _compare_xarray_dataarray(
233233
issues.append(f"Shape mismatch: {actual.shape} != {expected.shape}")
234234
compatible = len(issues) == 0
235235
try:
236-
if (pixel_tolerance > _DEFAULT_PIXELTOL) and compatible:
237-
_bad_pixels = (actual * 1.0 - expected * 1.0) > atol
236+
if pixel_tolerance and compatible:
237+
threshold = abs(expected * rtol) + atol
238+
bad_pixels = abs(actual * 1.0 - expected * 1.0) > threshold
239+
percentage_bad_pixels = bad_pixels.mean().item() * 100
238240
assert (
239-
_bad_pixels.mean().item() * 100 <= pixel_tolerance
240-
), "Percentage number of pixels that are different is above the threshold"
241+
percentage_bad_pixels <= pixel_tolerance
242+
), f"{percentage_bad_pixels:.3f}% of pixels that are different and this is above the threshold of {pixel_tolerance:.3f}%"
241243
xarray.testing.assert_allclose(
242-
a=actual.where(~_bad_pixels), b=expected.where(~_bad_pixels), rtol=rtol, atol=atol
244+
a=actual.where(~bad_pixels), b=expected.where(~bad_pixels), rtol=rtol, atol=atol
243245
)
244246
else:
245247
xarray.testing.assert_allclose(a=actual, b=expected, rtol=rtol, atol=atol)
@@ -495,7 +497,7 @@ def assert_job_results_allclose(
495497
:py:meth:`~openeo.rest.job.JobResults` object or path to directory with downloaded assets.
496498
:param rtol: relative tolerance
497499
:param atol: absolute tolerance
498-
:param pixel_tolerance: allowable tolerance for fraction of pixels in percentage
500+
:param pixel_tolerance: maximum fracton of pixels (in percent) that is allowed to be different (considering ``atol`` and ``rtol``)
499501
:param tmp_path: root temp path to download results if needed.
500502
It's recommended to pass pytest's `tmp_path` fixture here
501503
:raises AssertionError: if not equal within the given tolerance

tests/testing/test_results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ def test_simple_atol(self, actual, atol, expected_issues):
154154
@pytest.mark.parametrize(
155155
["actual", "atol", "pixel_tolerance", "expected_issues"],
156156
[
157-
(xarray.DataArray([1, 2, 3.001, 4, 5]), 1e-4, 21.0, []),
157+
(xarray.DataArray([1, 2, 300, 4, 5]), 1e-4, 21.0, []),
158158
(xarray.DataArray([1, 2, 3.00001, 4.1, 5]), 1e-4, 21, []),
159159
(
160160
xarray.DataArray([1, 2, 3.001, 4.1, 5]),
161161
1e-4,
162162
21,
163163
[
164164
dirty_equals.IsStr(
165-
regex=r"Percentage number of pixels that are different is above the threshold",
165+
regex=r"40.000% of pixels that are different and this is above the threshold of 21.000%",
166166
regex_flags=re.DOTALL,
167167
)
168168
],

0 commit comments

Comments
 (0)