Add CORDEX domain target grids for regridding#3096
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3096 +/- ##
==========================================
- Coverage 96.14% 96.01% -0.13%
==========================================
Files 267 267
Lines 15771 15803 +32
==========================================
+ Hits 15163 15174 +11
- Misses 608 629 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Looks like a great start! Could you take a look at the checklist? A few things to do would be
- sign the CLA
- add a unit test
- add documentation
Usually you can find advice on how to go about that in the pull request template, but in case you missed it you can find it here: https://github.com/ESMValGroup/ESMValCore/blob/main/.github/pull_request_template.md
| Dummy cube with rotated-pole dimension coordinates and geographical | ||
| auxiliary coordinates matching the official domain specification. | ||
| """ | ||
| domain = cx.cordex_domain(domain_name, bounds=True) |
There was a problem hiding this comment.
Maybe you could simplify this code by using ncdata.iris_xarray.cubes_to_xarray to convert the xarray.Dataset to an iris.cube.Cube directly?
There was a problem hiding this comment.
This is a bit simpler, but not much. What I meant was something like
domain = cordex.domain(domain_name, bounds=True).reset_coords()
# Add a mock variable.
domain["data"] = xr.zeros_like(domain.lon)
# Associate the grid mapping and coordinates with the data.
domain.data.attrs = {
"coordinates": "lat lon",
"grid_mapping": "rotated_latitude_longitude",
}
# Associate the bounds with the coordinates.
domain.lat.attrs["bounds"] = "lat_vertices"
domain.lon.attrs["bounds"] = "lon_vertices"
cube, = ncdata.iris_xarray.cubes_from_xarray(domain)
cube.coord("grid_latitude").guess_bounds()
cube.coord("grid_longitude").guess_bounds()…ion and streamline coordinate handling
This update introduces a new section in the preprocessor documentation detailing how to regrid to standard CORDEX domains using the `target_grid` parameter. An example configuration for the `EUR-11` domain is provided, clarifying the use of domain names recognized by the `cordex` package.
|
Hi @bouweandela , Please provide another review. Not sure why the workflow commit is failing! |
|
Hi @bouweandela , I found that in case of : in this line, it's failing due to no having bounds ESMValCore/esmvalcore/preprocessor/_regrid.py Line 1017 in ddd67d7 A possible solution could be like adding this: what do you think? |
Should be fixed by #3104 |
|
Regarding the no-bounds issue: this seems unrelated to the changes in this pull request, so it would be great if you could open a new issue for this. We can then make a plan for how to solve it there and tackle it in a new pull request. |
| ------- | ||
| bool | ||
| Whether ``spec`` is recognised by :mod:`cordex`. | ||
| """ |
There was a problem hiding this comment.
| """ | |
| """ | |
| if not isinstance(spec, str): | |
| return False |
Adding this here would avoid the extra nesting in the places where you're calling this function, making that code a bit easier to read.
| Alternatively, a :class:`~esmvalcore.dataset.Dataset` can be provided. | ||
| Alternatively, a string cell specification may be provided, | ||
| of the form ``MxN``, which specifies the extent of the cell, longitude | ||
| by latitude (degrees) for a global, regular target grid. |
There was a problem hiding this comment.
Please also mention that this can be a CORDEX domain here
| target_grid: EUR-11 | ||
| scheme: linear | ||
|
|
||
| Any domain name recognized by the ``cordex`` package can be used, for example |
There was a problem hiding this comment.
It would be nice to add a link to this page so users can find the available domains easily.
| domain definition instead of interpreting the value as an ``MxN`` grid | ||
| specification. |
There was a problem hiding this comment.
| domain definition instead of interpreting the value as an ``MxN`` grid | |
| specification. | |
| domain definition. |
would suggest leaving that out as it doesn't add much
| assert target.coord(var_name="rlon") is not None | ||
|
|
||
|
|
||
| def test_update_target_grid_accepts_cordex_domain(): |
There was a problem hiding this comment.
Nice that you're adding tests for this! I think this would be a better place for them:
ESMValCore/tests/unit/recipe/test_recipe.py
Line 809 in ddd67d7
| def test_get_target_grid_cube_cordex_domain(global_cube): | ||
| """Test target grid cube construction for a CORDEX domain.""" | ||
| target = _get_target_grid_cube(global_cube, "EUR-11") | ||
| assert target.coord(var_name="rlat") is not None |
There was a problem hiding this comment.
| assert target.coord(var_name="rlat") is not None | |
| assert target.coords(var_name="rlat") |
would test that there is at least one coordinate with the name "rlat". The iris.cube.Cube.coord method raises an exception if no coordinate is found, so it will never return None.
There was a problem hiding this comment.
Nice progress @ghossh! I've pasted the checklist back in the pull request description to make it easier for myself to remember what to look for. A few more things to do would be to add a label to the pull request (e.g. preprocessor) and add yourself to the list of authors. Could you please also update the branch so coverage is uploaded again and I can see which lines of code have coverage.
Description
Adds support for using standard CORDEX domain names, such as
EUR-11, astarget_gridvalues in theregridpreprocessor.Previously,
target_grid: EUR-11was treated as anMxNgrid specification and failed with:Closes #3088
Link to documentation:
https://esmvaltool--3096.org.readthedocs.build/projects/ESMValCore/en/3096/recipe/preprocessor.html#regridding-on-a-cordex-domain-grid
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.