Skip to content

Commit

Permalink
moved import constants to bottom; it's something like this
Browse files Browse the repository at this point in the history
  • Loading branch information
ESadek-MO committed Jul 31, 2023
1 parent e4d6b16 commit f5b9994
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numpy import ma

from esmf_regrid import esmpy
from .... import Constants
from esmf_regrid import Constants
from esmf_regrid.esmf_regridder import GridInfo, Regridder
from esmf_regrid.tests import make_grid_args

Expand Down
2 changes: 1 addition & 1 deletion esmf_regrid/tests/unit/esmf_regridder/test_Regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import scipy.sparse

from .... import Constants
from esmf_regrid import Constants
from esmf_regrid.esmf_regridder import GridInfo, Regridder
from esmf_regrid.tests import make_grid_args

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
from numpy import ma
import pytest
from ..... import Constants

from esmf_regrid.experimental.io import load_regridder, save_regridder
from esmf_regrid.experimental.unstructured_scheme import (
Expand All @@ -17,6 +16,7 @@
from esmf_regrid.tests.unit.schemes.test__mesh_to_MeshInfo import (
_gridlike_mesh_cube,
)
from esmf_regrid import Constants


def _make_grid_to_mesh_regridder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import numpy as np
from numpy import ma

from ..... import Constants
from esmf_regrid.esmf_regridder import GridInfo, Regridder
from esmf_regrid.experimental.unstructured_regrid import MeshInfo
from esmf_regrid.tests import get_result_path, make_grid_args

from esmf_regrid import Constants

def _make_small_mesh_args():
ugrid_node_coords = np.array(
Expand Down Expand Up @@ -112,9 +112,7 @@ 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 @@ -135,17 +133,13 @@ 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 @@ -7,7 +7,6 @@
from numpy import ma
import pytest

from ..... import Constants
from esmf_regrid.experimental.unstructured_scheme import (
GridToMeshESMFRegridder,
)
Expand All @@ -22,7 +21,7 @@
from esmf_regrid.tests.unit.schemes.test__regrid_unstructured_to_rectilinear__prepare import (
_flat_mesh_cube,
)

from esmf_regrid import Constants

def _add_metadata(cube):
result = cube.copy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
import pytest

from ..... import Constants
from esmf_regrid.experimental.unstructured_scheme import (
MeshToGridESMFRegridder,
)
Expand All @@ -22,6 +21,7 @@
_flat_mesh_cube,
_full_mesh,
)
from esmf_regrid import Constants


def _add_metadata(cube):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from numpy import ma
import pytest

from ..... import Constants
from esmf_regrid.experimental.unstructured_scheme import (
regrid_rectilinear_to_unstructured,
)
Expand All @@ -19,7 +18,7 @@
from esmf_regrid.tests.unit.schemes.test__regrid_unstructured_to_rectilinear__prepare import (
_flat_mesh_cube,
)

from esmf_regrid import Constants

def _add_metadata(cube):
result = cube.copy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import pytest

from ..... import Constants
from esmf_regrid.experimental.unstructured_scheme import (
regrid_unstructured_to_rectilinear,
)
Expand All @@ -19,7 +18,7 @@
_flat_mesh_cube,
_full_mesh,
)

from esmf_regrid import Constants

def _add_metadata(cube):
result = cube.copy()
Expand Down Expand Up @@ -65,9 +64,7 @@ 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 @@ -115,35 +112,25 @@ 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 @@ -4,7 +4,6 @@
from iris.cube import Cube
import numpy as np

from .... import Constants
from esmf_regrid.esmf_regridder import GridInfo
from esmf_regrid.experimental.unstructured_regrid import MeshInfo
from esmf_regrid.schemes import (
Expand All @@ -16,7 +15,7 @@
from esmf_regrid.tests.unit.schemes.test__mesh_to_MeshInfo import (
_example_mesh,
)

from esmf_regrid import Constants

def _full_mesh():
mesh = _example_mesh()
Expand Down

0 comments on commit f5b9994

Please sign in to comment.