xarray.Dataset.where

Dataset.where(cond)

Return an object of the same shape with all entries where cond is True and all other entries masked.

This operation follows the normal broadcasting and alignment rules that xarray uses for binary arithmetic.

Parameters:cond : boolean DataArray or Dataset
Returns:same type as caller

Examples

>>> import numpy as np
>>> a = xr.DataArray(np.arange(25).reshape(5, 5), dims=('x', 'y'))
>>> a.where((a > 6) & (a < 18))
<xarray.DataArray (x: 5, y: 5)>
array([[ nan,  nan,  nan,  nan,  nan],
       [ nan,  nan,   7.,   8.,   9.],
       [ 10.,  11.,  12.,  13.,  14.],
       [ 15.,  16.,  17.,  nan,  nan],
       [ nan,  nan,  nan,  nan,  nan]])
Coordinates:
  * y        (y) int64 0 1 2 3 4
  * x        (x) int64 0 1 2 3 4