Skip to content

[Bug]: regridder.horizontal() with xesmf fails in 0.11.4 on datasets that worked in 0.11.3 #850

Closed

Description

@chengzhuzhang

What happened?

After upgrading from xcdat 0.11.3 to 0.11.4, ds.regridder.horizontal(..., tool="xesmf") raises on two kinds of datasets that regridded without error in 0.11.3:

  1. A scalar Z coordinate plus a Z dimension used by another variable. The Dataset has a scalar height coordinate (axis: "Z") and a separate plev dimension used by other data variables. Regridding a 2D variable that uses neither raises:

    ValueError: Multiple 'Z' axis dims were found in this dataset, ['plev']. Please drop the unused dimension(s) before performing grid operations.
    

    In our full traceback, this is raised while handling an earlier ValueError: Coordinate '<xarray.DataArray 'height' ()> ...' is a singleton and cannot be used. from _get_axis_coord_and_bounds.

  2. lat/lon dimension coordinates with no CF attributes. Regridding raises:

    KeyError: "No 'X' axis dimension coordinate variables were found in the xarray object. ..."
    

    from _get_input_grid → get_dim_coords.

Both shapes occur in real observational climatology files: ERA5 and MERRA2 for case 1, and an AIRS OLR product for case 2. In E3SM Diags this silently dropped ~330 of ~2,000 plots from a routine model-vs-obs run.

What did you expect to happen?

The same behavior as 0.11.3: both datasets regrid without error.

Minimal Complete Verifiable Example

import numpy as np
import xarray as xr
import xcdat

lat = np.arange(-89.5, 90, 1.0)
lon = np.arange(0.5, 360, 1.0)
output_grid = xcdat.create_uniform_grid(-88.0, 88.0, 2.0, 1.0, 359.0, 2.0)

# Case 1: scalar Z coordinate (`height`) plus a separate `plev` dimension used
# by another variable in the same Dataset.
ds1 = xr.Dataset(
    {
        "tauu": (("lat", "lon"), np.random.rand(lat.size, lon.size)),
        "ta": (("plev", "lat", "lon"), np.random.rand(2, lat.size, lon.size)),
    },
    coords={
        "lat": ("lat", lat, {"axis": "Y", "units": "degrees_north"}),
        "lon": ("lon", lon, {"axis": "X", "units": "degrees_east"}),
        "plev": ("plev", [85000.0, 50000.0], {"axis": "Z", "units": "Pa", "standard_name": "air_pressure", "positive": "down"}),
        "height": ((), 10.0, {"axis": "Z", "units": "m", "standard_name": "height", "positive": "up"}),
    },
).bounds.add_missing_bounds(axes=["X", "Y"])

# Case 2: lat/lon dimension coordinates with no CF attributes.
ds2 = xr.Dataset(
    {"olr": (("lat", "lon"), np.random.rand(lat.size, lon.size))},
    coords={"lat": lat, "lon": lon},
).bounds.add_missing_bounds(axes=["X", "Y"])

print(f"xcdat {xcdat.__version__}, xarray {xr.__version__}")
for name, ds, var in (("case 1", ds1, "tauu"), ("case 2", ds2, "olr")):
    try:
        ds.regridder.horizontal(var, output_grid, tool="xesmf", method="bilinear")
        print(f"{name}: OK")
    except Exception as e:
        print(f"{name}: {type(e).__name__}: {str(e).splitlines()[0]}")

Output in the same environment, changing only the xcdat version:

xcdat 0.11.3, xarray 2026.7.0
case 1: OK
case 2: OK
xcdat 0.11.4, xarray 2026.7.0
case 1: ValueError: Multiple 'Z' axis dims were found in this dataset, ['plev']. Please drop the unused dimension(s) before performing grid operations.
case 2: KeyError: "No 'X' axis dimension coordinate variables were found in the xarray object. Make sure dimension coordinate variables exist, they are one dimensional, and their CF 'axis' or 'standard_name' attrs are correctly set."

Relevant log output

Case 1 traceback from the E3SM Diags run (trimmed):

  File ".../xcdat/regridder/accessor.py", line 170, in horizontal
    input_grid = _get_input_grid(
        self._ds, data_var, ["X", "Y"], multidim=regrid_tool.can_handle_multidim()
    )
  File ".../xcdat/regridder/accessor.py", line 402, in _get_input_grid
    grid = _obj_to_grid_ds(input_grid, multidim=multidim)
  File ".../xcdat/regridder/accessor.py", line 289, in _obj_to_grid_ds
    coord, bounds = _get_axis_coord_and_bounds(obj, axis, multidim=multidim)
  File ".../xcdat/regridder/accessor.py", line 337, in _get_axis_coord_and_bounds
    _validate_grid_has_single_axis_dim(axis, coord_var)
  File ".../xcdat/regridder/grid.py", line 744, in _validate_grid_has_single_axis_dim
ValueError: Multiple 'Z' axis dims were found in this dataset, ['plev']. ...

Case 2 traceback (trimmed):

  File ".../xcdat/regridder/accessor.py", line 170, in horizontal
  File ".../xcdat/regridder/accessor.py", line 387, in _get_input_grid
  File ".../xcdat/axis.py", line 153, in get_dim_coords
KeyError: "No 'X' axis dimension coordinate variables were found in the xarray object. ..."

Anything else we need to know?

  • This appears to come from Support multidimensional coordinates for bounds and regridding #820 (multidimensional coordinates for bounds and regridding). It is the only commit between v0.11.3 and v0.11.4 that changes xcdat/ source, apart from the version bump. It modifies _get_input_grid, _obj_to_grid_ds, _get_axis_coord_and_bounds and get_dim_coords, which are the functions in both tracebacks.
  • With tool="regrid2", case 1 succeeds on 0.11.4. We did not test case 2 with regrid2 in isolation.

Environment

  • xcdat 0.11.4 (fails) vs 0.11.3 (passes)
  • xarray 2026.7.0, xesmf 0.9.2, cf_xarray 0.11.3, numpy 2.5.3, Python 3.14.7
  • Linux (LCRC Chrysalis), e3sm-unified 1.14.0rc2 conda environment

Activity

  1. tomvothecoder commented on Oct 7, 2026

    @tomvothecoder
    Collaborator

    Thanks for reporting. I will have a fix ASAP and tag you to test, then I will release a new xCDAT version.

  2. pochedls commented on Oct 7, 2026

    @pochedls
    Collaborator

    Thanks for reporting. I will have a fix ASAP and tag you to test, then I will release a new xCDAT version.

    Tag me too? I partially blame myself for this since the last release was patching another regridding issue. I tested the release on curvilinear grids (the source of the issue I was having), but not on rectilinear grids. I can test this new release on a wider array of data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions