MCPcopy Index your code
hub / github.com/pydata/xarray / DataArrayRolling

Class DataArrayRolling

xarray/computation/rolling.py:261–770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259
260
261class DataArrayRolling(Rolling["DataArray"]):
262 __slots__ = ("window_labels",)
263
264 def __init__(
265 self,
266 obj: DataArray,
267 windows: Mapping[Any, int],
268 min_periods: int | None = None,
269 center: bool | Mapping[Any, bool] = False,
270 ) -> None:
271 """
272 Moving window object for DataArray.
273 You should use DataArray.rolling() method to construct this object
274 instead of the class constructor.
275
276 Parameters
277 ----------
278 obj : DataArray
279 Object to window.
280 windows : mapping of hashable to int
281 A mapping from the name of the dimension to create the rolling
282 window along (e.g. `time`) to the size of the moving window.
283 min_periods : int, default: None
284 Minimum number of observations in window required to have a value
285 (otherwise result is NA). The default, None, is equivalent to
286 setting min_periods equal to the size of the window.
287 center : bool, default: False
288 Set the labels at the center of the window. The default, False,
289 sets the labels at the right edge of the window.
290
291 Returns
292 -------
293 rolling : type of input argument
294
295 See Also
296 --------
297 xarray.DataArray.rolling
298 xarray.DataArray.groupby
299 xarray.Dataset.rolling
300 xarray.Dataset.groupby
301 """
302 super().__init__(obj, windows, min_periods=min_periods, center=center)
303
304 # TODO legacy attribute
305 self.window_labels = self.obj[self.dim[0]]
306
307 def __iter__(self) -> Iterator[tuple[DataArray, DataArray]]:
308 if self.ndim > 1:
309 raise ValueError("__iter__ is only supported for 1d-rolling")
310
311 dim0 = self.dim[0]
312 window0 = int(self.window[0])
313 offset = (window0 + 1) // 2 if self.center[0] else 1
314 stops = np.arange(offset, self.obj.sizes[dim0] + offset)
315 starts = stops - window0
316 starts[: window0 - offset] = 0
317
318 for label, start, stop in zip(self.window_labels, starts, stops, strict=True):

Callers 3

rollingMethod · 0.90
cumulativeMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…