-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
xray.open_mfdataset
concatenates also variables without time dimension
#438
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
Comments
Hmm, I'll have to think about this one. We use some heuristics to figure out what to concatenation but they aren't perfect. Could you print what the full datasets look like, not just this variable? |
Here is a print-out of the full dataset for POP ocean model output (see that gist in nbviewer). I can see that the heuristics exclude variables from concatenation that are associated with dimensions of other variables. But why not just exclude all that do not have a time dimension? |
|
Yeah, this is probably a good idea.
|
With #473, you will be able to achieve your desired result by adjusting the |
Hi @shoyer: where is this In [10]: ds = xarray.open_mfdataset("/snow3/huziy/Daymet_daily_derivatives/daymet_spatial_agg_tmin_10x10/daymet_v3_tmin_*.nc4", data_vars="minimum")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-ba844206f74a> in <module>()
----> 1 ds = xarray.open_mfdataset("/snow3/huziy/Daymet_daily_derivatives/daymet_spatial_agg_tmin_10x10/daymet_v3_tmin_*.nc4", data_vars="minimum")
/snow3/huziy/Python/python_builds/anaconda3/envs/py3.6-a3/lib/python3.6/site-packages/xarray/backends/api.py in open_mfdataset(paths, chunks, concat_dim, compat, preprocess, engine, lock, **kwargs)
503 paths = sorted(glob(paths))
504 else:
--> 505 paths = [str(p) if isinstance(p, path_type) else p for p in paths]
506
507 if not paths:
/snow3/huziy/Python/python_builds/anaconda3/envs/py3.6-a3/lib/python3.6/site-packages/xarray/backends/api.py in <listcomp>(.0)
503 paths = sorted(glob(paths))
504 else:
--> 505 paths = [str(p) if isinstance(p, path_type) else p for p in paths]
506
507 if not paths:
TypeError: open_dataset() got an unexpected keyword argument 'data_vars'
In [11]: ds = xarray.open_mfdataset("/snow3/huziy/Daymet_daily_derivatives/daymet_spatial_agg_tmin_10x10/daymet_v3_tmin_*.nc4")
In [12]: ds.data_vars = "minimum"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-9026b067946d> in <module>()
----> 1 ds.data_vars = "minimum"
/snow3/huziy/Python/python_builds/anaconda3/envs/py3.6-a3/lib/python3.6/site-packages/xarray/core/common.py in __setattr__(self, name, value)
180 raise AttributeError(
181 "cannot set attribute %r on a %r object. Use __setitem__ "
--> 182 "style assignment (e.g., `ds['name'] = ...`) instead to "
183 "assign variables." % (name, type(self).__name__))
184 object.__setattr__(self, name, value)
AttributeError: can't set attribute
In [13]: ds.data_vars
Out[13]:
Data variables:
tmin (time, y, x) float64 nan nan nan nan nan nan ...
lon (time, y, x) float64 156.5 156.5 156.6 156.6 ...
lat (time, y, x) float64 58.55 58.64 58.72 58.81 ...
lambert_conformal_conic (time) int64 -32767 -32767 -32767 -32767 -32767 ...
In [16]: xarray.__version__
Out[16]: '0.9.6' Cheers |
I think you've accidentally used "minimum" instead of "minimal" |
Thanks @spencerahill : Cheers |
|
This seems to be working, and no deprecation warning... (But probably I have to sort paths...) In [8]: ds = xarray.concat([xarray.open_dataset(p, chunks={"time": 100}) for p in paths], data_vars="minimal", dim="time")
In [9]: ds
Out[9]:
<xarray.Dataset>
Dimensions: (time: 13505, x: 782, y: 808)
Coordinates:
* x (x) float64 -4.556e+06 -4.546e+06 -4.536e+06 ...
* y (y) float64 4.98e+06 4.97e+06 4.96e+06 4.95e+06 ...
* time (time) datetime64[ns] 1993-01-01T12:00:09.140797440 ...
Data variables:
lon (y, x) float64 156.5 156.5 156.6 156.6 156.7 ...
lat (y, x) float64 58.55 58.64 58.72 58.81 58.9 ...
lambert_conformal_conic int16 -32767
tmin (time, y, x) float64 nan nan nan nan nan nan ...
In [10]: lon = ds["lon"]
In [11]: lon.ndim
Out[11]: 2 Cheers |
Indeed, |
I stand corrected. Misread the old issue. ☕️ 😪 |
Thanks @shoyer: Cheers |
When opening a multi-file dataset with
xray.open_mfdataset
, also some variables are concatenated that do not have atime
dimension.My netCDF files contain a lot of those "static" variables (e.g. grid spacing etc.).
netCDF4.MFDataset
used to handle those as expected (i.e. did not concatenate them).Is the different behaviour of
xray.open_mfdataset
intentional or due to a bug?Note: I am using
decode_times=False
.Example
The text was updated successfully, but these errors were encountered: