-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
852ba0d
commit f75498a
Showing
2 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
esmf_regrid/tests/unit/experimental/unstructured_scheme/test__create_cube.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Unit tests for miscellaneous helper functions in `esmf_regrid.experimental.unstructured_scheme`.""" | ||
|
||
import iris | ||
import numpy as np | ||
|
||
from esmf_regrid.experimental.unstructured_scheme import _create_cube | ||
|
||
|
||
def test_create_cube_2D(): | ||
"""Test creation of 2D output grid.""" | ||
data = np.ones([2, 3]) | ||
|
||
# Create a source cube with metadata and scalar coords | ||
src_cube = iris.cube.Cube(np.zeros(5)) | ||
src_cube.units = "K" | ||
src_cube.attributes = {"a": 1} | ||
src_cube.standard_name = "air_temperature" | ||
scalar_height = iris.coords.AuxCoord([5], units="m", standard_name="height") | ||
scalar_time = iris.coords.DimCoord([10], units="s", standard_name="time") | ||
src_cube.add_aux_coord(scalar_height) | ||
src_cube.add_aux_coord(scalar_time) | ||
|
||
mesh_dim = 0 | ||
|
||
grid_x = iris.coords.DimCoord(np.arange(3), standard_name="longitude") | ||
grid_y = iris.coords.DimCoord(np.arange(2), standard_name="latitude") | ||
|
||
cube = _create_cube(data, src_cube, mesh_dim, grid_x, grid_y) | ||
src_metadata = src_cube.metadata | ||
|
||
expected_cube = iris.cube.Cube(data) | ||
expected_cube.metadata = src_metadata | ||
expected_cube.add_dim_coord(grid_x, 1) | ||
expected_cube.add_dim_coord(grid_y, 0) | ||
expected_cube.add_aux_coord(scalar_height) | ||
expected_cube.add_aux_coord(scalar_time) | ||
assert expected_cube == cube |