climate_indices
climate_indices copied to clipboard
Consider a small tolerance when verifying matching coordinates
Is your feature request related to a problem? Please describe.
SPEI, for instance, requires two NetCDFs. If the float lon/lat of the same data provider differ slightly due to (presumably) rounding errors, np.array_equal()
returns False
which causes a ValueError: Precipitation and temperature variables contain non-matching latitudes
in _validate_args
.
Describe the solution you'd like
A small tolerance should be considered in the comparison of x1 and x2. A solution might be np.allclose(x1, x2, rtol=0, atol=small_threshold)
. In my case (grid resolution of 0.1°), small_threshold
of 1e-5 would be fine. This is already done in other comparisons (e.g. lats_precip and dataset_awc). I suggest to consequently replace the np.array_equal
s with np.allclose
s.
Describe alternatives you've considered
np.abs(x1-x2).max() < small_threshold
Additional context I issue occurred with E-OBS datasets, i.e. temperature and precipitation.
Thanks for this good idea @itati01, it seems very reasonable. I probably don't have the bandwidth to implement myself but a PR will be welcome.
@itati01 Thank you for adding the PR for this issue! It fixed the first problem I was having when trying to run the code.