function of dascore.proc.basic source

    patch: Patch ,
    other ,
    operator ,
)-> ‘PatchType’

Apply a ufunc-type operator to a patch.

This is used to implement a patch’s operator overload.


Parameter Description
patch The patch instance.
other The other object to apply the operator element-wise. Must be either a
non-patch which is broadcastable to the shape of the patch’s data, or
a patch which has compatible coordinates. If units are provided they
must be compatible.
operator The operator. Must be numpy ufunc-like.


import numpy as np
import dascore as dc
from dascore.proc.basic import apply_operator
patch = dc.get_example_patch()
# multiply the patch by 10
new = apply_operator(patch, 10, np.multiply)
assert np.allclose( * 10,
# add a random value to each element of patch data
noise = np.random.random(patch.shape)
new = apply_operator(patch, noise, np.add)
assert np.allclose(, + noise)
# subtract one patch from another. Coords and attrs must be compatible
new = apply_operator(patch, patch, np.subtract)
assert np.allclose(, 0)