-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error using reduce(): percentile() got an unexpected keyword argument 'axis' #3701
Comments
the reason for this is that the In [13]: # Get the percentiles at each lat/lon:
...: ds = ds.compute()
...: percentiles = ds.reduce(np.percentile, q=percentile, dim='time')
...: quantiles = ds.quantile(q=percentile / 100, dim="time")
...: xr.testing.assert_identical(percentiles.drop_vars("height"), quantiles.drop_vars("quantile")) the only difference is that the unused coordinate |
Thanks for that but ideally I wouldn't use |
you should be able to just use |
Seems like I do need it: percentiles = ds.quantile(q=percentile / 100, dim="time") returns
|
sorry, my mistake. I've been testing on master which has #3559 merged and thus works with dask arrays. Unless someone has a better idea, I'd suggest copying that approach for now: using percentiles = quantile(ds, q=percentile / 100, dim="time")
ds.quantile(...) |
This def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):
from xarray.core.computation import apply_ufunc
from xarray.core import utils
scalar = utils.is_scalar(q)
q = np.atleast_1d(np.asarray(q, dtype=np.float64))
if dim is None:
dim = self.dims
if utils.is_scalar(dim):
dim = [dim]
def _wrapper(npa, **kwargs):
# move quantile axis to end. required for apply_ufunc
return np.moveaxis(np.nanpercentile(npa, **kwargs), 0, -1)
axis = np.arange(-1, -1 * len(dim) - 1, -1)
result = apply_ufunc(
_wrapper,
self,
input_core_dims=[dim],
exclude_dims=set(dim),
output_core_dims=[["quantile"]],
output_dtypes=[np.float64],
output_sizes={"quantile": len(q)},
dask="parallelized",
kwargs={"q": q * 100, "axis": axis, "interpolation": interpolation},
)
# for backward compatibility
result = result.transpose("quantile", ...)
if scalar:
result = result.squeeze("quantile")
if keep_attrs:
result.attrs = self._attrs
return result
xr.Variable.quantile = quantile seems to make |
Thanks a lot for this! |
Personally I would add this |
that would work if we would be working with variables, but
I agree |
keewis'
|
yes. you'll need to have 1 chunk along the dimension being reduced (here 'time'). The reason is that there is no approximate quantile algorithm implemented in dask. So this implementation is just calling |
here's the |
MCVE Code Sample
Code above gives following error:
TypeError: percentile() got an unexpected keyword argument 'axis'
Expected Output
Expected code to return percentiles of daily temperature for each latitude and longitude.
Problem Description
Code works fine on a different system with the following modules installed:
xarray: 0.14.1
pandas: 0.25.3
numpy: 1.16.2
scipy: 1.2.1
netCDF4: 1.3.1
pydap: installed
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: 2.3.2
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: 0.16.1
distributed: 1.20.2
matplotlib: 2.2.2
cartopy: 0.16.0
seaborn: 0.8.1
numbagg: None
setuptools: 38.4.0
pip: 9.0.1
conda: 4.4.10
pytest: 3.3.2
IPython: 6.2.1
sphinx: 1.6.6
Output of
xr.show_versions()
Issue occurs on system with the following installed modules:
xarray: 0.14.1
pandas: 0.25.3
numpy: 1.17.3
scipy: 1.3.2
netCDF4: 1.5.1.2
pydap: installed
h5netcdf: 0.7.4
h5py: 2.10.0
Nio: None
zarr: 2.3.2
cftime: 1.0.4.2
nc_time_axis: 1.2.0
PseudoNetCDF: None
rasterio: 1.0.25
cfgrib: None
iris: 2.2.0
bottleneck: 1.3.1
dask: 2.9.0
distributed: 2.9.0
matplotlib: 3.1.2
cartopy: 0.17.0
seaborn: 0.9.0
numbagg: None
setuptools: 44.0.0.post20200102
pip: 19.3.1
conda: None
pytest: 5.3.1
IPython: 7.11.1
sphinx: None
The text was updated successfully, but these errors were encountered: