Closed DahnJ closed 2 months ago
Bug confirmed - thank you for your report!
Related #372
Even though this doesn't fix the issue, I recommend changing your code like as shown in the crs management example as it will help your spatial dimension persist better and follow the CF conventions for metadata:
import numpy
import xarray
import rioxarray
lat = [0.1, 0.15, 0.2]
lon = [0.1, 0.15, 0.2]
data = numpy.arange(1, 10).reshape(3, 3)
ds = xarray.Dataset(
data_vars={
"foo": (["lat", "lon"], data),
"bar": (["lat", "lon"], data),
},
coords={"lat": lat, "lon": lon},
)
ds = ds.rio.write_crs(
4326, inplace=True
).rio.set_spatial_dims(
x_dim="lon", y_dim="lat", inplace=True
).rio.write_coordinate_system(inplace=True)
ds = ds.rio.reproject_match(ds)
Code Sample, a copy-pastable example if possible
Thanks @bocalml for the MRE.
Problem description
This results in
MissingSpatialDimensionError: x dimension (lon) not found.
This is likely related to the renaming mentioned in https://github.com/corteva/rioxarray/issues/751 but I haven't been able to make sense of this fully and the result is surprising to me.
Full traceback
```python --------------------------------------------------------------------------- MissingSpatialDimensionError Traceback (most recent call last) Cell In[31], line 1 ----> 1 ds = ds.rio.reproject_match(ds) File ~/miniconda3/envs/myenv/lib/python3.12/site-packages/rioxarray/raster_dataset.py:191, in RasterDataset.reproject_match(self, match_data_array, resampling, **reproject_kwargs) 189 raise 190 resampled_dataset[var] = self._obj[var].copy() --> 191 return resampled_dataset.rio.set_spatial_dims( 192 x_dim=self.x_dim, y_dim=self.y_dim, inplace=True 193 ) File ~/miniconda3/envs/myenv/lib/python3.12/site-packages/rioxarray/rioxarray.py:853, in XRasterBase.set_spatial_dims(self, x_dim, y_dim, inplace) 851 data_obj.rio._x_dim = x_dim 852 else: --> 853 raise MissingSpatialDimensionError( 854 f”x dimension ({x_dim}) not found.{_get_data_var_message(data_obj)}” 855 ) 856 if y_dim in data_obj.dims: 857 data_obj.rio._y_dim = y_dim MissingSpatialDimensionError: x dimension (lon) not found. ```Expected Output
The dataset itself with no error.
Environment Information
Installation method
Conda
Conda environment information (if you installed with conda):
Environment (
conda list
):Details about
conda
and system (conda info
):