You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have several datasets of ocean data from different climate models that I'm trying to interpolate to a common vertical grid using xarray.interp_like. The depth of the surface cell isn't the same on each model, so I'm trying to interpolate in a way that mirrors the behavior of numpy.interp, i.e. filling in with the first and last array values, fp[0] and fp[-1], outside the range of the input data. But since interp_like uses the SciPy interpolator it instead fills with np.nan. The scipy documentation has an example of how to implement the same behavior in scipy, but that syntax really only works if you do it directly in scipy rather than passing it through xarray.
I've tried a few different things for the fill_value kwarg in interp_like but couldn't come up with anything that gives me the desired behavior. The documentation for interp_like mentions numpy is used in some cases, but it's not clear to me if there is a way to choose whether numpy or scipy is used.
So my question is, is there some way to tell xarray interp_like to use the constant extrapolation for values outside the range? This seems like it should be a fairly common use case, but I couldn't find anything suggesting this is currently possible
If I instead use kwargs={'fill_value': 'extrapolate'}, the values are much different from the constant fill value, since it uses linear rather than constant extrapolation:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have several datasets of ocean data from different climate models that I'm trying to interpolate to a common vertical grid using
xarray.interp_like. The depth of the surface cell isn't the same on each model, so I'm trying to interpolate in a way that mirrors the behavior of numpy.interp, i.e. filling in with the first and last array values,fp[0]andfp[-1], outside the range of the input data. But sinceinterp_likeuses the SciPy interpolator it instead fills withnp.nan. The scipy documentation has an example of how to implement the same behavior in scipy, but that syntax really only works if you do it directly in scipy rather than passing it through xarray.I've tried a few different things for the
fill_valuekwarg ininterp_likebut couldn't come up with anything that gives me the desired behavior. The documentation for interp_like mentions numpy is used in some cases, but it's not clear to me if there is a way to choose whether numpy or scipy is used.So my question is, is there some way to tell xarray
interp_liketo use the constant extrapolation for values outside the range? This seems like it should be a fairly common use case, but I couldn't find anything suggesting this is currently possibleExample input:
Output:
Desired behavior:
I'd like to interpolate the same way as numpy would, e.g. for the
tmpvariable:Extrapolation in interp_like:
If I instead use
kwargs={'fill_value': 'extrapolate'}, the values are much different from the constant fill value, since it uses linear rather than constant extrapolation:Beta Was this translation helpful? Give feedback.
All reactions