This is my code
R = OM.rolling(time=59)
for label, arr_window in R:
aa_try = dset.precip \
.where(dset.precip < 50) \
.count(dim='time')
so my data is of shape 324,72,144 i.e. time,lon and lat. I want to do a rolling count over the time dimention with threshold as specified above. the problem is I expect to get data of the same dimension but instead I get only 2d data. Is there anyway to get around this? Any advice will be very helpfull.
[this should explain why the current behavior is a problem and why the expected output is a better solution.]
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Darwin
OS-release: 18.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: en_AU.UTF-8
xarray: 0.11.0
pandas: 0.23.4
numpy: 1.15.4
scipy: 1.1.0
netCDF4: 1.4.1
h5netcdf: None
h5py: 2.8.0
Nio: None
zarr: None
cftime: 1.0.3.4
PseudonetCDF: None
rasterio: None
iris: 2.2.0
bottleneck: None
cyordereddict: None
dask: 1.0.0
distributed: 1.25.0
matplotlib: 3.0.2
cartopy: 0.17.0
seaborn: 0.9.0
setuptools: 40.6.2
pip: 18.1
conda: None
pytest: None
IPython: 7.2.0
sphinx: 1.8.3
I'm very confused by your code. I think you want dset.where(dset.precip < 50).rolling(time=59).count('time')?
Hi thanks but yes I want something like you have written I tried it and got the following error
aa = dset.where(dset.precip<50).rolling(time=59).count('time')
Traceback (most recent call last):
File "/Users/mada0007/anaconda3/envs/RAWORK/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "
aa = dset.where(dset.precip<50).rolling(time=59).count('time')
TypeError: rolling_count() takes 1 positional argument but 2 were given
You don't need 'time' argument in .count.
Probably
aa = dset.where(dset.precip<50).rolling(time=59).count()
Hi all so finally it worked, just for the benefit of others this is how it wents
aa = dset.where(dset.precip<50).rolling(time=59).count()
this works but brings up a dataset which i then convert to xarray dataset with
aa = aa.to_array()
Thanks to all for the guidance.
We should print a better error message when the user passes a dimension to rolling.
Most helpful comment
You don't need 'time' argument in
.count.Probably