Stream: python-questions

Topic: can't interpolate along Y, y?


view this post on Zulip Anna-Lena Deppenmeier (Jul 18 2022 at 23:25):

Hi there, I am trying to interpolate some MITgcm grid distances to be compatible with the grid of some other variables. I need the distances on YC and XC. I can interpolate ds_2014.dxC just fine with grid.interp(ds_2014.dxC, 'X'), but the same doesn't work for the Y direction and I don't get why:
grid.interp(ds_2014.dyC, 'Y')
gives me:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Input In [143], in <cell line: 1>()
----> 1 grid.interp(ds_2014.dyG, 'Y')

File /glade/work/deppenme/miniconda3/envs/mhw_lens/lib/python3.10/site-packages/xgcm/grid.py:2041, in Grid.interp(self, da, axis, **kwargs)
   1989 def interp(self, da, axis, **kwargs):
   1990     """
   1991     Interpolate neighboring points to the intermediate grid point along
   1992     this axis.
   (...)
   2039     >>> grid.interp(da, ["X", "Y"], periodic={"X": True, "Y": False})
   2040     """
-> 2041     return self._1d_grid_ufunc_dispatch("interp", da, axis, **kwargs)

File /glade/work/deppenme/miniconda3/envs/mhw_lens/lib/python3.10/site-packages/xgcm/grid.py:1836, in Grid._1d_grid_ufunc_dispatch(self, funcname, data, axis, to, keep_coords, metric_weighted, other_component, **kwargs)
   1833 else:
   1834     map_overlap = False
-> 1836 array = grid_ufunc(
   1837     self,
   1838     array,
   1839     axis=[(ax_name,)],
   1840     keep_coords=keep_coords,
   1841     dask=dask,
   1842     map_overlap=map_overlap,
   1843     other_component=other_component,
   1844     **remaining_kwargs,
   1845 )
   1847 if ax_metric_weighted:
   1848     metric = self.get_metric(array, ax_metric_weighted)

File /glade/work/deppenme/miniconda3/envs/mhw_lens/lib/python3.10/site-packages/xgcm/grid_ufunc.py:460, in GridUFunc.__call__(self, grid, axis, *args, **kwargs)
    458 map_overlap = kwargs.pop("map_overlap", self.map_overlap)
    459 pad_before_func = kwargs.pop("pad_before_func", self.pad_before_func)
--> 460 return apply_as_grid_ufunc(
    461     self.ufunc,
    462     *args,
    463     axis=axis,
    464     grid=grid,
    465     signature=self.signature,
    466     boundary_width=self.boundary_width,
    467     boundary=boundary,
    468     dask=dask,
    469     map_overlap=map_overlap,
    470     pad_before_func=pad_before_func,
    471     **kwargs,
    472 )

File /glade/work/deppenme/miniconda3/envs/mhw_lens/lib/python3.10/site-packages/xgcm/grid_ufunc.py:745, in apply_as_grid_ufunc(func, axis, grid, signature, boundary_width, boundary, fill_value, keep_coords, dask, map_overlap, pad_before_func, other_component, *args, **kwargs)
    742 # Maybe map function over chunked core dims using dask.array.map_overlap
    743 if map_overlap:
    744     # Disallow situations where shifting axis position would cause chunk size to change
--> 745     _check_if_length_would_change(sig)
    747     mapped_func = _map_func_over_core_dims(
    748         func,
    749         args,
   (...)
    753         out_dtypes,
    754     )
    755 else:

File /glade/work/deppenme/miniconda3/envs/mhw_lens/lib/python3.10/site-packages/xgcm/grid_ufunc.py:1002, in _check_if_length_would_change(signature)
    996 all_ax_positions = set(
    997     p
    998     for arg_ps in signature.in_ax_positions + signature.out_ax_positions
    999     for p in arg_ps
   1000 )
   1001 if any(pos in DISALLOWED_OVERLAP_POSITIONS for pos in all_ax_positions):
-> 1002     raise NotImplementedError(
   1003         "Cannot chunk along a core dimension for a grid ufunc which has a signature which "
   1004         f"includes one of the axis positions {DISALLOWED_OVERLAP_POSITIONS}"
   1005     )

NotImplementedError: Cannot chunk along a core dimension for a grid ufunc which has a signature which includes one of the axis positions ['inner', 'outer']

The grid looks like this:

<xgcm.Grid>
T Axis (not periodic, boundary=None):
  * center   time
Z Axis (not periodic, boundary=None):
  * center   Z --> left
  * left     Zl --> center
Y Axis (not periodic, boundary=None):
  * center   YC --> outer
  * outer    YG --> center
X Axis (not periodic, boundary=None):
  * center   XC --> left
  * left     XG --> center

@Deepak Cherian I googled for some issues but can't find anything useful, also because ds_2014.dyC isn't actually chunked?! Any ideas? image.png

view this post on Zulip Deepak Cherian (Jul 19 2022 at 17:57):

It is chunked; there's just a single chunk. This is the upstream issue: https://github.com/xgcm/xgcm/issues/518


Last updated: May 16 2025 at 17:14 UTC