Skip to content
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

Unstructured Scheme - Mesh Fetching #46

Conversation

stephenworsley
Copy link
Contributor

This PR adds support for fetching meshes and mesh dimensions from iris. Originally we had planned on using a helper function _get_mesh_and_dim to do this, however iris has updated to the point where this functionality is given in one line, so for clarities sake I have replaced the helper function. Instead of testing the helper function, I have tested _regrid_unstructured_to_rectilinear__prepare, where _get_mesh_and_dim would have been called. I have also added a test for regrid_unstructured_to_rectilinear to show that the whole regridder now functions as a result. Full test coverage can be added in a further PR.

@codecov
Copy link

codecov bot commented Mar 26, 2021

Codecov Report

Merging #46 (54bbc1f) into unstructured_scheme (f892f5f) will increase coverage by 4.60%.
The diff coverage is 100.00%.

Impacted file tree graph

@@                   Coverage Diff                   @@
##           unstructured_scheme      #46      +/-   ##
=======================================================
+ Coverage                93.47%   98.07%   +4.60%     
=======================================================
  Files                       13       16       +3     
  Lines                      521      624     +103     
=======================================================
+ Hits                       487      612     +125     
+ Misses                      34       12      -22     
Impacted Files Coverage Δ
esmf_regrid/experimental/unstructured_scheme.py 96.82% <100.00%> (+36.16%) ⬆️
...nstructured_scheme/test_MeshToGridESMFRegridder.py 100.00% <100.00%> (ø)
...st__regrid_unstructured_to_rectilinear__prepare.py 100.00% <100.00%> (ø)
..._scheme/test_regrid_unstructured_to_rectilinear.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f892f5f...54bbc1f. Read the comment docs.

stephenworsley and others added 9 commits March 29, 2021 09:29
…com/stephenworsley/iris-esmf-regrid into unstructured_scheme_mesh_extraction

* 'unstructured_scheme_mesh_extraction' of https://github.com/stephenworsley/iris-esmf-regrid:
  [pre-commit.ci] auto fixes from pre-commit.com hooks
…ion' into unstructured_scheme_mesh_extraction

* origin/unstructured_scheme_mesh_extraction:
  [pre-commit.ci] auto fixes from pre-commit.com hooks
Copy link
Member

@jamesp jamesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @stephenworsley 👍 . A few comments inline

grid_x, grid_y = get_xy_coords(target_grid_cube)
grid_x, grid_y = get_xy_dim_coords(target_grid_cube)
mesh = src_mesh_cube.mesh
assert mesh is not None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to be properly handled / exception raised in the future? If so maybe a TODO added?

# mesh is probably an iris Mesh object, though it could also be a MeshCoord
mesh, mesh_dim = _get_mesh_and_dim(cube)
mesh = cube.mesh
assert mesh is not None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO here if we plan on adding more error handling

# mesh belongs to (mesh_dim).
mesh, mesh_dim = _get_mesh_and_dim(src_mesh_cube)
# mesh belongs to.
mesh_dim = src_mesh_cube.mesh_dim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous pseudocode version of this (L28) took mesh as a parameter. Is it not necessary to do this anymore? Is there a possibility that a cube contains more than one mesh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous pseudocode version was written before this functionality was implemented in iris. We've discussed the idea of a cube containing more than one mesh and we don't anticipate this possibility. In fact I don't believe it's possible to define such a thing under the current UGRID conventions.

return mesh


def _flat_mesh_cube():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document what the object that this returns looks like? i.e. data is all ones?

src = _add_metadata(src)
result = regrid_unstructured_to_rectilinear(src, tgt)

expected_data = np.ones([5, 6])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious to me why the expected data is [5,6] from the regrid operation, the test is relying on setup from another module in _flat_mesh_cube. Could you add a comment explaining why this is the expected outcome?

@jamesp jamesp merged commit a33e376 into SciTools:unstructured_scheme Mar 31, 2021
jamesp pushed a commit that referenced this pull request Apr 8, 2021
* Unstructured scheme skeleton (#31)

* create skeleton of unstructured regridding code
This code is primarily based on Iris's current Area weighted regridding scheme, with the required adaptions for accepting unstructred UGRID data.

* Unstructured Scheme - Basic GridInfo Handling (#32)

Add basic `GridInfo` function and associated tests.  It returns an ESMF regridding object for gridded data.

* Unstructured scheme iris source (#33)

* refresh cirrus-ci and nox

* add iris artifact support

* deal with special-case cirrus-ci quoting

* review actions

* Unstructured Scheme - Basic MeshInfo Handling (#36)

* provide iris Mesh to MeshInfo conversion

* test against iris feature branch

* lint fixes and documentation

* fix typo

* address review comments.

* change tests to better reflect UGRID orientation

* address review comments.

* address review comments

* ASCII art fix

* Unstructured Scheme - Cube Creation 2D (#39)

* support creation of 2D cubes

* lint fixes

* rewrite test

* remove mesh from _create_cube arguments

* add TODO

* add TODO

* Unstructured Scheme - Mesh Fetching (#46)

* support mesh fetching

* fix docstring

* lint fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add docstrings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add and restructure tests

* fix test

* fix test

* address review comments

* address review comments

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Co-authored-by: Bill Little <bill.little@metoffice.gov.uk>
Co-authored-by: Anna Booton <anna.booton@metoffice.gov.uk>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
stephenworsley added a commit to stephenworsley/iris-esmf-regrid that referenced this pull request Jun 2, 2021
* Unstructured scheme skeleton (SciTools#31)

* create skeleton of unstructured regridding code
This code is primarily based on Iris's current Area weighted regridding scheme, with the required adaptions for accepting unstructred UGRID data.

* Unstructured Scheme - Basic GridInfo Handling (SciTools#32)

Add basic `GridInfo` function and associated tests.  It returns an ESMF regridding object for gridded data.

* Unstructured scheme iris source (SciTools#33)

* refresh cirrus-ci and nox

* add iris artifact support

* deal with special-case cirrus-ci quoting

* review actions

* Unstructured Scheme - Basic MeshInfo Handling (SciTools#36)

* provide iris Mesh to MeshInfo conversion

* test against iris feature branch

* lint fixes and documentation

* fix typo

* address review comments.

* change tests to better reflect UGRID orientation

* address review comments.

* address review comments

* ASCII art fix

* Unstructured Scheme - Cube Creation 2D (SciTools#39)

* support creation of 2D cubes

* lint fixes

* rewrite test

* remove mesh from _create_cube arguments

* add TODO

* add TODO

* Unstructured Scheme - Mesh Fetching (SciTools#46)

* support mesh fetching

* fix docstring

* lint fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add docstrings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add and restructure tests

* fix test

* fix test

* address review comments

* address review comments

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Co-authored-by: Bill Little <bill.little@metoffice.gov.uk>
Co-authored-by: Anna Booton <anna.booton@metoffice.gov.uk>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@trexfeathers trexfeathers mentioned this pull request Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants