climate_indices icon indicating copy to clipboard operation
climate_indices copied to clipboard

Consider a small tolerance when verifying matching coordinates

Open itati01 opened this issue 2 years ago • 2 comments

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_equals with np.allcloses.

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.

itati01 avatar Mar 18 '22 12:03 itati01

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.

monocongo avatar Mar 19 '22 00:03 monocongo

@itati01 Thank you for adding the PR for this issue! It fixed the first problem I was having when trying to run the code.

cgmorton avatar Apr 30 '22 00:04 cgmorton