A have a netCDF file that I opened with xarray. I want to clip the xarray data set using a shapefile; however, I cannot figure out how to properly set my spatial dimensions.
I have the following data set:
print(ds.keys())
Dimensions: (sample: 86401, ddm: 4, delay: 17,
doppler: 11)
Coordinates:
* sample (sample) int32 0 1 2 ... 86398 86399 86400
* ddm (ddm) int8 0 1 2 3
ddm_timestamp_utc (sample) datetime64[ns] ...
sp_lat (sample, ddm) float32 ...
sp_lon (sample, ddm) float32 ...
Dimensions without coordinates: delay, doppler
Data variables: (12/126)
spacecraft_id int16 ...
spacecraft_num int8 ...
ddm_source int8 ...
ddm_time_type_selector int8 ...
delay_resolution float32 ...
And from:
print(ds.dims)
Frozen({'sample': 86401, 'ddm': 4, 'delay': 17, 'doppler': 11})
I have tried expanding the dimensions to include sp_lat and sp_lon with
ds.expand_dims(['x', 'y']
ds.rename_vars({'sp_lon': 'x', 'sp_lat': 'x'})
I have also tried
ds.rename({'sp_lon': 'x', 'sp_lat': 'y'})
ds.rio.set_spatial_dims('x', 'y', inplace=True)
And I even tried multi-indexing. How can I use my coordinates as my spatial dimensions so that I can clip my dataset with
ds.rio.clip(...)
I am using xarray and rioxarray with python 3.9.