GeoscienceAustralia / dea-notebooks

Repository for Digital Earth Australia Jupyter Notebooks: tools and workflows for geospatial analysis with Open Data Cube and Xarray
https://docs.dea.ga.gov.au/notebooks/
Apache License 2.0
433 stars 127 forks source link

Temporarily modify `spatial.py` tests to work around `odc-geo` Geobox comparison precision issue #1235

Closed robbibt closed 2 weeks ago

robbibt commented 2 weeks ago

Proposed changes

A recent change in odc-geo (link here) is causing our tests to fail against odc-geo version 0.4.7, due to tiny differences in coordinate certainty causing comparisons like this to fail:

ds.odc.geobox == ds2.odc.geobox

This PR implements a temporary workaround using a new geobox_test testing function that compares GeoBoxes using np.allclose to account for tiny differences in coordinate precision. This should be reverted if an odc-geo fix/workaround becomes available.

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