13
13
from openeo .testing .results import (
14
14
_compare_xarray_dataarray ,
15
15
assert_job_results_allclose ,
16
- assert_xarray_allclose ,
17
16
assert_xarray_dataarray_allclose ,
18
17
assert_xarray_dataset_allclose ,
19
18
)
@@ -36,7 +35,6 @@ def test_simple_defaults(self):
36
35
[
37
36
"Coordinates mismatch for dimension 'dim_0': [0 1 2 3] != [0 1 2]" ,
38
37
"Shape mismatch: (4,) != (3,)" ,
39
- dirty_equals .IsStr (regex = "Left and right DataArray objects are not close.*" , regex_flags = re .DOTALL ),
40
38
],
41
39
),
42
40
(
@@ -45,15 +43,13 @@ def test_simple_defaults(self):
45
43
"Dimension mismatch: ('dim_0', 'dim_1') != ('dim_0',)" ,
46
44
"Coordinates mismatch for dimension 'dim_0': [0 1] != [0 1 2]" ,
47
45
"Shape mismatch: (2, 3) != (3,)" ,
48
- dirty_equals .IsStr (regex = "Left and right DataArray objects are not close.*" , regex_flags = re .DOTALL ),
49
46
],
50
47
),
51
48
(
52
49
xarray .DataArray ([[1 ], [2 ], [3 ]]),
53
50
[
54
51
"Dimension mismatch: ('dim_0', 'dim_1') != ('dim_0',)" ,
55
52
"Shape mismatch: (3, 1) != (3,)" ,
56
- dirty_equals .IsStr (regex = "Left and right DataArray objects are not close.*" , regex_flags = re .DOTALL ),
57
53
],
58
54
),
59
55
],
@@ -75,20 +71,12 @@ def test_simple_shape_mismatch(self, actual, expected_issues):
75
71
"Dimension mismatch: ('y', 'x') != ('x', 'y')" ,
76
72
"Coordinates mismatch for dimension 'x': [0 1 2] != [0 1]" ,
77
73
"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
- ),
82
74
],
83
75
),
84
76
(
85
77
xarray .DataArray ([[1 , 2 , 3 ], [4 , 5 , 6 ]], dims = ["x" , "z" ]),
86
78
[
87
79
"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
- ),
92
80
],
93
81
),
94
82
],
@@ -108,10 +96,6 @@ def test_simple_dims_mismatch(self, actual, expected_issues):
108
96
xarray .DataArray ([[1 , 2 , 3 ], [4 , 5 , 6 ]], coords = [("x" , [111 , 222 ]), ("y" , [33 , 44 , 55 ])]),
109
97
[
110
98
"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
- ),
115
99
],
116
100
),
117
101
],
@@ -351,6 +335,108 @@ def test_allclose_minimal_success(self, tmp_path, actual_dir, expected_dir):
351
335
ds .to_netcdf (actual_dir / "data.nc" )
352
336
assert_job_results_allclose (actual = actual_dir , expected = expected_dir , tmp_path = tmp_path )
353
337
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
+
354
440
def test_allclose_basic_fail (self , tmp_path , actual_dir , expected_dir ):
355
441
expected_ds = xarray .Dataset ({"a" : (["time" ], [1 , 2 , 3 ])}, coords = {"time" : [11 , 22 , 33 ]})
356
442
expected_ds .to_netcdf (expected_dir / "data.nc" )
0 commit comments