MCPcopy
hub / github.com/pydata/xarray / rolling_window

Method rolling_window

xarray/core/variable.py:2117–2244  ·  view source on GitHub ↗

Make a rolling_window along dim and add a new_dim to the last place. Parameters ---------- dim : str Dimension over which to compute rolling_window. For nd-rolling, should be list of dimensions. window : int Window size of

(
        self,
        dim,
        window,
        window_dim,
        *,
        center=False,
        fill_value=dtypes.NA,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

2115
2116 @_deprecate_positional_args("v2024.11.0")
2117 def rolling_window(
2118 self,
2119 dim,
2120 window,
2121 window_dim,
2122 *,
2123 center=False,
2124 fill_value=dtypes.NA,
2125 **kwargs,
2126 ):
2127 """
2128 Make a rolling_window along dim and add a new_dim to the last place.
2129
2130 Parameters
2131 ----------
2132 dim : str
2133 Dimension over which to compute rolling_window.
2134 For nd-rolling, should be list of dimensions.
2135 window : int
2136 Window size of the rolling
2137 For nd-rolling, should be list of integers.
2138 window_dim : str
2139 New name of the window dimension.
2140 For nd-rolling, should be list of strings.
2141 center : bool, default: False
2142 If True, pad fill_value for both ends. Otherwise, pad in the head
2143 of the axis.
2144 fill_value
2145 value to be filled.
2146 **kwargs
2147 Keyword arguments that should be passed to the underlying array type's
2148 ``sliding_window_view`` function.
2149
2150 Returns
2151 -------
2152 Variable that is a view of the original array with an added dimension of
2153 size w.
2154 The return dim: self.dims + (window_dim, )
2155 The return shape: self.shape + (window, )
2156
2157 See Also
2158 --------
2159 numpy.lib.stride_tricks.sliding_window_view
2160 dask.array.lib.stride_tricks.sliding_window_view
2161
2162 Examples
2163 --------
2164 >>> v = Variable(("a", "b"), np.arange(8).reshape((2, 4)))
2165 >>> v.rolling_window("b", 3, "window_dim")
2166 <xarray.Variable (a: 2, b: 4, window_dim: 3)> Size: 192B
2167 array([[[nan, nan, 0.],
2168 [nan, 0., 1.],
2169 [ 0., 1., 2.],
2170 [ 1., 2., 3.]],
2171 <BLANKLINE>
2172 [[nan, nan, 4.],
2173 [nan, 4., 5.],
2174 [ 4., 5., 6.],

Callers 6

test_dask_rollingMethod · 0.95
_constructMethod · 0.80
test_rolling_windowMethod · 0.80
test_rolling_1dMethod · 0.80
test_nd_rollingMethod · 0.80

Calls 4

VariableClass · 0.70
astypeMethod · 0.45
padMethod · 0.45
get_axis_numMethod · 0.45

Tested by 5

test_dask_rollingMethod · 0.76
test_rolling_windowMethod · 0.64
test_rolling_1dMethod · 0.64
test_nd_rollingMethod · 0.64