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

Unify unstructured and rectilinear schemes (curvilinear support) #175

Merged
merged 16 commits into from
Jun 23, 2022

Conversation

stephenworsley
Copy link
Contributor

Generalises the helper functions (_cube_to_GridInfo and _create_cube) so that one of each type of function can be used for all regridding schemes. This reduces code copying and begins to unify the behaviour of the regridders.

This adds curvilinear support to the unstructured regridders.

@codecov
Copy link

codecov bot commented Apr 27, 2022

Codecov Report

Merging #175 (d2e22bc) into main (90ac73a) will decrease coverage by 0.01%.
The diff coverage is 99.54%.

@@            Coverage Diff             @@
##             main     #175      +/-   ##
==========================================
- Coverage   99.40%   99.38%   -0.02%     
==========================================
  Files          28       28              
  Lines        2703     2785      +82     
==========================================
+ Hits         2687     2768      +81     
- Misses         16       17       +1     
Impacted Files Coverage Δ
esmf_regrid/schemes.py 97.65% <96.15%> (-0.59%) ⬇️
esmf_regrid/experimental/io.py 100.00% <100.00%> (ø)
esmf_regrid/experimental/unstructured_scheme.py 99.00% <100.00%> (-0.17%) ⬇️
.../tests/unit/experimental/io/test_round_tripping.py 100.00% <100.00%> (ø)
...nstructured_scheme/test_GridToMeshESMFRegridder.py 100.00% <100.00%> (ø)
...nstructured_scheme/test_MeshToGridESMFRegridder.py 100.00% <100.00%> (ø)
...erimental/unstructured_scheme/test__create_cube.py 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@stephenworsley stephenworsley marked this pull request as ready for review April 28, 2022 11:58
esmf_regrid/experimental/io.py Outdated Show resolved Hide resolved
esmf_regrid/experimental/io.py Outdated Show resolved Hide resolved
esmf_regrid/experimental/io.py Outdated Show resolved Hide resolved
esmf_regrid/experimental/io.py Outdated Show resolved Hide resolved
esmf_regrid/experimental/io.py Outdated Show resolved Hide resolved
Copy link

@wjbenfold wjbenfold left a comment

Choose a reason for hiding this comment

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

I like how this has gone, but I still think we can make it easier to read/maintain:

    if regridder_type == "GridToMeshESMFRegridder":
        grid_name = SOURCE_NAME
        mesh_name = TARGET_NAME
    elif regridder_type == "MeshToGridESMFRegridder":
        mesh_name = SOURCE_NAME
        grid_name = TARGET_NAME
    else:
        msg = (
            f"Expected a regridder of type `GridToMeshESMFRegridder` or "
            f"`MeshToGridESMFRegridder`, got type {regridder_type}."
        )
        raise TypeError(msg)

    grid_cube = _standard_grid_cube((rg.grid_y, rg.grid_x), grid_name)

    mesh_coords = rg.mesh.to_MeshCoords(rg.location)
    mesh_data = np.zeros(tgt_mesh_coords[0].points.shape[0])
    mesh_cube = Cube(tgt_data, var_name=mesh_name, long_name=mesh_name)
    for coord in tgt_mesh_coords:
        mesh_cube.add_aux_coord(coord, 0)

We then wouldn't need the if/else here too https://github.com/SciTools-incubator/iris-esmf-regrid/blob/d2e22bc97283512a0c4fab131818f4b0c1643b8d/esmf_regrid/experimental/io.py#L147-L150

@stephenworsley
Copy link
Contributor Author

We then wouldn't need the if/else here too

Actually, I think we can get rid of this anyway because it seems like the bug in iris it's trying to work around has been fixed.

I'm hesitant to organise the cubes by being mesh_cube and grid_cube because I plan on extending the saving to the grid-to-grid regridder, where there will be two grid cubes. I think the only consistent way to distinguish them is by being source and target.

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