-
-
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
Dataset.resample() adds time dimension to independent variables #2145
Comments
Thanks for the report! Do you think you can craft a minimal working example ? |
In my previous comment I said that this would be useful for staggered grids, but then I realized that resample only operates on the time dimension. Anyway, here is my example: import xarray as xr
import pandas as pd
import numpy as np
# Create coordinates
time = pd.date_range('1/1/2018', periods=365, freq='D')
space = pd.np.arange(10)
# Create random variables
var_withtime1 = np.random.randn(len(time), len(space))
var_withtime2 = np.random.randn(len(time), len(space))
var_timeless1 = np.random.randn(len(space))
var_timeless2 = np.random.randn(len(space))
# Create dataset
ds = xr.Dataset({'var_withtime1': (['time', 'space'], var_withtime1),
'var_withtime2': (['time', 'space'], var_withtime2),
'var_timeless1': (['space'], var_timeless1),
'var_timeless2': (['space'], var_timeless2)},
coords={'time': (['time',], time),
'space': (['space',], space)})
# Standard resample: this add the time dimension to the timeless variables
ds_resampled = ds.resample(time='1M').mean()
# My workaround: this does not add the time dimension to the timeless variables
ds_withtime = ds.drop([ var for var in ds.variables if not 'time' in ds[var].dims ])
ds_timeless = ds.drop([ var for var in ds.variables if 'time' in ds[var].dims ])
ds_workaround = xr.merge([ds_timeless, ds_withtime.resample(time='1M').mean()]) Datasets:
|
I see. Note that |
This is not really desirable behavior, but it's an implication of how xarray implements
To fix this I would suggest three steps:
|
There is compatibility code in |
Code Sample, a copy-pastable example if possible
Problem description
I'm downsampling in time a dataset which also contains timeless variables.
I've noticed that resample adds the time dimension to the timeless variables.
One workaround is:
This is not a big deal, but I was wondering if I'm missing some flag that avoids this behavior.
If not, is it something that can be easily implemented in resample?
It would be very useful for datasets with variables on staggered grids.
Output of
xr.show_versions()
xarray: 0.10.3
pandas: 0.20.2
numpy: 1.12.1
scipy: 0.19.1
netCDF4: 1.2.4
h5netcdf: 0.5.1
h5py: 2.7.0
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.4
distributed: 1.21.8
matplotlib: 2.0.2
cartopy: 0.16.0
seaborn: 0.7.1
setuptools: 39.1.0
pip: 9.0.1
conda: 4.5.3
pytest: 3.1.2
IPython: 6.1.0
sphinx: 1.6.2
The text was updated successfully, but these errors were encountered: