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 - Basic GridInfo Handling #32

Conversation

stephenworsley
Copy link
Contributor

This copies the most basic functionality from #26 to integrate rectilinear grid handling. This allows development of the unstructured regridder to continue.

@codecov
Copy link

codecov bot commented Mar 1, 2021

Codecov Report

Merging #32 (d05784c) into unstructured_scheme (bddb48e) will increase coverage by 2.64%.
The diff coverage is 100.00%.

Impacted file tree graph

@@                   Coverage Diff                   @@
##           unstructured_scheme      #32      +/-   ##
=======================================================
+ Coverage                88.43%   91.08%   +2.64%     
=======================================================
  Files                       10       11       +1     
  Lines                      346      415      +69     
=======================================================
+ Hits                       306      378      +72     
+ Misses                      40       37       -3     
Impacted Files Coverage Δ
esmf_regrid/experimental/unstructured_scheme.py 48.07% <100.00%> (+16.36%) ⬆️
...ntal/unstructured_scheme/test__cube_to_GridInfo.py 100.00% <100.00%> (ø)
esmf_regrid/esmf_regridder.py 92.92% <0.00%> (+2.02%) ⬆️

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 bddb48e...d05784c. Read the comment docs.

rg = Regridder(gridinfo, gridinfo)
expected_weights = scipy.sparse.identity(n_lats * n_lons)
assert np.array_equal(expected_weights.todense(), rg.weight_matrix.todense())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Separate these into two tests, consider the naming convention (keep consistent with iris).

@@ -28,7 +37,17 @@ def _cube_to_MeshInfo(cube):
def _cube_to_GridInfo(cube):
# Returns a GridInfo object describing the horizontal grid of the cube.
# This may be inherited from code written for the rectilinear regridding scheme.
pass
lat = cube.coord("latitude")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to confirm that the incoming cube is a gridded cube?


def test_cube_to_GridInfo():
"""Basic test for :func:`~esmf_regrid.experimental.unstructured_scheme._cube_to_GridInfo`."""
n_lats = 5
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should have a test for n_lats=1. I believe this could be passed in. Not sure what the final behaviour is!



def _grid_cube(n_lons, n_lats, lon_bounds, lat_bounds, circular=False):
lon_lower, lon_upper = lon_bounds
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 13-17 are identical to 22-27. And only the ll_bound_span needs to be returned in both cases.
Lets refactor and tidy this up - then its looking good.

lat = cube.coord("latitude")
# Ensure coords come from a proper grid.
assert isinstance(lon, iris.coords.DimCoord)
assert isinstance(lat, iris.coords.DimCoord)
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this - but I've just had a thought as to whether the scalar passes. Let's just confirm, and remove these lines if they are more problematic than helpful!

Copy link
Contributor

Choose a reason for hiding this comment

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

The scalar test is passing fine with this.
Having discussed this with @stephenworsley , we think this is because the information is added to the Cube as a DimCoord, then it becomes a scalar as it has length 1. Hence the test and the data process correctly.

@abooton abooton merged commit 036d3bb into SciTools:unstructured_scheme Mar 3, 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