Skip to content

Commit 7827ba4

Browse files
authored
Merge pull request #750 from davidhassell/regridc-fix
1-d Z Cartesian regridding fix and test
2 parents 627105b + 7e9e9fb commit 7827ba4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

cf/regrid/regrid.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,14 +988,14 @@ def Cartesian_coords_to_domain(dst, dst_z=None, domain_class=None):
988988

989989
if dst_z is not None:
990990
# Check that there are vertical coordinates, and replace
991-
# 'dst_z' with its construct identifier.
991+
# 'dst_z' with the identifier of its domain axis construct.
992992
z_key = d.coordinate(dst_z, key=True, default=None)
993993
if z_key is None:
994994
raise ValueError(
995995
f"Could not find destination {dst_z!r} vertical coordinates"
996996
)
997997

998-
dst_z = z_key
998+
dst_z = d.get_data_axes(z_key)[0]
999999

10001000
return d, axis_keys, dst_z
10011001

@@ -2112,7 +2112,6 @@ def create_esmpy_grid(grid, mask=None):
21122112
# masked/unmasked elements.
21132113
grid_mask[...] = np.invert(mask).astype("int32")
21142114

2115-
# print(esmpy_grid)
21162115
return esmpy_grid
21172116

21182117

cf/test/test_regrid.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ class RegridTest(unittest.TestCase):
157157
dst = dst_src[0]
158158
src = dst_src[1]
159159

160+
filename_xyz = os.path.join(
161+
os.path.dirname(os.path.abspath(__file__)), "regrid_xyz.nc"
162+
)
163+
160164
@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
161165
def test_Field_regrid_2d_field(self):
162166
"""2-d regridding with Field destination grid."""
@@ -735,6 +739,17 @@ def test_Field_regridc_1d_field(self):
735739
with self.assertRaises(ValueError):
736740
src.regridc(dst, method=method, axes=axes)
737741

742+
@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
743+
def test_Field_regridc_1d_coordinates_z(self):
744+
"""1-d Z Cartesian regridding with coordinates destination grid."""
745+
src = cf.read(self.filename_xyz)[0]
746+
dst = cf.DimensionCoordinate(
747+
data=cf.Data([800, 705, 632, 510, 320.0], "hPa")
748+
)
749+
d = src.regridc([dst], method="linear", axes="Z", z="Z", ln_z=True)
750+
z = d.dimension_coordinate("Z")
751+
self.assertTrue(z.data.equals(dst.data))
752+
738753
@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
739754
def test_Field_regrid_chunks(self):
740755
"""Regridding of chunked axes"""

0 commit comments

Comments
 (0)