Closed
Description
Hello xarray team
I was trying to implement functionality similar to Scikit Image's view_as_windows, but I was having a hard time with the boundary conditions. I understand this request is very similar to rolling with periodic boundary conditions #2007.
MCVE Code Sample
>>> arr = xr.DataArray(np.arange(4), dims=("x",))
>>> arr.rolling(x=2).construct("roll_x", stride=2)
<xarray.DataArray (x: 2, roll_x: 2)>
array([[nan, 0.],
[ 1., 2.]])
Dimensions without coordinates: x, roll_x
Expected Output
It would be nice to be able to easily get an output of:
<xarray.DataArray (x: 2, roll_x: 2)>
array([[0., 1.],
[2., 3.]])
Dimensions without coordinates: x, roll_x
Possible workarounds
With the upcoming features of pad (#3596) and rolling: periodic (#2011) it is actually not that hard to work around with:
arr.pad(x=(1,0)).rolling(x=2).construct("roll_x", stride=2).isel(x=slice(1,None))
# or
arr.roll(x=-1).rolling(x=2, boundary="periodic").construct("roll_x", stride=2)
Idea
Would it be possible to add a keyword argument to either rolling()
or construct()
that expects an alignment of "left", "right" or "center". I understand that this could break interface copied from Pandas, but I hope it could be useful to others as well.
Metadata
Metadata
Assignees
Labels
No labels