PatchProcessor
PatchProcessor(
*args ,
)-> None
An operation on a patch, written as a class.
Subclasses declare their parameters as fields and override some of:
get_metadata(meta): the result’s metadata and the argumentskernelneeds, worked out together from metadata alone. Deriving the one usually computes the other.kernel(data, **plan): the array computation. None of it may see a patch, so a chain of kernels can be compiled.numpy_kernel(data, **plan): a numpy, scipy or numba computation. NumPy data prefer it; other backends usekernelif available, otherwise convert through NumPy as thenumpy_fallbacksetting says: with aNumpyFallbackWarningunless it is changed.reconcile(result, out, meta): the one hook which sees both halves, given the input metadata as well. Return metadata to attach the result, or a patch holding the final data.chunk_contract(dtype, plan): what a chunk of the output needs of the input, which is what lets the operation run on a lazy array. None, the default, says it cannot.halo(plan): how many samples of the input a kernel reads before and after a sample to fill it, where it leaves the sample empty for want of them, as a rolling mean leaves its first. No axis by default.
A class whose get_metadata returns the same plan wherever the patch’s coordinates start sets position_free = True, beside the method. Where its arguments decide, it writes a method instead, position_free(self, dims), given the dimensions whose start may move. A class which writes get_metadata runs in the windows of Patch.window, where one plan is worked out and run in every window, only if it says so; one which plans nothing need not. A class which is linear as well, as a recursive filter is, sets linear = True: its response to one impulse then says what it does to any data, and it runs in an Patch.impulse_window. It promises too that the response spreads from the impulse along each axis on its own and decays away from it, as a filter’s does; a probe of finite length cannot see a response which starts far from the impulse, or off the lines through it. The word is for the kernel of the class which says it: a subclass with a kernel of its own says it again.
Each subclass is registered under name (snake case of the class name unless set). One of DASCore’s own is reached through a method of that name, written in the body of Patch or, for an operation with no kernel, PatchMeta:
def scale(self, factor: float = 2.0) -> Self:
'''Multiply the data by a factor.'''
return Scale(factor=factor).run(self)
A real method is one a type checker, an IDE and help can all read, which a synthesized function is not, and -> Self is what run promises: metadata comes back metadata and a subclass comes back a subclass. Every field must appear among its parameters; the method may take more, since a body may resolve something before building the instance. cls.patch_function is that method, and carries the class’s docstring: the parameters, notes and examples are written once, with the class. A class with name = None has no method and is registered nowhere, and a class outside DASCore declares a staticmethod of that name itself, taking the patch positionally.
Methods
| Name | Description |
|---|---|
| check | Refuse a patch which does not carry what the operation needs. |
| chunk_contract | Return what a chunk of the output needs of the input, or None. |
| get_metadata |
Return the result’s metadata and the arguments kernel needs.
|
| halo | Return how far along an axis the kernel reads to fill a sample. |
| model_copy | Copy the model, dropping cached values the update invalidates. |
| kernel_for | Return the kernel this class runs for a backend, or None. |
| new | Create new instance with some attributed updated. |
| reconcile | Return metadata or a patch holding the final data; default as is. |
| run | Run the operation: check, get_metadata, kernel, reconcile, record. |