-
Notifications
You must be signed in to change notification settings - Fork 48
Add iris-esmf-regrid as a dependency #1809
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8ea1502
Add iris-esmf-regrid to env file
sloosvel f97985d
Allow to use regrid_rectilinear_to_rectilinear scheme
sloosvel 263f4b4
Add tests
sloosvel b5dda6f
Clean
sloosvel 5d4a348
Fix flake
sloosvel bc214a5
Merge remote-tracking branch 'origin/main' into dev_install_iris_esfm
sloosvel 473af23
Add package to setup
sloosvel 54b3acf
Fix some tests
sloosvel 41ff490
Correct package name
sloosvel 448f1c4
Fix shape in tests
sloosvel fcf77a2
Remove warning from docs
sloosvel 1de2ccd
Reorder code to make it cleaner
sloosvel aaa0cae
Improve documentation
sloosvel c23699d
Merge remote-tracking branch 'origin/main' into dev_install_iris_esfm
sloosvel 176f4ce
Fix flake
sloosvel 56b85aa
Restore condition
sloosvel 47005ea
Fix flake
sloosvel 6305e7d
Apply suggestions from code review
sloosvel d81ca55
Improve documentation
sloosvel aff8b2a
run GA tests
valeriupredoi c7ec2cc
GA tests run fine turning them off
valeriupredoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||
| """Horizontal and vertical regridding module.""" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import importlib | ||||||||||||||||||||||||||||
| import inspect | ||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||
|
|
@@ -536,8 +537,7 @@ def regrid(cube, target_grid, scheme, lat_offset=True, lon_offset=True): | |||||||||||||||||||||||||||
| extrapolation_mode: nanmask | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| To use the area weighted regridder available in | ||||||||||||||||||||||||||||
| :class:`esmf_regrid.schemes.ESMFAreaWeighted`, make sure that | ||||||||||||||||||||||||||||
| :doc:`iris-esmf-regrid:index` is installed and use | ||||||||||||||||||||||||||||
| :class:`esmf_regrid.schemes.ESMFAreaWeighted` use | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| .. code-block:: yaml | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -547,34 +547,7 @@ def regrid(cube, target_grid, scheme, lat_offset=True, lon_offset=True): | |||||||||||||||||||||||||||
| scheme: | ||||||||||||||||||||||||||||
| reference: esmf_regrid.schemes:ESMFAreaWeighted | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| .. note:: | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Note that :doc:`iris-esmf-regrid:index` is still experimental. | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| if isinstance(scheme, dict): | ||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||
| object_ref = scheme.pop("reference") | ||||||||||||||||||||||||||||
| except KeyError as key_err: | ||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||
| "No reference specified for generic regridding.") from key_err | ||||||||||||||||||||||||||||
| module_name, separator, scheme_name = object_ref.partition(":") | ||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||
| obj = importlib.import_module(module_name) | ||||||||||||||||||||||||||||
| except ImportError as import_err: | ||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||
| "Could not import specified generic regridding module. " | ||||||||||||||||||||||||||||
| "Please double check spelling and that the required module is " | ||||||||||||||||||||||||||||
| "installed.") from import_err | ||||||||||||||||||||||||||||
| if separator: | ||||||||||||||||||||||||||||
| for attr in scheme_name.split('.'): | ||||||||||||||||||||||||||||
| obj = getattr(obj, attr) | ||||||||||||||||||||||||||||
| loaded_scheme = obj(**scheme) | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| loaded_scheme = HORIZONTAL_SCHEMES.get(scheme.lower()) | ||||||||||||||||||||||||||||
| if loaded_scheme is None: | ||||||||||||||||||||||||||||
| emsg = 'Unknown regridding scheme, got {!r}.' | ||||||||||||||||||||||||||||
| raise ValueError(emsg.format(scheme)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if isinstance(target_grid, str): | ||||||||||||||||||||||||||||
| if os.path.isfile(target_grid): | ||||||||||||||||||||||||||||
| target_grid = iris.load_cube(target_grid) | ||||||||||||||||||||||||||||
|
|
@@ -592,14 +565,46 @@ def regrid(cube, target_grid, scheme, lat_offset=True, lon_offset=True): | |||||||||||||||||||||||||||
| ycoord = target_grid.coord(axis='y', dim_coords=True) | ||||||||||||||||||||||||||||
| xcoord.coord_system = src_cs | ||||||||||||||||||||||||||||
| ycoord.coord_system = src_cs | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| elif isinstance(target_grid, dict): | ||||||||||||||||||||||||||||
| # Generate a target grid from the provided specification, | ||||||||||||||||||||||||||||
| target_grid = _regional_stock_cube(target_grid) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if not isinstance(target_grid, iris.cube.Cube): | ||||||||||||||||||||||||||||
| raise ValueError(f'Expecting a cube, got {target_grid}.') | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if isinstance(scheme, dict): | ||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||
| object_ref = scheme.pop("reference") | ||||||||||||||||||||||||||||
| except KeyError as key_err: | ||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||
| "No reference specified for generic regridding.") from key_err | ||||||||||||||||||||||||||||
| module_name, separator, scheme_name = object_ref.partition(":") | ||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||
| obj = importlib.import_module(module_name) | ||||||||||||||||||||||||||||
| except ImportError as import_err: | ||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||
| "Could not import specified generic regridding module. " | ||||||||||||||||||||||||||||
| "Please double check spelling and that the required module is " | ||||||||||||||||||||||||||||
| "installed.") from import_err | ||||||||||||||||||||||||||||
| if separator: | ||||||||||||||||||||||||||||
| for attr in scheme_name.split('.'): | ||||||||||||||||||||||||||||
| obj = getattr(obj, attr) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| scheme_args = inspect.getfullargspec(obj).args | ||||||||||||||||||||||||||||
| # Add source and target cubes as arguments if required | ||||||||||||||||||||||||||||
| if 'src_cube' in scheme_args: | ||||||||||||||||||||||||||||
| scheme['src_cube'] = cube | ||||||||||||||||||||||||||||
| if 'grid_cube' in scheme_args: | ||||||||||||||||||||||||||||
| scheme['grid_cube'] = target_grid | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| loaded_scheme = obj(**scheme) | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| loaded_scheme = HORIZONTAL_SCHEMES.get(scheme.lower()) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if loaded_scheme is None: | ||||||||||||||||||||||||||||
| emsg = 'Unknown regridding scheme, got {!r}.' | ||||||||||||||||||||||||||||
| raise ValueError(emsg.format(scheme)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Unstructured regridding requires x2 2d spatial coordinates, | ||||||||||||||||||||||||||||
| # so ensure to purge any 1d native spatial dimension coordinates | ||||||||||||||||||||||||||||
| # for the regridder. | ||||||||||||||||||||||||||||
|
|
@@ -629,6 +634,10 @@ def regrid(cube, target_grid, scheme, lat_offset=True, lon_offset=True): | |||||||||||||||||||||||||||
| # Perform the horizontal regridding | ||||||||||||||||||||||||||||
| if _attempt_irregular_regridding(cube, scheme): | ||||||||||||||||||||||||||||
| cube = esmpy_regrid(cube, target_grid, scheme) | ||||||||||||||||||||||||||||
| elif isinstance(loaded_scheme, iris.cube.Cube): | ||||||||||||||||||||||||||||
| # Return regridded cube in cases in which the | ||||||||||||||||||||||||||||
| # scheme is a function f(src_cube, grid_cube) -> Cube | ||||||||||||||||||||||||||||
| return loaded_scheme | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| cube = cube.regrid(target_grid, loaded_scheme) | ||||||||||||||||||||||||||||
|
Comment on lines
634
to
642
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Maybe clearer? Could you also add a comment here in which cases
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, I have also updated the documentation. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.