Skip to content

Usage question for interpolate_na #4639

Answered by keewis
alessioarena asked this question in Q&A
Discussion options

You must be logged in to vote

consider this:

In [2]: da = xr.DataArray(
   ...:     [0, np.nan, 1, np.nan, np.nan, 2, np.nan, np.nan, np.nan, 3],
   ...:     dims="x",
   ...:     coords={"x": np.arange(-10, 10, 2)},
   ...: )
   ...: da
Out[2]: 
<xarray.DataArray (x: 10)>
array([ 0., nan,  1., nan, nan,  2., nan, nan, nan,  3.])
Coordinates:
  * x        (x) int64 -10 -8 -6 -4 -2 0 2 4 6 8

In [3]: da.interpolate_na(dim="x", method="nearest", limit=2)
Out[3]: 
<xarray.DataArray (x: 10)>
array([ 0.,  0.,  1.,  1.,  2.,  2.,  2.,  2., nan,  3.])
Coordinates:
  * x        (x) int64 -10 -8 -6 -4 -2 0 2 4 6 8

In [4]: da.interpolate_na(dim="x", method="nearest", max_gap=7)
Out[4]: 
<xarray.DataArray (x: 10)>
array([ 0.,  0.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dcherian
Comment options

Answer selected by keewis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants