community!
While working with outputs of climate simulation models I've faced some strange xarray behavior - slicing by latitude returns an empty array.
xr.open_mfdataset(nc_list[1])
Output
<xarray.Dataset>
Dimensions: (bnds: 2, time: 1128, lev: 13, lat: 360, lon: 720)
Coordinates:
* bnds (bnds) float64 0.0 1.0
* time (time) float64 4.14e+03 4.141e+03 ... 5.266e+03 5.267e+03
* lev (lev) float64 1.0 2.0 3.0 4.0 5.0 ... 9.0 10.0 11.0 12.0 13.0
* lat (lat) float64 89.75 89.25 88.75 ... -88.75 -89.25 -89.75
* lon (lon) float64 -179.8 -179.2 -178.8 ... 178.8 179.2 179.8
Data variables:
depth (time, lev, lat, lon) float64 ...
depth_bnds (bnds, time, lev, lat, lon) float64 ...
soilmoistfroz (time, lev, lat, lon) float32 ...
Attributes: (12/15)
Slicing by longtitude works fine:
xr.open_mfdataset(nc_list[1]).sel(lon=slice(0, 100))
Output
<xarray.Dataset>
Dimensions: (bnds: 2, time: 1128, lev: 13, lat: 360, lon: 200)
Coordinates:
* bnds (bnds) float64 0.0 1.0
* time (time) float64 4.14e+03 4.141e+03 ... 5.266e+03 5.267e+03
* lev (lev) float64 1.0 2.0 3.0 4.0 5.0 ... 9.0 10.0 11.0 12.0 13.0
* lat (lat) float64 89.75 89.25 88.75 ... -88.75 -89.25 -89.75
* lon (lon) float64 0.25 0.75 1.25 1.75 ... 98.25 98.75 99.25 99.75
Data variables:
depth (time, lev, lat, lon) float64 ...
depth_bnds (bnds, time, lev, lat, lon) float64 ...
soilmoistfroz (time, lev, lat, lon) float32 ...
Attributes: (12/15)
However, filtering by latitude returns an empty list:
xr.open_mfdataset(nc_list[1]).sel(lat=slice(0, 100))
Output
<xarray.Dataset>
Dimensions: (bnds: 2, time: 1128, lev: 13, lat: 0, lon: 720)
Coordinates:
* bnds (bnds) float64 0.0 1.0
* time (time) float64 4.14e+03 4.141e+03 ... 5.266e+03 5.267e+03
* lev (lev) float64 1.0 2.0 3.0 4.0 5.0 ... 9.0 10.0 11.0 12.0 13.0
* lat (lat) float64
* lon (lon) float64 -179.8 -179.2 -178.8 ... 178.8 179.2 179.8
Data variables:
depth (time, lev, lat, lon) float64 ...
depth_bnds (bnds, time, lev, lat, lon) float64 ...
soilmoistfroz (time, lev, lat, lon) float32 ...
Attributes: (12/15)
Can you tell me what I’m doing wrong?
SOLVED
The order of the coordinate values matters, thus slicing by latitude should be performed with
xr.open_dataset(path, decode_times=False).sel(lat=slice(100, 0))