Rolling window object for DataArrays. Parameters ---------- dim : dict, optional Mapping from the dimension name to create the rolling iterator along (e.g. `time`) to its moving window size. min_periods : int or None, default: None
(
self,
dim: Mapping[Any, int] | None = None,
min_periods: int | None = None,
center: bool | Mapping[Any, bool] = False,
**window_kwargs: int,
)
| 7205 | return DataArrayWeighted(self, weights) |
| 7206 | |
| 7207 | def rolling( |
| 7208 | self, |
| 7209 | dim: Mapping[Any, int] | None = None, |
| 7210 | min_periods: int | None = None, |
| 7211 | center: bool | Mapping[Any, bool] = False, |
| 7212 | **window_kwargs: int, |
| 7213 | ) -> DataArrayRolling: |
| 7214 | """ |
| 7215 | Rolling window object for DataArrays. |
| 7216 | |
| 7217 | Parameters |
| 7218 | ---------- |
| 7219 | dim : dict, optional |
| 7220 | Mapping from the dimension name to create the rolling iterator |
| 7221 | along (e.g. `time`) to its moving window size. |
| 7222 | min_periods : int or None, default: None |
| 7223 | Minimum number of observations in window required to have a value |
| 7224 | (otherwise result is NA). The default, None, is equivalent to |
| 7225 | setting min_periods equal to the size of the window. |
| 7226 | center : bool or Mapping to int, default: False |
| 7227 | Set the labels at the center of the window. The default, False, |
| 7228 | sets the labels at the right edge of the window. |
| 7229 | **window_kwargs : optional |
| 7230 | The keyword arguments form of ``dim``. |
| 7231 | One of dim or window_kwargs must be provided. |
| 7232 | |
| 7233 | Returns |
| 7234 | ------- |
| 7235 | computation.rolling.DataArrayRolling |
| 7236 | |
| 7237 | Examples |
| 7238 | -------- |
| 7239 | Create rolling seasonal average of monthly data e.g. DJF, JFM, ..., SON: |
| 7240 | |
| 7241 | >>> da = xr.DataArray( |
| 7242 | ... np.linspace(0, 11, num=12), |
| 7243 | ... coords=[ |
| 7244 | ... pd.date_range( |
| 7245 | ... "1999-12-15", |
| 7246 | ... periods=12, |
| 7247 | ... freq=pd.DateOffset(months=1), |
| 7248 | ... ) |
| 7249 | ... ], |
| 7250 | ... dims="time", |
| 7251 | ... ) |
| 7252 | >>> da |
| 7253 | <xarray.DataArray (time: 12)> Size: 96B |
| 7254 | array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]) |
| 7255 | Coordinates: |
| 7256 | * time (time) datetime64[us] 96B 1999-12-15 2000-01-15 ... 2000-11-15 |
| 7257 | >>> da.rolling(time=3, center=True).mean() |
| 7258 | <xarray.DataArray (time: 12)> Size: 96B |
| 7259 | array([nan, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., nan]) |
| 7260 | Coordinates: |
| 7261 | * time (time) datetime64[us] 96B 1999-12-15 2000-01-15 ... 2000-11-15 |
| 7262 | |
| 7263 | Remove the NaNs using ``dropna()``: |
| 7264 |