Copy additional coordinates when regridding#3048
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3048 +/- ##
=======================================
Coverage 96.19% 96.20%
=======================================
Files 272 272
Lines 15957 15985 +28
=======================================
+ Hits 15350 15378 +28
Misses 607 607 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
For testing purposes, here are four types of grids we commonly encounter: In [1]: from esmvalcore.dataset import Dataset
...: from esmvalcore.preprocessor import regrid
In [2]: cordex_lambert_conformal = Dataset(
...: project="CORDEX",
...: mip="mon",
...: short_name="tas",
...: dataset="RegCM4-6",
...: ensemble="r1i1p1",
...: driver="CNRM-CERFACS-CNRM-CM5",
...: institute="ICTP",
...: domain="EUR-11",
...: exp="historical",
...: rcm_version="v2",
...: timerange="2001/2005",
...: use_standard_grid=True,
...: ).load()
...:
...: cordex_rotated_pole = Dataset(
...: project="CORDEX",
...: mip="day",
...: short_name="ts",
...: dataset="HIRHAM5",
...: ensemble="r1i1p1",
...: driver="IPSL-IPSL-CM5A-MR",
...: institute="DMI",
...: domain="EUR-11",
...: exp="historical",
...: rcm_version="v1",
...: timerange="2001/2005",
...: ).load()
...:
...: tas = Dataset(
...: project="CMIP6",
...: mip="Amon",
...: short_name="tas",
...: dataset="CanESM5",
...: ensemble="r1i1p1f1",
...: exp="historical",
...: grid="gn",
...: timerange="2001/2005",
...: ).load()
...:
...: tos = Dataset(
...: project="CMIP6",
...: mip="Omon",
...: short_name="tos",
...: dataset="CanESM5",
...: ensemble="r1i1p1f1",
...: exp="historical",
...: grid="gn",
...: timerange="2001/2005",
...: ).load()
...:
WARNING:esmvalcore.cmor._fixes.cordex.cordex_fixes:Support for CORDEX datasets in a Lambert Conformal coordinate system is ongoing. Certain preprocessor functions may fail.
WARNING:esmvalcore.cmor._fixes.cordex.cordex_fixes:Maximum difference between original projection_x_coordinate points and standard EUR-11 domain points for variable tas from dataset RegCM4-6 is 131500.0 m. Consider visualizing the data on a map and comparing with recognizable features such as coastlines to check that the grid is correct.
WARNING:esmvalcore.cmor._fixes.cordex.cordex_fixes:Maximum difference between original projection_y_coordinate points and standard EUR-11 domain points for variable tas from dataset RegCM4-6 is 131500.0 m. Consider visualizing the data on a map and comparing with recognizable features such as coastlines to check that the grid is correct.
WARNING:esmvalcore.cmor._fixes.cordex.cordex_fixes:Maximum difference between original latitude points and standard EUR-11 domain points for variable tas from dataset RegCM4-6 is 1.331701984850012 degrees_north. Consider visualizing the data on a map and comparing with recognizable features such as coastlines to check that the grid is correct.
WARNING:esmvalcore.cmor._fixes.cordex.cordex_fixes:Maximum difference between original longitude points and standard EUR-11 domain points for variable tas from dataset RegCM4-6 is 359.7994925609495 degrees_east. Consider visualizing the data on a map and comparing with recognizable features such as coastlines to check that the grid is correct.
/home/bandela/src/esmvalgroup/esmvalcore/.pixi/envs/default/lib/python3.14/site-packages/intake_esgf/catalog.py:73: UserWarning: You have enabled at least one index which uses the old Solr technology. ESGF is moving away from this technology and you may find that some indicesfail to return a response.
warnings.warn(
/home/bandela/src/esmvalgroup/esmvalcore/.pixi/envs/default/lib/python3.14/site-packages/intake_esgf/catalog.py:73: UserWarning: You have enabled at least one index which uses the old Solr technology. ESGF is moving away from this technology and you may find that some indicesfail to return a response.
warnings.warn(Note that with this branch, the regridded data has all horizontal coordinates of the target grid, instead of a subset: In [3]: regrid(tos, target_grid=cordex_rotated_pole, scheme="linear").coords()
Out[3]:
[<DimCoord: time / (days since 1850-1-1 00:00:00) [...]+bounds shape(60,)>,
<DimCoord: grid_latitude / (degrees) [-23.375, ...]+bounds shape(412,)>,
<DimCoord: grid_longitude / (degrees) [-28.375, ...]+bounds shape(424,)>,
<AuxCoord: latitude / (degrees_north) [...]+bounds shape(412, 424)>,
<AuxCoord: longitude / (degrees_east) [...]+bounds shape(412, 424)>]
In [4]: regrid(cordex_rotated_pole, target_grid=tos, scheme="linear").coords()
Out[4]:
[<DimCoord: time / (days since 1850-1-1 00:00:00) [...]+bounds shape(1825,)>,
<DimCoord: cell index along second dimension / (1) [ 0, 1, ..., 289, 290] shape(291,)>,
<DimCoord: cell index along first dimension / (1) [ 0, 1, ..., 358, 359] shape(360,)>,
<AuxCoord: latitude / (degrees_north) [...]+bounds shape(291, 360)>,
<AuxCoord: longitude / (degrees_east) [[73.5, 74.5, ..., 71.5, 72.5], ...]+bounds shape(291, 360)>]while with the current In [3]: regrid(tos, target_grid=cordex_rotated_pole, scheme="linear").coords()
Out[3]:
[<DimCoord: time / (days since 1850-1-1 00:00:00) [...]+bounds shape(60,)>,
<DimCoord: grid_latitude / (degrees) [-23.375, ...]+bounds shape(412,)>,
<DimCoord: grid_longitude / (degrees) [-28.375, ...]+bounds shape(424,)>]
In [4]: regrid(cordex_rotated_pole, target_grid=tos, scheme="linear").coords()
Out[4]:
[<DimCoord: time / (days since 1850-1-1 00:00:00) [...]+bounds shape(1825,)>,
<AuxCoord: latitude / (degrees_north) [...]+bounds shape(291, 360)>,
<AuxCoord: longitude / (degrees_east) [[73.5, 74.5, ..., 71.5, 72.5], ...]+bounds shape(291, 360)>] |
flicj191
left a comment
There was a problem hiding this comment.
Thanks, I've tested this in a recipe regridding to a tos dataset and its working, makes sense to copy the dim coords.
| array1 = coord1.core_points() | ||
| array2 = coord2.core_points() | ||
|
|
||
| if not np.allclose(array1, array2): |
There was a problem hiding this comment.
I think _horizontal_grid_is_close should include the coordinate system/projection in the comparison. At the moment identical grid_latitude/grid_longitude points with different RotatedGeogCS parameters will return True, so regrid() can skip the actual regrid and then copy the target coordinates onto data that is still on the source projection. Could you add a test where two rotated grids have the same points but different rotated pole/projection metadata, and make the helper return False for that case? Comparing coord_system/units in addition to points/bounds, or falling back to the 2D lat/lon coordinates when present, should avoid the silent mislabelling.
|
|
Description
The
regridpreprocessor function regrids one set of coordinates to another. However, CORDEX data typically has two sets of coordinates:rotated_latitude/rotated_longitudeorprojection_y_coordinate/projection_x_coordinateas airis.coords.DimCoordandlatitude/longitudeas an additionaliris.coords.AuxCoord. The changes in this pull request ensure that if the target grid has multiple coordinates, these will be available on the regridded cube, even if only one set is used for the regridding.Closes #2839
Link to documentation:
Before you get started
Checklist
It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.
To help with the number pull requests: