77 cuda_and_cupy_available , general_output_checks )
88
99
10- def input_data (backend = 'numpy' ):
11- data = np .asarray ([
12- [np .nan , np .nan , np .nan , np .nan , np .nan , np .nan ],
13- [1584.8767 , 1584.8767 , 1585.0546 , 1585.2324 , 1585.2324 , 1585.2324 ],
14- [1585.0546 , 1585.0546 , 1585.2324 , 1585.588 , 1585.588 , 1585.588 ],
15- [1585.2324 , 1585.4102 , 1585.588 , 1585.588 , 1585.588 , 1585.588 ],
16- [1585.588 , 1585.588 , 1585.7659 , 1585.7659 , 1585.7659 , 1585.7659 ],
17- [1585.7659 , 1585.9437 , 1585.7659 , 1585.7659 , 1585.7659 , 1585.7659 ],
18- [1585.9437 , 1585.9437 , 1585.9437 , 1585.7659 , 1585.7659 , 1585.7659 ]],
19- dtype = np .float32
20- )
21- raster = create_test_raster (data , backend , attrs = {'res' : (10.0 , 10.0 )})
10+ def input_data (data , backend = 'numpy' ):
11+ raster = create_test_raster (data , backend )
2212 return raster
2313
2414
2515@pytest .fixture
26- def qgis_output ():
16+ def qgis_aspect ():
2717 result = np .array ([
28- [np .nan , np .nan , np .nan , np .nan , np .nan , np .nan ],
29- [np .nan , np .nan , np .nan , np .nan , np .nan , np .nan ],
30- [330.94687 , 335.55496 , 320.70786 , 330.94464 , 0. , 0. ],
31- [333.43494 , 333.43494 , 329.03394 , 341.56897 , 0. , 18.434948 ],
32- [338.9621 , 338.20062 , 341.56506 , 0. , 0. , 45. ],
33- [341.56506 , 351.8699 , 26.56505 , 45. , - 1. , 90. ],
34- [351.86676 , 11.306906 , 45. , 45. , 45. , 108.431015 ]], dtype = np . float32
35- )
18+ [ np .nan , np .nan , np .nan , np .nan , np .nan , np .nan ],
19+ [ np .nan , np .nan , np .nan , np .nan , np .nan , np .nan ],
20+ [233.19478 , 278.358 , 45.18813 , 306.6476 , 358.34296 , 106.45898 ],
21+ [267.7002 , 274.42487 , 11.035832 , 357.9641 , 129.98279 , 50.069843 ],
22+ [263.18484 , 238.47426 , 196.37103 , 149.25227 , 187.85748 , 263.684 ],
23+ [266.63937 , 271.05124 , 312.09726 , 348.89136 , 351.618 , 315.59424 ],
24+ [279.90872 , 314.11356 , 345.76315 , 327.5568 , 339.5455 , 312.9249 ],
25+ [ 271.93985 , 268.81046 , 24.793104 , 185.978 , 299.82904 , 159.0188 ]], dtype = np . float32 )
3626 return result
3727
3828
39- def test_numpy_equals_qgis (qgis_output ):
40- numpy_agg = input_data ()
29+ def test_numpy_equals_qgis (elevation_raster , qgis_aspect ):
30+ numpy_agg = input_data (elevation_raster , backend = 'numpy' )
4131 xrspatial_aspect = aspect (numpy_agg , name = 'numpy_aspect' )
4232
4333 general_output_checks (numpy_agg , xrspatial_aspect , verify_dtype = True )
4434 assert xrspatial_aspect .name == 'numpy_aspect'
4535
4636 xrspatial_vals = xrspatial_aspect .data [1 :- 1 , 1 :- 1 ]
47- qgis_vals = qgis_output [1 :- 1 , 1 :- 1 ]
37+ qgis_vals = qgis_aspect [1 :- 1 , 1 :- 1 ]
4838 # aspect is nan if nan input
4939 # aspect is invalid (-1) if slope equals 0
5040 # otherwise aspect are from 0 to 360
51- np .testing .assert_allclose (xrspatial_vals , qgis_vals , equal_nan = True )
41+ np .testing .assert_allclose (xrspatial_vals , qgis_vals , rtol = 1e-05 , equal_nan = True )
5242 # nan edge effect
5343 assert_nan_edges_effect (xrspatial_aspect )
5444
5545
56- def test_numpy_equals_dask_qgis_data ():
46+ def test_numpy_equals_dask_qgis_data (elevation_raster ):
5747 # compare using the data run through QGIS
58- numpy_agg = input_data ('numpy' )
59- dask_agg = input_data ('dask+numpy' )
48+ numpy_agg = input_data (elevation_raster , 'numpy' )
49+ dask_agg = input_data (elevation_raster , 'dask+numpy' )
6050 assert_numpy_equals_dask_numpy (numpy_agg , dask_agg , aspect )
6151
6252
@@ -72,8 +62,8 @@ def test_numpy_equals_dask_random_data(random_data):
7262@cuda_and_cupy_available
7363def test_numpy_equals_cupy_qgis_data ():
7464 # compare using the data run through QGIS
75- numpy_agg = input_data ()
76- cupy_agg = input_data ('cupy' )
65+ numpy_agg = input_data (elevation_raster )
66+ cupy_agg = input_data (elevation_raster , 'cupy' )
7767 assert_numpy_equals_cupy (numpy_agg , cupy_agg , aspect )
7868
7969
0 commit comments