Skip to content

Commit

Permalink
Merge pull request #750 from davidhassell/regridc-fix
Browse files Browse the repository at this point in the history
1-d Z Cartesian regridding fix and test
  • Loading branch information
davidhassell committed Mar 26, 2024
2 parents 627105b + 7e9e9fb commit 7827ba4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cf/regrid/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,14 +988,14 @@ def Cartesian_coords_to_domain(dst, dst_z=None, domain_class=None):

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

dst_z = z_key
dst_z = d.get_data_axes(z_key)[0]

return d, axis_keys, dst_z

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

# print(esmpy_grid)
return esmpy_grid


Expand Down
15 changes: 15 additions & 0 deletions cf/test/test_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ class RegridTest(unittest.TestCase):
dst = dst_src[0]
src = dst_src[1]

filename_xyz = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "regrid_xyz.nc"
)

@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
def test_Field_regrid_2d_field(self):
"""2-d regridding with Field destination grid."""
Expand Down Expand Up @@ -735,6 +739,17 @@ def test_Field_regridc_1d_field(self):
with self.assertRaises(ValueError):
src.regridc(dst, method=method, axes=axes)

@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
def test_Field_regridc_1d_coordinates_z(self):
"""1-d Z Cartesian regridding with coordinates destination grid."""
src = cf.read(self.filename_xyz)[0]
dst = cf.DimensionCoordinate(
data=cf.Data([800, 705, 632, 510, 320.0], "hPa")
)
d = src.regridc([dst], method="linear", axes="Z", z="Z", ln_z=True)
z = d.dimension_coordinate("Z")
self.assertTrue(z.data.equals(dst.data))

@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
def test_Field_regrid_chunks(self):
"""Regridding of chunked axes"""
Expand Down

0 comments on commit 7827ba4

Please sign in to comment.