import dascore as dc
class ScaleExample(dc.PatchProcessor):
'''Multiply the data by a factor.'''
name = None # so this example claims no name of its own
factor: float = 2.0
def kernel(self, data):
return data * self.factor
patch = dc.get_example_patch()
out = ScaleExample(3)(patch)
assert ScaleExample(3).operation_id == ScaleExample(3.0).operation_idprocessor
Patch operations written as classes.
A PatchProcessor subclass is a whole operation: its fields are the parameters, get_metadata works out the result’s metadata and the numbers the kernel needs without touching data, and kernel computes the array. Subclassing registers the operation, so the class is written once and the patch method is a two-line body which builds it and runs it.
One of DASCore’s own operations which writes no kernel changes metadata alone, so its method is written in PatchMeta and runs on a patch’s metadata as readily as on the patch; one with a kernel is written in Patch. A class defined outside DASCore is a method of neither – the data-less contract is one DASCore holds itself to, and nothing outside it can write into Patch – so it declares its own staticmethod, which is what the registry holds.
Examples
Functions
| Name | Description |
|---|---|
| check_patch_listings | Check the classes made before there was anything to check against. |
| register_kernel | Say that a function is how an operation runs on given array backends. |
Classes
| Name | Description |
|---|---|
| PatchProcessor | An operation on a patch, written as a class. |