where

function of dascore.proc.basic source

where(
    patch: Patch ,
    cond: ndarray | Patch ,
    other: Any | Patch = nan,
)-> ‘PatchType’

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.

Examples

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)