Skip to content

Commit

Permalink
Fix and improve single grid interpolator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Nov 15, 2023
1 parent 56d4a41 commit ed60b5c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion geotiepoints/tests/test_geointerpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_geogrid_interpolation_preserves_dtype(self):

def test_chunked_geogrid_interpolation(self):
"""Test that the interpolator works with both explicit tie-point arrays and swath definition objects."""
import dask
dask = pytest.importorskip("dask")

x_points = np.array([0, 1, 3, 7])
y_points = np.array([0, 1, 3, 7, 15])
Expand Down
21 changes: 20 additions & 1 deletion geotiepoints/tests/test_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def grid_interpolator():
[2, 2, 2, 1],
[0, 3, 3, 3],
[1, 2, 1, 2],
[4, 4, 4, 4]])
[4, 4, 4, 4]],
dtype=np.float64)

return SingleGridInterpolator((ypoints, xpoints), data)

Expand Down Expand Up @@ -378,3 +379,21 @@ def test_interpolate_dask(self, grid_interpolator, chunks, expected_chunks):

np.testing.assert_allclose(res, self.expected, atol=2e-9)
assert interpolate.called

def test_interpolate_preserves_dtype(self):
"""Test that interpolation is preserving the dtype."""
xpoints = np.array([0, 3, 7, 15])
ypoints = np.array([0, 3, 7, 15, 31])
data = np.array([[0, 1, 0, 1],
[2, 2, 2, 1],
[0, 3, 3, 3],
[1, 2, 1, 2],
[4, 4, 4, 4]],
dtype=np.float32)

grid_interpolator = SingleGridInterpolator((ypoints, xpoints), data)
fine_x = np.arange(16)
fine_y = np.arange(32)

res = grid_interpolator.interpolate((fine_y, fine_x), method="cubic")
assert res.dtype == data.dtype

0 comments on commit ed60b5c

Please sign in to comment.