import dascore as dc
import numpy as np
patch = dc.get_example_patch()
# Where data > 0 fill with original patch values else nan.
condition = patch.data > 0
out = patch.where(condition)
# Use another patch as condition
threshold = patch.data.mean()
boolean_patch = patch.new(data=(patch.data > threshold))
out = patch.where(boolean_patch, other=0)
# Replace values below threshold with 0
out = patch.where(patch.data > patch.data.mean(), other=0)Where
Where(
*args ,
cond: Any ,
other: Any = nan,
)-> None
Return elements from patch where condition is True, else fill with other.
Parameters
| Parameter | Description |
|---|---|
| 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.
Examples
Methods
| Name | Description |
|---|---|
| check | Refuse a patch which does not carry what the operation needs. |
| get_metadata | Return the metadata aligned with any patch given, and how each aligns. |
| kernel |
As numpy_kernel, on the data’s own backend.
|
| model_copy | Copy the model, dropping cached values the update invalidates. |
| new | Create new instance with some attributed updated. |
| numpy_kernel | Return the data where the condition holds, else the other values. |
| where | Return elements from patch where condition is True, else fill with other. |
| reconcile | Return metadata or a patch holding the final data; default as is. |
| run | Run the operation: check, get_metadata, kernel, reconcile, record. |