Unstructured Scheme - Cube Creation 3D#47
Conversation
Codecov Report
@@ Coverage Diff @@
## unstructured_scheme #47 +/- ##
=======================================================
+ Coverage 98.15% 98.27% +0.11%
=======================================================
Files 16 16
Lines 652 695 +43
=======================================================
+ Hits 640 683 +43
Misses 12 12
Continue to review full report at Codecov.
|
jamesp
left a comment
There was a problem hiding this comment.
Looking good @stephenworsley , a few comments inline
| dims = src_cube.coord_dims(coord) | ||
| if hasattr(coord, "mesh") or mesh_dim in dims: | ||
| continue | ||
| dims = [dim if dim < mesh_dim else dim + 1 for dim in dims] |
There was a problem hiding this comment.
Can we have a comment to explain this line?
I think from the continue statement above, dim will never equal mesh_dim, but explaining why it's going to be necessary to shift all later dimensions by 1 would make it clearer.
There was a problem hiding this comment.
If this code has been copied from iris then this comment probably belongs there too!
There was a problem hiding this comment.
This line is new.
| continue | ||
| dims = [dim if dim < mesh_dim else dim + 1 for dim in dims] | ||
| result_coord = coord.copy() | ||
| add_method(result_coord, dims) |
There was a problem hiding this comment.
I think I get this, but slightly confusing as we're not returning anything from this function. Is this because add_method is always going to be a method on a cube to which we are now appending these new coordinates, so the state change happens on the add_method owner?
| @@ -88,10 +88,6 @@ def _create_cube(data, src_cube, mesh_dim, grid_x, grid_y): | |||
|
|
|||
There was a problem hiding this comment.
See Line 85: describes a mesh object, but this is no longer part of the _create_cube signature
| grid_y = DimCoord(np.arange(2), standard_name="latitude") | ||
|
|
||
| cube = _create_cube(data, src_cube, mesh_dim, grid_x, grid_y) | ||
| src_metadata = src_cube.metadata |
There was a problem hiding this comment.
should _create_cube be handling metadata as well?
There was a problem hiding this comment.
_create_cube already handles metadata, this is also the case in iris.
There was a problem hiding this comment.
Ah yes, sorry I misread this section. You're getting the source metadata to attach to the expected_cube, not to cube.
| src_cube.attributes = {"a": 1} | ||
| src_cube.standard_name = "air_temperature" | ||
| scalar_height = AuxCoord([5], units="m", standard_name="height") | ||
| scalar_time = DimCoord([10], units="s", standard_name="time") |
There was a problem hiding this comment.
Is this right? Adding a DimCoord as an add_aux_coord?
There was a problem hiding this comment.
This is a bit of Iris weirdness. While DimCoord and AuxCoord are different classes, a cube also has two "boxes" to put coords in: _aux_coords_and_dims and _dim_coords_and_dims. Somewhat counterintuitively, _aux_coords_and_dims can contain DimCoords. In fact, since this is a scalar coordinate, it has to be added to _aux_coords_and_dims since it does not describe a dimension (all coords in _dim_coords_and_dims must be associated with a dimension). Scalar DimCoords will be generated when a cube is sliced, so these are worth considering and testing with.
There was a problem hiding this comment.
Great, thanks for the explanation. With that in mind, are we comfortable these tests are sufficiently complete in their coverage for now?
There was a problem hiding this comment.
I think so, there's still some stuff like derived coordinates which we might want to add in the future, but I think this covers the main stuff.
420904e to
1bb659f
Compare
* handle extra dims in _create_cube * add test * lint fix * address review comment
* unstructured_scheme: Add grid to mesh scheme (SciTools#96) Unstructured scheme integration test (SciTools#66) Updated lockfiles according to branch requirement spec. Update Version to v0.1.dev2 (SciTools#59) Update version to v0.1.dev1 (SciTools#58) Unstructured Scheme - Extra Dims (SciTools#55) add __init__ to tests (SciTools#56) Unstructured Scheme - Additional Polish (docstrings and test coverage) (SciTools#53) Unstructured Scheme - Cube Creation 3D (SciTools#47) fix test (SciTools#52) Update unstructured_scheme Feature Branch (SciTools#51) # Conflicts: # esmf_regrid/__init__.py # requirements/nox.lock/py36-linux-64.lock # requirements/nox.lock/py37-linux-64.lock # requirements/nox.lock/py38-linux-64.lock
* unstructured_scheme: (22 commits) Check mesh equality on MeshToGridESMFRegridder call (SciTools#138) Formalise regridder file format (SciTools#137) Fix issue 135 (mesh to grid chunking problems) (SciTools#136) Add load/save benchmarks (SciTools#132) Regridder load/saving (SciTools#130) Update dependencies (SciTools#128) Perform scalability for larger grids (SciTools#122) Add performance tests (SciTools#117) change iris source (SciTools#115) Unstructured scheme lazy regridding (with performance tests) (SciTools#111) Updating feature branch unstructured_scheme from 44d6048 to head of main, e528cbf Add grid to mesh scheme (SciTools#96) Unstructured scheme integration test (SciTools#66) Updated lockfiles according to branch requirement spec. Update Version to v0.1.dev2 (SciTools#59) Update version to v0.1.dev1 (SciTools#58) Unstructured Scheme - Extra Dims (SciTools#55) add __init__ to tests (SciTools#56) Unstructured Scheme - Additional Polish (docstrings and test coverage) (SciTools#53) Unstructured Scheme - Cube Creation 3D (SciTools#47) ... # Conflicts: # benchmarks/benchmarks/ci/esmf_regridder.py # benchmarks/benchmarks/generate_data.py # requirements/nox.lock/py36-linux-64.lock # requirements/nox.lock/py37-linux-64.lock # requirements/nox.lock/py38-linux-64.lock # requirements/py36.yml
Expands on #39 by adding the ability to handle cubes with additional dimensions. Specifically, this copies from the source cube all DimCoords and AuxCoords which do not span the mesh dimension. Derived coordinates are a more complicated case which may be added in a future PR.