Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-d Z Cartesian regridding fix and test #750

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cf/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,11 @@ def __getitem__(self, indices):
# below.
if org_cyclic:
new_cyclic = new_data.cyclic()
[new.cyclic(i, iscyclic=False) for i in org_cyclic if i not in new_cyclic]

[
new.cyclic(i, iscyclic=False)
for i in org_cyclic
if i not in new_cyclic
]

# ------------------------------------------------------------
# Subspace constructs with data
Expand Down
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
Loading