Skip to content

Commit

Permalink
Temporarily modify spatial.py tests to work around odc-geo bug (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbibt committed Jul 1, 2024
1 parent 21e7a9b commit 2f82af5
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Tests/dea_tools/test_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
from dea_tools.validation import eval_metrics


def geobox_test(gbox1, gbox2):
"""
Tests equivalency between two GeoBoxes, allowing for floating
point precision differences between coordinates
TODO: Remove once `odc-geo` bug is resolved
"""
y_dim, x_dim = gbox1.dims
assert np.allclose(gbox1.coords[x_dim].values, gbox2.coords[x_dim].values)
assert np.allclose(gbox1.coords[y_dim].values, gbox2.coords[y_dim].values)
assert np.allclose(gbox1.resolution.xy, gbox2.resolution.xy)
assert gbox1.crs == gbox2.crs
assert gbox1.shape == gbox2.shape


@pytest.fixture(
params=[
None, # Default WGS84
Expand Down Expand Up @@ -346,7 +360,7 @@ def test_idw():
output_y = [0.0, 0.0, 0.0, 0.0]
out = idw(input_z, input_x, input_y, output_x, output_y, k=2)
assert np.allclose(out, [1.5, 2.5, 3.5, 4.5])

# Verify that k > input points gives error
with pytest.raises(ValueError):
idw(input_z, input_x, input_y, output_x, output_y, k=6)
Expand Down Expand Up @@ -380,11 +394,11 @@ def test_idw():
# Four neighbours; max distance of 2, k_min of 4 (should return NaN)
out = idw(input_z, input_x, input_y, output_x, output_y, k=4, max_dist=2, k_min=4)
assert np.isnan(out).all()

# Four neighbours; power function p=0
out = idw(input_z, input_x, input_y, output_x, output_y, k=4, p=0)
assert np.allclose(out, [2.5, 2.5, 2.5, 2.5])

# Four neighbours; power function p=2
out = idw(input_z, input_x, input_y, output_x, output_y, k=4, p=2)
assert np.allclose(out, [1.83, 2.17, 2.83, 3.17], rtol=0.01)
Expand Down Expand Up @@ -429,7 +443,7 @@ def test_xr_interpolate(dem_da, points_gdf, method):
method=method,
k=5,
)
assert interpolated_ds.odc.geobox == dem_da.odc.geobox
geobox_test(interpolated_ds.odc.geobox, dem_da.odc.geobox)
assert "z" in interpolated_ds.data_vars
assert interpolated_ds["z"].notnull().sum() > 0

Expand All @@ -450,7 +464,7 @@ def test_xr_interpolate(dem_da, points_gdf, method):
k=5,
factor=10,
)
assert interpolated_ds_factor10.odc.geobox == dem_da.odc.geobox
geobox_test(interpolated_ds_factor10.odc.geobox, dem_da.odc.geobox)
assert "z" in interpolated_ds_factor10.data_vars
assert interpolated_ds_factor10["z"].notnull().sum() > 0

Expand Down

0 comments on commit 2f82af5

Please sign in to comment.