Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emileten/397797217db4c19909d2a9ccfb605fdc to your computer and use it in GitHub Desktop.
Save emileten/397797217db4c19909d2a9ccfb605fdc to your computer and use it in GitHub Desktop.
Replace xarray values conditionally by a set of values samples from the uniform distribution
def censor(x):
if x < 1:
return np.random.uniform(low=0.5, high=1)
else:
return x
vcensor = np.vectorize(censor)
ds_corrected = xr.apply_ufunc(vcensor, ds, dask='parallelized') # rather, should we load the data before hand ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment