0

I'm currently using the Python module rioxarray to clip an Xarray dataset based on a specific geometry to produce a latitude/longitude grid of coordinates. My data is below:

obs_dataset_full

xarray.Dataset

Dimensions:
Lat: 451 Lon: 350 lat: 450 lon: 350

Coordinates:
Lon
(Lon)
int64
0 1 2 3 4 5 ... 345 346 347 348 349
Lat
(Lat)
int64
0 1 2 3 4 5 ... 446 447 448 449 450
Longitude
(lon)
float64
-105.7 -105.7 ... -78.34 -78.26
Latitude
(lat)
float64
35.04 35.08 35.11 ... 51.52 51.56
spatial_ref
()
int64
0
Data variables:
precip_var
(lon, lat, Lon, Lat)
float64
0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 nan

Attributes:
grid_mapping :
spatial_ref

Note: The Lon/Lat dimensions are irrelevant; I'm trying to utilize the lon/lat, which have the actual coordinates.

obs_dataset_full.rio.write_crs('EPSG:4326',inplace = True)
obs_dataset_cropped = obs_dataset_full.rio.clip(geometries=cropping_geometries, crs='EPSG:4326')

When I run this code, I get the following error:

DimensionMissingCoordinateError: lon missing coordinates.

Both the obs_dataset_full dataset and the precip_var data array have the appropriate coordinates assigned to them, the lat/lon grid is filled with evenly spaced values, and the dimensions exist. Unfortunately, the rioxarray documentation page is not particularly clear as to what this exception entails.

1 Answer 1

1

rioxarray expects the names of the coordinates and dimensions to be the same.

This should resolve your problem:

obs_dataset_full = obs_dataset_full.rename(Longitude='lon', Latitude='lat')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.