Open nkarasiak opened 1 month ago
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!
@nkarasiak This one threw me for a loop too. But I believe the issue you're experiencing is due to the presence/absence of nan
values. When using the quadratic or cubic interpolations, if there are any nans
in your dataset, then the returned result is all nans
. I don't know if this is expected behaviour or not. A workaround could be to fill the nans
first (e.g. ds.fillna()
or ds.interpolate_na()
) then conduct your resample+interpolation, or drop coordinates with nans (e.g. ds.dropna(how='all')
)
#load a dataset and subsample - this dataset has nans
ds = xr.tutorial.load_dataset("ersstv5")['sst'].isel(time=slice(0,10),lat=slice(20,40),lon=slice(20,40))
#take the spatial average so we have a 1D datset with no nans
no_nans = ds.mean(['lat','lon'])
#make the last two time-steps nans
with_nans = _1D_no_nans.where(no_nans.time<=pd.to_datetime('1970-08'))
#resample and interpolate
no_nans_upsampled = no_nans.resample(time='D').interpolate('quadratic')
with_nans_upsampled = with_nans.resample(time='D').interpolate('quadratic')
#plot
no_nans.plot(label='original')
no_nans_upsampled.plot(label='upsampled')
with_nans_upsampled.plot(label='upsampled with nans')
plt.legend();
What happened?
When using a multiple dimensions xarray (like time, x and y), the quadratic function is not working anymore with interpolate, it returns only nan. slinear is ok. quadratic is only ok when using only a dimension (like only a lat/lon value).
What did you expect to happen?
No response
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment