Closed MorningGlory747 closed 2 months ago
Hi @MorningGlory747 !
I think the issue comes from the time
dimension on the lon
and lat
coordinates. clisops
does not expect seing a temporal dimension on the coordinates and does not support it. But I am guessing this is just an issue of the way the datasets were combined by xarray. Look into your input data to confirm the lat and lon coordinates are supposed to be the same across all datasets you are combining.
You could do:
tmp = tmp.assign_coords(
lat=tmp.lat.isel(time=0, drop=True),
lon=tmp.lat.isel(time=0, drop=True)
)
to get rid of this unwanted time
dimension.
Hi @aulemahal,
That makes a lot of sense to me and your solution did fix the problem. Thank you very much for this! :)
Curious because I'm still new to manipulating xarray datasets, what would happen if I were to drop other dimensions (say the rlon=0 or the rlat=0) dimensions from lon or lat? Would that essentially be like taking a dataset slice on only that rlon=0 row?
Yes. In fact,
tmp = tmp.assign_coords(
lat=tmp.lat.isel(rlon=0, drop=True),
lon=tmp.lat.isel(rlon=0, drop=True)
)
would probably break your dataset because you would now be missing information : the latitude axis is sliced along the rlon
dimension, but the data is not. Xarray would assume that all lat/lon coordinates are the same for each rlon
index, which is not true. Reprojection with cartopy
or xesmf
would either fail or yield strange results.
Description
I'm trying to create a spatial subset of an xarray dataset containing rotated coordinates with multiple timesteps. The dataset is from netcdf CaLDAS ECCC data.
What happened: I'm getting the following error when using
subset.subset_bbox
on the xarray that contains multiple timestepstmp_bbox = subset.subset_bbox(tmp, lon_bnds=[-76,-72], lat_bnds=[45,50])
>> numpy.core._exceptions._UFuncInputCastingError: Cannot cast ufunc 'less' input 0 from dtype('<m8[ns]') to dtype('<m8') with casting rule 'same_kind'
However, when selecting only one timestep of the dataset
tmp_bbox = subset.subset_bbox(tmp.isel(time=0), lon_bnds=[-76,-72], lat_bnds=[45,50])
The subset works just fine.
What I Did
Please let me know if there's anything else I need to add to the post!
Full error code here