import dascore as dc
import numpy as np
= dc.get_example_patch()
patch
# Where data > 0 fill with original patch values else nan.
= patch.data > 0
condition = patch.where(condition)
out
# Use another patch as condition
= patch.data.mean()
threshold = patch.new(data=(patch.data > threshold))
boolean_patch = patch.where(boolean_patch, other=0)
out
# Replace values below threshold with 0
= patch.where(patch.data > patch.data.mean(), other=0) out
where
Return elements from patch where condition is True, else fill with other.
Parameters
Parameter | Description |
---|---|
patch | The input patch |
cond |
Condition array. Should be a boolean array with the same shape as patch data, or a patch with boolean data that is broadcastable to the patch’s shape. |
other |
Value to use for locations where cond is False. Can be a scalar value, array, or patch that is broadcastable to the patch’s shape. Default is NaN. |
Returns
PatchType A new patch with values from patch where cond is True, and other elsewhere.