-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regridding very similar grids may result in lat/lon coordinates that are not exactly identical #1551
Comments
See #1177 for information on how this was solved for vertical coordinates. |
I had a look at the code changes in #1177 and as I understand the solution in there was to adapt the tolerance of the diff --git a/esmvalcore/preprocessor/_regrid.py b/esmvalcore/preprocessor/_regrid.py
index de822a73a..a39592b37 100644
--- a/esmvalcore/preprocessor/_regrid.py
+++ b/esmvalcore/preprocessor/_regrid.py
@@ -639,6 +639,11 @@ def regrid(cube, target_grid, scheme, lat_offset=True, lon_offset=True):
"'%s': %s", original_dtype, cube.core_data().dtype,
str(exc))
cube.data = da.ma.masked_equal(cube.core_data(), fill_value)
+ else:
+ # force target coordinates
+ for coord in ['latitude', 'longitude']:
+ cube.coord(coord).points = target_grid.coord(coord).points
+ cube.coord(coord).bounds = target_grid.coord(coord).bounds
return cube
|
That looks fine to me. Note that @zklaus requested that the user has control over the tolances in #1177 (comment), so I guess that would also be needed here? |
I think that the test performed in if @zklaus agrees on the above solution I'll open a PR to fix it ... |
I like the idea of forcing the target grid on the result. I do think that some user control on the required precision might be useful, particularly in light of projections where the coordinates may take very large values ( But I'd say go ahead with the forcing in a PR and let's discuss fine-tweaking of tolerances there. |
* replace regular lat/lon coords of source cube with target ones when points are close enough * add test for regular grid comparison (#1551) * test regular grid coordinates are the same using iris Resolve * fix bug in previous commit for regrid test
Issue reported by @tomaslovato in #485 (comment):
The grid coordinates comparison done in
_horizontal_grid_is_close
uses the functionnp.allclose
which has default tolerance values set tortol=1e-05, atol=1e-08
that may not be always enough.In particular, when lat/lon coordinates are not the same for all regridded datasets any following manipulation made between cubes will produce an
iris
error from the cube coordinates equality check.I found this issue while working with CMIP6 ocean data on regular grid from
GFDL-CM4
andGFDL-ESM4
datasets.Here below a sample of the
latitude
field fromdissic_Omon_GFDL-CM4_historical_r1i1p1f1_gr_201001-201412.nc
I see a couple of possible fixes:
_regrid
functionnp.allclose
with a more stringent iris equality check (as proposed by @valeriupredoi in the above discussion) and modify in here the lat/lon coordinates of the cube.Originally posted by @tomaslovato in #485 (comment)
The text was updated successfully, but these errors were encountered: