I have an xarray DataArray which contains data from multiple days. I am able to mask it using the .where function for one condition, but I'd like to make all values over a certain value 1 and all values under that value 0. Ideally, I;d also like to ensure that any np.nans in the dataset are not changed, but this is not a requirement.
import numpy as np
import xarray as xr
dval = np.random.randint(5,size=[3,4,4])
x = [0,1,2,3]
y = [0,1,2,3]
time = ['2017-10-13','2017-10-12','2017-10-11']
a = xr.DataArray(dval,coords=[time,x,y],dims=['time','x','y'])
a = a.where(a>2,1,0) #ideally this would work as (condition,True val, False val)
This results in a ValueError of "cannot set 'other' if drop=True"
Any help with this would be greatly appreciated.
xr.where
with the same call and get back a instead of a.values – Crowther