Created
January 24, 2022 22:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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