You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on the documentation of xarray.save_mfdataset, I would expect that arguments that can be passed to xarray.Dataset.to_netcdf() can also be passed to xarray.save_mfdataset:
When not using dask, it is no different than calling to_netcdf repeatedly.
But it appears that the unlimited_dims and encoding arguments available in to_netcdf are not also available in save_mfdataset:
test_save_mfdataset_encoding_opt.py:
importxarrayasxr# create a timeseries to store in a netCDF filetimes=list(range(0,3652))
time=xr.DataArray(times, dims= ("time",))
# create a simple dataset to write using save_mfdatasettest_ds=xr.Dataset()
test_ds['time'] =time# tell netCDF to write the times as doublesencoding=dict(time=dict(dtype="double"))
# set the output file nameoutput_path="test.nc"# the test fails when encoding is added as an argument to save_mfdataset# but it works if instead the dataset is saved using# test_ds.to_netcdf(output_path, encoding = encoding)xr.save_mfdataset([test_ds], [output_path], encoding=encoding)
Is your feature request related to a problem?
Based on the documentation of
xarray.save_mfdataset
, I would expect that arguments that can be passed toxarray.Dataset.to_netcdf()
can also be passed toxarray.save_mfdataset
:But it appears that the
unlimited_dims
andencoding
arguments available into_netcdf
are not also available insave_mfdataset
:test_save_mfdataset_encoding_opt.py
:This appears to be because
save_mfdataset
does not accept theencoding
argument, nor does it accept and pass along**kwargs
.This means that datasets written with
save_mfdataset
are less flexible than those written withto_netcdf
.Describe the solution you'd like
A simple fix, which I have verified, is to modify
save_mfdataset
to accept and pass along**kwargs
:When a version of
xarray
withxarray/backends/api.py
patched as above, the test file indicated above runs as expected, with the encoding passed along:Describe alternatives you've considered
I attempted to set the encoding dictionary directly on the dataset prior to calling
save_mfdataset
, but that didn't seem to have an effect.Additional context
Here is version information, in case it is relevant:
$ python3 -c 'import xarray; print(xarray.show_versions())' INSTALLED VERSIONS ------------------ commit: None python: 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] python-bits: 64 OS: Darwin OS-release: 21.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.4 libnetcdf: 4.6.1 xarray: 0.15.0 pandas: 0.25.1 numpy: 1.17.2 scipy: 1.6.3 netCDF4: 1.4.2 pydap: installed h5netcdf: None h5py: 2.9.0 Nio: None zarr: None cftime: 1.1.1.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.2.1 dask: 2.5.2 distributed: 2.5.2 matplotlib: 3.1.3 cartopy: None seaborn: 0.9.0 numbagg: None setuptools: 41.4.0 pip: 19.2.3 conda: 4.8.3 pytest: 5.2.1 IPython: 7.8.0 sphinx: 2.2.0 None
The text was updated successfully, but these errors were encountered: