Skip to content

Commit 7e9e9fb

Browse files
committed
1-d Z Cartesian regridding fix and test
1 parent de6d0b5 commit 7e9e9fb

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

cf/field.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,11 @@ def __getitem__(self, indices):
454454
# below.
455455
if org_cyclic:
456456
new_cyclic = new_data.cyclic()
457-
[new.cyclic(i, iscyclic=False) for i in org_cyclic if i not in new_cyclic]
458-
457+
[
458+
new.cyclic(i, iscyclic=False)
459+
for i in org_cyclic
460+
if i not in new_cyclic
461+
]
459462

460463
# ------------------------------------------------------------
461464
# Subspace constructs with data

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)