1313from openeo .testing .results import (
1414 _compare_xarray_dataarray ,
1515 assert_job_results_allclose ,
16- assert_xarray_allclose ,
1716 assert_xarray_dataarray_allclose ,
1817 assert_xarray_dataset_allclose ,
1918)
@@ -36,7 +35,6 @@ def test_simple_defaults(self):
3635 [
3736 "Coordinates mismatch for dimension 'dim_0': [0 1 2 3] != [0 1 2]" ,
3837 "Shape mismatch: (4,) != (3,)" ,
39- dirty_equals .IsStr (regex = "Left and right DataArray objects are not close.*" , regex_flags = re .DOTALL ),
4038 ],
4139 ),
4240 (
@@ -45,15 +43,13 @@ def test_simple_defaults(self):
4543 "Dimension mismatch: ('dim_0', 'dim_1') != ('dim_0',)" ,
4644 "Coordinates mismatch for dimension 'dim_0': [0 1] != [0 1 2]" ,
4745 "Shape mismatch: (2, 3) != (3,)" ,
48- dirty_equals .IsStr (regex = "Left and right DataArray objects are not close.*" , regex_flags = re .DOTALL ),
4946 ],
5047 ),
5148 (
5249 xarray .DataArray ([[1 ], [2 ], [3 ]]),
5350 [
5451 "Dimension mismatch: ('dim_0', 'dim_1') != ('dim_0',)" ,
5552 "Shape mismatch: (3, 1) != (3,)" ,
56- dirty_equals .IsStr (regex = "Left and right DataArray objects are not close.*" , regex_flags = re .DOTALL ),
5753 ],
5854 ),
5955 ],
@@ -75,20 +71,12 @@ def test_simple_shape_mismatch(self, actual, expected_issues):
7571 "Dimension mismatch: ('y', 'x') != ('x', 'y')" ,
7672 "Coordinates mismatch for dimension 'x': [0 1 2] != [0 1]" ,
7773 "Coordinates mismatch for dimension 'y': [0 1] != [0 1 2]" ,
78- dirty_equals .IsStr (
79- regex = r"Left and right DataArray objects are not close.*Differing dimensions:.*\(y: 2, x: 3\) != \(x: 2, y: 3\)" ,
80- regex_flags = re .DOTALL ,
81- ),
8274 ],
8375 ),
8476 (
8577 xarray .DataArray ([[1 , 2 , 3 ], [4 , 5 , 6 ]], dims = ["x" , "z" ]),
8678 [
8779 "Dimension mismatch: ('x', 'z') != ('x', 'y')" ,
88- dirty_equals .IsStr (
89- regex = r"Left and right DataArray objects are not close.*Differing dimensions:.*\(x: 2, z: 3\) != \(x: 2, y: 3\)" ,
90- regex_flags = re .DOTALL ,
91- ),
9280 ],
9381 ),
9482 ],
@@ -108,10 +96,6 @@ def test_simple_dims_mismatch(self, actual, expected_issues):
10896 xarray .DataArray ([[1 , 2 , 3 ], [4 , 5 , 6 ]], coords = [("x" , [111 , 222 ]), ("y" , [33 , 44 , 55 ])]),
10997 [
11098 "Coordinates mismatch for dimension 'x': [111 222] != [11 22]" ,
111- dirty_equals .IsStr (
112- regex = r"Left and right DataArray objects are not close.*Differing coordinates:.*L \* x\s+\(x\).*?111 222.*R \* x\s+\(x\).*?11 22" ,
113- regex_flags = re .DOTALL ,
114- ),
11599 ],
116100 ),
117101 ],
@@ -351,6 +335,108 @@ def test_allclose_minimal_success(self, tmp_path, actual_dir, expected_dir):
351335 ds .to_netcdf (actual_dir / "data.nc" )
352336 assert_job_results_allclose (actual = actual_dir , expected = expected_dir , tmp_path = tmp_path )
353337
338+ def test_allclose_xy_success (self , tmp_path , actual_dir , expected_dir ):
339+ expected_ds = xarray .Dataset (
340+ {
341+ "b1" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 2 * numpy .ones ((3 , 4 , 5 ))),
342+ "b2" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 3 * numpy .ones ((3 , 4 , 5 ))),
343+ },
344+ coords = {
345+ "t" : range (0 , 3 ),
346+ "x" : range (4 , 8 ),
347+ "y" : range (5 , 10 ),
348+ },
349+ )
350+ expected_ds .to_netcdf (expected_dir / "data.nc" )
351+ actual_ds = xarray .Dataset (
352+ {
353+ "b1" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 1 * numpy .ones ((3 , 4 , 5 ))),
354+ "b2" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 3 * numpy .ones ((3 , 4 , 5 ))),
355+ },
356+ coords = {
357+ "t" : range (0 , 3 ),
358+ "x" : range (4 , 8 ),
359+ "y" : range (5 , 10 ),
360+ },
361+ )
362+ actual_ds .to_netcdf (actual_dir / "data.nc" )
363+ assert_job_results_allclose (actual = actual_dir , expected = expected_dir , tmp_path = tmp_path , rtol = 1 )
364+
365+ def test_allclose_minimal_xy_different (self , tmp_path , actual_dir , expected_dir ):
366+ expected_ds = xarray .Dataset (
367+ {
368+ "b1" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 2 * numpy .ones ((3 , 4 , 5 ))),
369+ "b2" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 3 * numpy .ones ((3 , 4 , 5 ))),
370+ },
371+ coords = {
372+ "t" : range (0 , 3 ),
373+ "x" : range (4 , 8 ),
374+ "y" : range (5 , 10 ),
375+ },
376+ )
377+ expected_ds .to_netcdf (expected_dir / "data.nc" )
378+ actual_ds = xarray .Dataset (
379+ {
380+ "b1" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 1 * numpy .ones ((3 , 4 , 5 ))),
381+ "b2" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 3 * numpy .ones ((3 , 4 , 5 ))),
382+ },
383+ coords = {
384+ "t" : range (0 , 3 ),
385+ "x" : range (4 , 8 ),
386+ "y" : range (5 , 10 ),
387+ },
388+ )
389+ actual_ds .to_netcdf (actual_dir / "data.nc" )
390+ with raises_assertion_error_or_not (
391+ r"Issues for file 'data.nc'.*"
392+ r"Issues for variable 'b1'.*"
393+ r"t 0: value difference min:1.0, max: 1.0, mean: 1.0, var: 0.0.*"
394+ r"t 0: differing pixels: 20/20 \(100.0%\), spread over 100.0% of the area.*"
395+ r"t 1: value difference min:1.0, max: 1.0, mean: 1.0, var: 0.0.*"
396+ r"t 1: differing pixels: 20/20 \(100.0%\), spread over 100.0% of the area.*"
397+ r"t 2: value difference min:1.0, max: 1.0, mean: 1.0, var: 0.0.*"
398+ r"t 2: differing pixels: 20/20 \(100.0%\), spread over 100.0% of the area"
399+ ):
400+ assert_job_results_allclose (actual = actual_dir , expected = expected_dir , tmp_path = tmp_path )
401+
402+ def test_allclose_minimal_xy_different_small_area (self , tmp_path , actual_dir , expected_dir ):
403+ expected_ds = xarray .Dataset (
404+ {
405+ "b1" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 2 * numpy .ones ((3 , 4 , 5 ))),
406+ "b2" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 3 * numpy .ones ((3 , 4 , 5 ))),
407+ },
408+ coords = {
409+ "t" : range (0 , 3 ),
410+ "x" : range (4 , 8 ),
411+ "y" : range (5 , 10 ),
412+ },
413+ )
414+ expected_ds .to_netcdf (expected_dir / "data.nc" )
415+ b2_modified_data = 3 * numpy .ones ((3 , 4 , 5 ))
416+ b2_modified_data [2 ][2 ][2 ] *= 15
417+ b2_modified_data [2 ][2 ][3 ] *= 14
418+ b2_modified_data [2 ][3 ][2 ] *= 13
419+ b2_modified_data [2 ][3 ][3 ] *= 12
420+ actual_ds = xarray .Dataset (
421+ {
422+ "b1" : xarray .Variable (dims = ["t" , "x" , "y" ], data = 2 * numpy .ones ((3 , 4 , 5 ))),
423+ "b2" : xarray .Variable (dims = ["t" , "x" , "y" ], data = b2_modified_data ),
424+ },
425+ coords = {
426+ "t" : range (0 , 3 ),
427+ "x" : range (4 , 8 ),
428+ "y" : range (5 , 10 ),
429+ },
430+ )
431+ actual_ds .to_netcdf (actual_dir / "data.nc" )
432+ with raises_assertion_error_or_not (
433+ r"Issues for file 'data.nc'.*"
434+ r"Issues for variable 'b2'.*"
435+ r"t 2: value difference min:33.0, max: 42.0, mean: 37.5, var: 11.2.*"
436+ r"t 2: differing pixels: 4/20 \(20.0%\), spread over 8.3% of the area"
437+ ):
438+ assert_job_results_allclose (actual = actual_dir , expected = expected_dir , tmp_path = tmp_path )
439+
354440 def test_allclose_basic_fail (self , tmp_path , actual_dir , expected_dir ):
355441 expected_ds = xarray .Dataset ({"a" : (["time" ], [1 , 2 , 3 ])}, coords = {"time" : [11 , 22 , 33 ]})
356442 expected_ds .to_netcdf (expected_dir / "data.nc" )
0 commit comments