Skip to content

Copy additional coordinates when regridding#3048

Open
bouweandela wants to merge 10 commits into
mainfrom
regrid-copy-additional-coords
Open

Copy additional coordinates when regridding#3048
bouweandela wants to merge 10 commits into
mainfrom
regrid-copy-additional-coords

Conversation

@bouweandela

@bouweandela bouweandela commented Apr 22, 2026

Copy link
Copy Markdown
Member

Description

The regrid preprocessor function regrids one set of coordinates to another. However, CORDEX data typically has two sets of coordinates: rotated_latitude/rotated_longitude or projection_y_coordinate/projection_x_coordinate as a iris.coords.DimCoord and latitude/longitude as an additional iris.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:

@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.19%. Comparing base (b03c23d) to head (5f2fbe9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3048   +/-   ##
=======================================
  Coverage   96.18%   96.19%           
=======================================
  Files         271      271           
  Lines       15913    15937   +24     
=======================================
+ Hits        15306    15330   +24     
  Misses        607      607           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ghossh ghossh moved this from In Progress to Todo in Cordex support (ESO4clima WP2) Jun 5, 2026
@ghossh ghossh moved this from Todo to In Progress in Cordex support (ESO4clima WP2) Jun 9, 2026
@bouweandela bouweandela added the preprocessor Related to the preprocessor label Jun 11, 2026
@bouweandela

Copy link
Copy Markdown
Member Author

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 main branch the result is:

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)>]

@bouweandela bouweandela marked this pull request as ready for review June 12, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preprocessor Related to the preprocessor

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

regrid pre-processor removes coordinates that may be useful

2 participants