Skip to content

Commit

Permalink
Merge branch 'test' of github.com:ESadek-MO/iris-esmf-regrid into test
Browse files Browse the repository at this point in the history
  • Loading branch information
ESadek-MO committed Aug 7, 2023
2 parents 651556b + 8c6079c commit cff1b0a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from esmf_regrid.tests import get_result_path, make_grid_args



def _make_small_mesh_args():
ugrid_node_coords = np.array(
[[0.0, 0.0], [0.0, 10.0], [10.0, 0.0], [10.0, 10.0], [10.0, 20.0]]
Expand Down Expand Up @@ -112,7 +113,9 @@ def test_regrid_bilinear_with_mesh():
grid_args = [ar * 2 for ar in make_grid_args(2, 3)]
grid = GridInfo(*grid_args, center=True)

mesh_to_grid_regridder = Regridder(node_mesh, grid, method=Constants.Method.BILINEAR)
mesh_to_grid_regridder = Regridder(
node_mesh, grid, method=Constants.Method.BILINEAR
)
mesh_input = np.arange(5)
grid_output = mesh_to_grid_regridder.regrid(mesh_input)
# For a flat surface, we would expect the fractional part of these values
Expand All @@ -133,13 +136,17 @@ def test_regrid_bilinear_with_mesh():
expected_grid_output = ma.array(expected_grid_output, mask=expected_grid_mask)
assert ma.allclose(expected_grid_output, grid_output)

grid_to_mesh_regridder = Regridder(grid, node_mesh, method=Constants.Method.BILINEAR)
grid_to_mesh_regridder = Regridder(
grid, node_mesh, method=Constants.Method.BILINEAR
)
grid_input = np.array([[0, 0], [1, 0], [2, 1]])
mesh_output = grid_to_mesh_regridder.regrid(grid_input)
expected_mesh_output = ma.array([0.0, 1.5, 0.0, 0.5, -1], mask=[0, 0, 0, 0, 1])
assert ma.allclose(expected_mesh_output, mesh_output)

grid_to_face_mesh_regridder = Regridder(grid, face_mesh, method=Constants.Method.BILINEAR)
grid_to_face_mesh_regridder = Regridder(
grid, face_mesh, method=Constants.Method.BILINEAR
)
grid_input_2 = np.array([[0, 0], [1, 0], [4, 1]])
face_mesh_output = grid_to_face_mesh_regridder.regrid(grid_input_2)
expected_face_mesh_output = np.array([0.0, 1.4888258584989558])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
_flat_mesh_cube,
)


def _add_metadata(cube):
result = cube.copy()
result.units = "K"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from esmf_regrid import Constants


def _add_metadata(cube):
result = cube.copy()
result.units = "K"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
_full_mesh,
)


def _add_metadata(cube):
result = cube.copy()
result.units = "K"
Expand Down Expand Up @@ -65,7 +66,9 @@ def test_flat_cubes():
assert expected_cube == result


@pytest.mark.parametrize("method", (Constants.Method.BILINEAR, Constants.Method.NEAREST))
@pytest.mark.parametrize(
"method", (Constants.Method.BILINEAR, Constants.Method.NEAREST)
)
def test_node_friendly_methods(method):
"""
Basic test for :func:`esmf_regrid.experimental.unstructured_scheme.regrid_unstructured_to_rectilinear`.
Expand Down Expand Up @@ -113,25 +116,35 @@ def test_invalid_args():
tgt = _grid_cube(n_lons, n_lats, lon_bounds, lat_bounds, circular=True)

with pytest.raises(ValueError):
_ = regrid_unstructured_to_rectilinear(tgt, tgt, method=Constants.Method.BILINEAR)
_ = regrid_unstructured_to_rectilinear(
tgt, tgt, method=Constants.Method.BILINEAR
)
with pytest.raises(NotImplementedError):
_ = regrid_unstructured_to_rectilinear(face_src, tgt, method=Constants.Method.NEAREST)
_ = regrid_unstructured_to_rectilinear(
face_src, tgt, method=Constants.Method.NEAREST
)
with pytest.raises(ValueError) as excinfo:
_ = regrid_unstructured_to_rectilinear(node_src, tgt, method=Constants.Method.CONSERVATIVE)
_ = regrid_unstructured_to_rectilinear(
node_src, tgt, method=Constants.Method.CONSERVATIVE
)
expected_message = (
"Conservative regridding requires a source cube located on "
"the face of a cube, target cube had the node location."
)
assert expected_message in str(excinfo.value)
with pytest.raises(ValueError) as excinfo:
_ = regrid_unstructured_to_rectilinear(edge_src, tgt, method=Constants.Method.BILINEAR)
_ = regrid_unstructured_to_rectilinear(
edge_src, tgt, method=Constants.Method.BILINEAR
)
expected_message = (
"bilinear regridding requires a source cube with a node "
"or face location, target cube had the edge location."
)
assert expected_message in str(excinfo.value)
with pytest.raises(ValueError) as excinfo:
_ = regrid_unstructured_to_rectilinear(edge_src, tgt, method=Constants.Method.NEAREST)
_ = regrid_unstructured_to_rectilinear(
edge_src, tgt, method=Constants.Method.NEAREST
)
expected_message = (
"nearest regridding requires a source cube with a node "
"or face location, target cube had the edge location."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
_example_mesh,
)


def _full_mesh():
mesh = _example_mesh()

Expand Down

0 comments on commit cff1b0a

Please sign in to comment.