Skip to content

[Bug]: regrid error for a specific dataset #836

@lee1043

Description

@lee1043

What happened?

Regrid for the sample data (attached) returns error.

sample_data.nc.zip

The sample data was created in the following way:

input_file2 = '/global/cfs/projectdirs/m3522/datalake/HadISST/HadISST_sst.nc'
ds2 = xc.open_dataset(input_file2).isel(time=slice(0,5))
ds2.to_netcdf("sample_data.nc")

What did you expect to happen? Are there are possible answers you came across?

No response

Minimal Complete Verifiable Example (MVCE)

ds = xc.open_dataset("sample_data.nc")
output_grid = xc.create_gaussian_grid(32)
ds_regrid = ds.regridder.horizontal("sst", output_grid, tool="regrid2")

Relevant log output

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[20], line 2
      1 output_grid = xc.create_gaussian_grid(32)
----> 2 ds_regrid = ds.regridder.horizontal("sst", output_grid, tool="regrid2")

File ~/.conda/envs/pmp_devel_20250908/lib/python3.13/site-packages/xcdat/regridder/accessor.py:171, in RegridderAccessor.horizontal(self, data_var, output_grid, tool, **options)
    169 input_grid = _get_input_grid(self._ds, data_var, ["X", "Y"])
    170 regridder = regrid_tool(input_grid, output_grid, **options)
--> 171 output_ds = regridder.horizontal(data_var, self._ds)
    173 return output_ds

File ~/.conda/envs/pmp_devel_20250908/lib/python3.13/site-packages/xcdat/regridder/regrid2.py:114, in Regrid2Regridder.horizontal(self, data_var, ds)
    111 lon_mapping, lon_weights = _map_longitude(src_lon_bnds, dst_lon_bnds)
    113 # horizontal regrid
--> 114 output_data = _regrid(
    115     input_data_var,
    116     lat_mapping,
    117     lon_mapping,
    118     lat_weights,
    119     lon_weights,
    120     src_mask,
    121     unmapped_to_nan=self._unmapped_to_nan,
    122 )
    124 output_ds = _build_dataset(
    125     ds,
    126     data_var,
   (...)    129     self._output_grid,
    130 )
    132 if self._output_weights:

File ~/.conda/envs/pmp_devel_20250908/lib/python3.13/site-packages/xcdat/regridder/regrid2.py:191, in _regrid(input_data_var, lat_mapping, lon_mapping, lat_weights, lon_weights, src_mask, omitted, unmapped_to_nan)
    189 for y in range(y_length):
    190     y_seg = np.take(input_data, lat_mapping[y], axis=y_index)
--> 191     y_mask_seg = np.take(src_mask, lat_mapping[y], axis=0)
    193     for x in range(x_length):
    194         x_seg = np.take(y_seg, lon_mapping[x], axis=x_index, mode="wrap")

File ~/.conda/envs/pmp_devel_20250908/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:203, in take(a, indices, axis, out, mode)
    109 @array_function_dispatch(_take_dispatcher)
    110 def take(a, indices, axis=None, out=None, mode='raise'):
    111     """
    112     Take elements from an array along an axis.
    113 
   (...)    201            [5, 7]])
    202     """
--> 203     return _wrapfunc(a, 'take', indices, axis=axis, out=out, mode=mode)

File ~/.conda/envs/pmp_devel_20250908/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:57, in _wrapfunc(obj, method, *args, **kwds)
     54     return _wrapit(obj, method, *args, **kwds)
     56 try:
---> 57     return bound(*args, **kwds)
     58 except TypeError:
     59     # A TypeError occurs if the object does have such a method in its
     60     # class, but its signature is not identical to that of NumPy's. This
   (...)     64     # Call _wrapit from within the except clause to ensure a potential
     65     # exception has a traceback chain.
     66     return _wrapit(obj, method, *args, **kwds)

IndexError: index 1 is out of bounds for axis 0 with size 1

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.13.11 | packaged by conda-forge | (main, Jan 26 2026, 23:57:06) [GCC 14.3.0]
python-bits: 64
OS: Linux
OS-release: 6.4.0-150600.23.73_15.0.14-cray_shasta_c
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.6
libnetcdf: 4.9.3

xarray: 2026.1.0
pandas: 3.0.0
numpy: 2.3.5
scipy: 1.17.0
netCDF4: 1.7.4
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.5
nc_time_axis: 1.4.1
iris: None
bottleneck: 1.6.0
dask: 2026.1.1
distributed: 2026.1.1
matplotlib: 3.10.8
cartopy: 0.25.0
seaborn: 0.13.2
numbagg: None
fsspec: 2026.1.0
cupy: None
pint: 0.25.2
sparse: 0.17.0
flox: None
numpy_groupies: None
setuptools: 80.10.2
pip: 25.3
conda: None
pytest: None
mypy: None
IPython: 9.9.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugInconsistencies or issues which will cause an issue or problem for users or implementors.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions