PatchProcessor

class of dascore.core.processor
inherits from: DascoreBaseModel, pydantic.main.BaseModel
source

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 arguments kernel needs, 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 use kernel if available, otherwise convert through NumPy with a NumpyFallbackWarning.
  • reconcile(result, out): the one hook which sees both halves. Return metadata to attach the result, or a patch holding the final data.

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.
get_metadata Return the result’s metadata and the arguments kernel needs.
kernel_for Return the kernel this class runs for a backend, or None.
model_copy Copy the model, dropping cached values the update invalidates.
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.