-
-
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
reduce() got multiple values for keyword argument 'dim' #3501
Comments
If you make it |
Thank you very much!! Could you please tell me where exactly did the rolling(...) set the mean dimension implicitly? Thank you again! |
Should raise an error on |
You've asked it to create the rolling object along dimension
I hope it does ;) . I skipped a few characters typing out my response... |
I agree that this looks like a silly question at first glance. So why 'dim' is not set implicitly in the rolling(time=3,...).mean(dim=time') of other variables? Thank you very much, |
You are right. If you could make a simpler reproducible example with dummy data, I could look at it. |
I just tried to reproduce this, which leads me to consider this a problem with import numpy as np
import pandas as pd
import xarray as xr
time = pd.date_range("1982-01-31", "2010-02-28", freq="M")
lat = np.linspace(-40, 40, 42)
lon = np.linspace(140, 290, 80)
air = np.random.rand(len(time), len(lat), len(lon))
time_nbds = np.random.rand(len(time), 2)
ds = xr.Dataset(
{
"air": (("time", "lat", "lon"), air),
"time_nbds": (("time", "nbds"), time_nbds),
},
coords={"lat": lat, "lon": lon, "time": time},
)
ds_dask = ds.chunk({"time": 1, "lat": 42, "lon": 80, "nbds": 2})
def rolling(ds):
return (
ds.where(ds["time.season"] == "DJF")
.rolling(time=3, min_periods=3, center=True)
.mean(dim='time')
.dropna('time')
)
print(rolling(ds))
print("---")
print(rolling(ds_dask)) prints as
|
Moreover, when I try to do something like rolling(time=3, min_period=3, center=True).mean(), without assigning anything in mean(), I am so confused at using xarray and the corresponding functions... Thanks, |
is that in the same situation as above where one dataset works as expected and the other doesn't, or does it differ between runs of the same code with the same data? Edit: what I would be interested in is an example for the second issue because I honestly can't figure out how to reproduce it. |
MCVE Code Sample
Expected Output
geo5_djf
<xarray.Dataset>
Dimensions: (lat: 33, lon: 61, time: 29)
Coordinates:
level float32 500.0
Data variables:
hgt (time, lat, lon) float32 5347.3706 5347.1294 ... 5696.4443
Problem Description
When I process the t2m2 to seasonal Dec-Jan-Feb mean, I encounter one very strange error.
The error is associated with 'dim'.
Personally, I guess the variable 't2m2' is different from variable 'geo5' only because 't2m2' originally is daily mean data, I processes them to be monthly data, as you can see in the code part.
Probably this leads to the error. But I am not able to tell why since the data structure is almost the same as the one of 'geo5'.
I apply exactly the same method from processing 'geo5' to 't2m2'.
Wierd enough is the method works fine for 'geo5' but fails for 't2m2'.
Is any one can help with this super annoying error?
The error seems like the mean(dim='time') has been set implicitly and I wrote mean(dim='time') again.
please find attached website for dealing with the rolling.
http://xarray.pydata.org/en/stable/generated/xarray.DataArray.rolling.html
TypeError Traceback (most recent call last)
in
15 t2m2_res = t2m2.where(t2m2['time.season']=='DJF')
16
---> 17 t2m2_djf = t2m2_res.air.rolling(time=3, min_periods=3,center=True).mean(dim='time').dropna('time')
//anaconda3/lib/python3.7/site-packages/xarray/core/rolling.py in method(self, **kwargs)
127 def method(self, **kwargs):
128 return self._numpy_or_bottleneck_reduce(
--> 129 array_agg_func, bottleneck_move_func, **kwargs
130 )
131
//anaconda3/lib/python3.7/site-packages/xarray/core/rolling.py in _numpy_or_bottleneck_reduce(self, array_agg_func, bottleneck_move_func, **kwargs)
381 return self._bottleneck_reduce(bottleneck_move_func, **kwargs)
382 else:
--> 383 return self.reduce(array_agg_func, **kwargs)
384
385
//anaconda3/lib/python3.7/site-packages/xarray/core/rolling.py in reduce(self, func, **kwargs)
297 rolling_dim = utils.get_temp_dimname(self.obj.dims, "_rolling_dim")
298 windows = self.construct(rolling_dim)
--> 299 result = windows.reduce(func, dim=rolling_dim, **kwargs)
300
301 # Find valid windows based on count.
TypeError: reduce() got multiple values for keyword argument 'dim'
Output of
xr.show_versions()
The text was updated successfully, but these errors were encountered: