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 - Cube Creation 2D #39

Conversation

stephenworsley
Copy link
Contributor

Fleshes out the creation of cubes. Now adds grid coordinates from the target cube and copies over metadata and scalar coords from the source cube. Code is mostly copied from a similar iris functionality here https://github.com/SciTools/iris/blob/master/lib/iris/analysis/_regrid.py#L360-L363.

@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #39 (300fde8) into unstructured_scheme (852ba0d) will increase coverage by 0.91%.
The diff coverage is 94.11%.

Impacted file tree graph

@@                   Coverage Diff                   @@
##           unstructured_scheme      #39      +/-   ##
=======================================================
+ Coverage                92.08%   93.00%   +0.91%     
=======================================================
  Files                       12       13       +1     
  Lines                      455      486      +31     
=======================================================
+ Hits                       419      452      +33     
+ Misses                      36       34       -2     
Impacted Files Coverage Δ
esmf_regrid/experimental/unstructured_scheme.py 60.65% <77.77%> (+7.92%) ⬆️
...erimental/unstructured_scheme/test__create_cube.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 852ba0d...300fde8. Read the comment docs.

new_cube.metadata = copy.deepcopy(src_cube.metadata)

for coord in src_cube.coords(dimensions=()):
new_cube.add_aux_coord(coord.copy())
Copy link
Contributor Author

@stephenworsley stephenworsley Mar 22, 2021

Choose a reason for hiding this comment

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

Code is copied from https://github.com/SciTools/iris/blob/f76288cb82eefc5bc3c74461bfd8f397618eda14/lib/iris/analysis/_regrid.py#L360-L363 . This is from a regridder which is specifically for 2D cubes.

This code is likely to be replaced when we update to handle more dimensions.

@@ -70,7 +72,7 @@ def _cube_to_GridInfo(cube):
# return result


def _create_cube(data, src_cube, mesh_dim, mesh, grid_x, grid_y):
def _create_cube(data, src_cube, mesh_dim, grid_x, grid_y):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally this followed a pattern seen for example here. In this pattern, (x_dim, y_dim) is equivalent to mesh_dim and (src_x_coord, src_y_coord) is equivalent to mesh. If we followed the same pattern then the purpose of mesh would be to determine which coordinates to copy over from src_cube to the new cube, this would be done by performing a comparison which used mesh. We anticipate that this would be done in multidimensional regridding. However, since a cube can only have one mesh, all that will need to be checked is whether the coord is a MeshCoord (or has a mesh attribute). It is therefore unlikely we will need mesh during cube creation and so I am removing it from the arguments.

@@ -81,7 +83,13 @@ def _create_cube(data, src_cube, mesh_dim, mesh, grid_x, grid_y):

new_cube = iris.cube.Cube(data)

# TODO: add coords and metadata.
new_cube.add_dim_coord(grid_x, mesh_dim + 1)
new_cube.add_dim_coord(grid_y, mesh_dim)
Copy link
Contributor Author

@stephenworsley stephenworsley Mar 22, 2021

Choose a reason for hiding this comment

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

The dimension ordering is set so that grid_y is explicitly before grid_x. This will be the case even if the dimension ordering is the other way around in the target cube. The ability to be preserve the target cube dimension ordering may be added in future.

TODO: add a comment describing this design decision.

Copy link
Member

Choose a reason for hiding this comment

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

@stephenworsley thanks for making the changes we discussed. could you make this comment just a tad more descriptive of what would need to be done? i.e. this is the specific case that will work for 2D, but needs to be reworked for 3D. Thanks!

@stephenworsley stephenworsley force-pushed the unstructured_scheme_create_cube branch from 4120efa to 3155be3 Compare March 22, 2021 15:03
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.

Great work @stephenworsley , LGTM!

@jamesp jamesp merged commit f75498a into SciTools:unstructured_scheme Mar 23, 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 <[email protected]>
Co-authored-by: Anna Booton <[email protected]>
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 <[email protected]>
Co-authored-by: Anna Booton <[email protected]>
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