You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to interpolate a DataArray by two coordinates. However, each input coord is two dimension.
So, I stack the input coords first to make them become one dimension and then unstack it back.
Error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [2], in <module> 10 y = xr.DataArray([[0.15, 0.25], [0.3, 0.35]], dims=['x', 'y']).stack(z=['x','y']) 13 # da.sel(x=x, y=y, method='nearest') ---> 14 da.interp(x=x, y=y, method='nearest').unstack('z') File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataarray.py:2196, in DataArray.unstack(self, dim, fill_value, sparse) 2136 def unstack( 2137 self, 2138 dim: Union[Hashable, Sequence[Hashable], None] = None, 2139 fill_value: Any = dtypes.NA, 2140 sparse: bool = False, 2141 ) -> "DataArray": 2142 """ 2143 Unstack existing dimensions corresponding to MultiIndexes into 2144 multiple new dimensions. (...) 2194 DataArray.stack 2195 """ -> 2196 ds = self._to_temp_dataset().unstack(dim, fill_value, sparse) 2197 return self._from_temp_dataset(ds) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py:4211, in Dataset.unstack(self, dim, fill_value, sparse) 4209 result = result._unstack_full_reindex(dim, fill_value, sparse) 4210 else: -> 4211 result = result._unstack_once(dim, fill_value, sparse) 4212 return result File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py:4065, in Dataset._unstack_once(self, dim, fill_value, sparse) 4062 else: 4063 fill_value_ = fill_value -> 4065 variables[name] = var._unstack_once( 4066 index=index, dim=dim, fill_value=fill_value_, sparse=sparse 4067 ) 4068 else: 4069 variables[name] = var File ~/miniconda3/lib/python3.9/site-packages/xarray/core/variable.py:1695, in Variable._unstack_once(self, index, dim, fill_value, sparse) 1690 # Indexer is a list of lists of locations. Each list is the locations 1691 # on the new dimension. This is robust to the data being sparse; in that 1692 # case the destinations will be NaN / zero. 1693 data[(..., *indexer)] = reordered -> 1695 return self._replace(dims=new_dims, data=data) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/variable.py:985, in Variable._replace(self, dims, data, attrs, encoding) 983 if encoding is _default: 984 encoding = copy.copy(self._encoding) --> 985 return type(self)(dims, data, attrs, encoding, fastpath=True) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/variable.py:2630, in IndexVariable.__init__(self, dims, data, attrs, encoding, fastpath) 2628 super().__init__(dims, data, attrs, encoding, fastpath) 2629 if self.ndim != 1: -> 2630 raise ValueError(f"{type(self).__name__} objects must be 1-dimensional") 2632 # Unlike in Variable, always eagerly load values into memory 2633 if not isinstance(self._data, PandasIndexingAdapter): ValueError: IndexVariable objects must be 1-dimensionalBeta Was this translation helpful? Give feedback.
All reactions