You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently recoded the remove_bottom_values function using numba:
fromnumbaimportfloat64, guvectorizeimportnumpyasnpimportxarrayasxr@guvectorize( [ (float64[:], float64[:]), ],"(n)->(n)",nopython=True,)def_remove_last_value(data, output):
# initialize outputoutput[:] =data[:]
foriinrange(len(data)-1):
ifnp.isnan(output[i+1]):
output[i] =np.nan# take care of boundariesifnotnp.isnan(output[-1]):
output[-1] =np.nandefremove_bottom_values_numba(da, dim='lev'):
out=xr.apply_ufunc(
_remove_last_value,
da,
input_core_dims=[[dim]],
output_core_dims=[[dim]],
dask="parallelized",
output_dtypes=[da.dtype],
)
returnoutdefremove_bottom_values_recoded(ds, dim="lev", fill_val=-1e10):
"""Remove the deepest values that are not nan along the dimension `dim`"""# for now assume that values of `dim` increase along the dimensionifds[dim][0] >ds[dim][-1]:
raiseValueError(
f"It seems like `{dim}` has decreasing values. This is not supported yet. Please sort before."
)
else:
ds_masked=xr.Dataset({va:remove_bottom_values_numba(ds[va]) forvainds.data_vars})
ds_masked=ds_masked.transpose(*tuple([difordiinds.dimsifdiinds_masked]))
ds_masked=ds_masked.assign_coords({co:ds[co].transpose(*[difordiinds.dimsifdiinds[co]]) forcoinds.coords})
ds_masked.attrs=ds.attrsreturnds_masked
I am planning on implementing this here at some point. It might also be nice to generalize this to optionally keep only the bottom, and maybe not just leave one value, but an arbitrary amount.
The text was updated successfully, but these errors were encountered:
Recently recoded the
remove_bottom_values
function using numba:I am planning on implementing this here at some point. It might also be nice to generalize this to optionally keep only the bottom, and maybe not just leave one value, but an arbitrary amount.
The text was updated successfully, but these errors were encountered: