@@ -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
0 commit comments