import dascore as dc
from dascore.proc.window import Windowed
patch = dc.get_example_patch()
# A trend taken out of every second of the patch, not out of all of it.
out = patch.window(time=1).detrend("time")
same = Windowed(dc.proc.Detrend(dim="time"), time=1)(patch)
assert out.equals(same)Windowed
Windowed(
*args ,
operation: Any ,
overlap: Any = None,
step: Any = None,
taper: Any = None,
analysis: Any = None,
fill: Any = None,
samples: bool = False,
**kwargs ,
)-> None
Run an operation in each window of a patch, and blend the windows.
The operation behind a patch method called on Patch.window, where the window’s parameters are described; the dimensions to window are given as keywords, such as time=0.5.
Parameters
| Parameter | Description |
|---|---|
| operation |
The operation each window is given, as aPatchProcessor.
|
Examples
Note
- One plan is worked out, from the metadata of the first window, and run in every window: the kernel never changes from window to window. Only an operation which acts relative to its window can be run that way, and its class says that it is one by setting
position_free; DASCore’s detrend, taper, filters, normalizations and the like do. Any other is refused. - Everything is decided before any data are read. The operation must also give back a window with the same dimensions and coordinates, or every n-th sample of them along a windowed dimension, take no other patch or array shaped like the patch, and not settle its result from the data it computed; the window must fit inside its dimension.
- An operation may keep every n-th sample of a windowed dimension, as
decimateandfbewith astepdo, if the windows advance by a multiple of n samples, so that every window lands on one grid. The result is then n times shorter. No other change of shape is blended. - An operation which leaves samples at the ends of its result empty says by its
halohow far it reads around a sample:fbeandstaltaleave NaN until a whole rolling window is behind a sample. Those are discarded from every window and what is left is blended, so the windows must overlap by at least as much. The patch’s own first samples have nothing before them, and are left NaN as the operation alone leaves them. - NumPy’s floating-point warnings are not raised for a window which reaches beyond the patch, where a logarithm or a quotient of the fill is not about the data; nor, then, for the data that window holds. Windows inside the patch warn as the operation does.
- On an array backend other than NumPy the data stay where they are. A dask array is computed a piece at a time, each from the windows which overlap it, so nothing is computed when the operation is called; a piece is blended on the library its chunks are held in, and the pieces one at a time in a process, since not every kernel may be run from two threads at once. On any other library the windows are cut, run and blended there, which takes several array operations for each window. Only an operation with no implementation for the library is converted through NumPy, as it is outside a window, and always with a
NumpyFallbackWarningnaming it. - An operation which only changes metadata leaves the data as they are.
- On a lazy patch an output chunk needs only the windows which overlap it, so a windowed dimension can be cut even where the operation itself needs its dimension whole. For a lazy or dask patch the dtype is found by running the operation on a window of zeros.
Methods
| Name | Description |
|---|---|
| check | Refuse a patch which does not carry what the operation needs. |
| chunk_contract | Return the tiles a chunk needs, and what the operation reads besides. |
| get_metadata | Return the blended metadata, the tiling, and one window’s plan. |
| halo | Return how far along an axis the kernel reads to fill a sample. |
| kernel | Return the windows the operation made, blended, on the data’s backend. |
| model_copy | Copy the model, dropping cached values the update invalidates. |
| new | Create new instance with some attributed updated. |
| numpy_kernel | Return the windows the operation made, blended. |
| reconcile | Return metadata or a patch holding the final data; default as is. |
| run | Run the operation: check, get_metadata, kernel, reconcile, record. |