I’m not sure if this is a stupid question, but I wanted to clip a .nc file by its time variable. I opened the dataset in xarray, but the following ds.sel line (which has worked before) only returns an error.
ds = xr.open_dataset('/Users/mia/Desktop/RMP/data/tracking/mcs_tracks_2015_11.nc')
selected_days = ds.sel(time=slice('2015-11-22', '2015-11-23'))
KeyError: "'time' is not a valid dimension or coordinate for Dataset with dimensions FrozenMappingWarningOnValuesAccess({'index': 6181})"
I have checked to make sure that the file does contain a time variable in datetime format. Below is that testing:
print(ds['time'])
<xarray.DataArray 'time' (index: 6181)> Size: 49kB
[6181 values with dtype=datetime64[ns]]
Coordinates:
* index (index) int64 49kB 12 17 22 23 27 ... 12300 12317 12320 12333 12338
Is there another way to do this or how would I approach this problem? Thank you in advance!!
New contributor
Jocelyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.