3
3
"""
4
4
import os
5
5
6
+ import numpy as np
6
7
import numpy .testing as npt
7
8
import pytest
8
9
import xarray as xr
@@ -20,32 +21,18 @@ def fixture_ship_data():
20
21
return load_sample_bathymetry ()
21
22
22
23
23
- def test_nearneighbor_input_file ():
24
+ @pytest .mark .parametrize ("array_func" , [np .array , xr .Dataset ])
25
+ def test_nearneighbor_input_data (array_func , ship_data ):
24
26
"""
25
- Run nearneighbor by passing in a filename .
27
+ Run nearneighbor by passing in a numpy.array or xarray.Dataset .
26
28
"""
27
- output = nearneighbor (
28
- data = "@tut_ship.xyz" ,
29
- spacing = "5m" ,
30
- region = [245 , 255 , 20 , 30 ],
31
- search_radius = "10m" ,
32
- )
33
- assert isinstance (output , xr .DataArray )
34
- assert output .gmt .registration == 0 # Gridline registration
35
- assert output .gmt .gtype == 0 # Cartesian type
36
- assert output .shape == (121 , 121 )
37
- npt .assert_allclose (output .mean (), - 2378.2385 )
38
-
39
-
40
- def test_nearneighbor_input_numpy_array (ship_data ):
41
- """
42
- Run nearneighbor by passing in a numpy array into data.
43
- """
44
- data = ship_data .values # convert pandas.DataFrame to numpy.ndarray
29
+ data = array_func (ship_data )
45
30
output = nearneighbor (
46
31
data = data , spacing = "5m" , region = [245 , 255 , 20 , 30 ], search_radius = "10m"
47
32
)
48
33
assert isinstance (output , xr .DataArray )
34
+ assert output .gmt .registration == 0 # Gridline registration
35
+ assert output .gmt .gtype == 1 # Geographic type
49
36
assert output .shape == (121 , 121 )
50
37
npt .assert_allclose (output .mean (), - 2378.2385 )
51
38
0 commit comments