Skip to content
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

Cannot specify options for pynio engine through backend_kwargs of open_dataset/open_dataarray #2380

Closed
joshcoden opened this issue Aug 23, 2018 · 4 comments
Labels

Comments

@joshcoden
Copy link

joshcoden commented Aug 23, 2018

Code Sample

frost_run = xr.open_dataarray("nam.grib2", engine="pynio", backend_kwargs={"SingleElementDimensions": "Initial_time"})
# or
import Nio
nio_options = Nio.options()
nio_options.SingleElementDimensions = "Initial_time"
frost_run = xr.open_dataarray("nam.grib2", engine="pynio", backend_kwargs={"options": nio_options})

Problem description

The problem is that there is not a way through xarray to set the PyNio specific options, and I have confirmed by taking a look at the initializer signature of NioDataStore

def __init__(self, filename, mode='r', autoclose=False):

Which does not provide a way to specify that value of the options parameter of the Nio.open_file method it uses

The only workaround is modify the global defaults for Nio prior to opening, i.e.,

import Nio
Nio.option_defaults["SingleElementDimensions"] = "Initial_time"
# open datasets now

Expected Output

Either way from the sample results in TypeError: __init__() got an unexpected keyword argument

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.6.final.0 python-bits: 64 OS: Darwin OS-release: 17.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

xarray: 0.10.8
pandas: 0.23.4
numpy: 1.15.0
scipy: 1.1.0
netCDF4: 1.4.1
h5netcdf: 0.6.2
h5py: 2.8.0
Nio: 1.5.2
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.18.2
distributed: 1.22.1
matplotlib: 2.2.3
cartopy: 0.16.0
seaborn: 0.9.0
setuptools: 40.0.0
pip: 18.0
conda: 4.5.11
pytest: 3.7.2
IPython: 6.5.0
sphinx: 1.7.5

@jonmjoyce
Copy link
Contributor

I have the same issue but with the "format" parameter in Nio open_file. I don't know of a workaround for it.

@chiaral
Copy link
Contributor

chiaral commented Dec 11, 2018

I have found a workaround, I think, in the last item of this issue.
You have to set it before running it in xarray.
NCAR/pynio#19

@jonmjoyce
Copy link
Contributor

Thanks for the reply, but unfortunately I don't think the format can be set via options. It is a separate parameter entirely:

def open_file(filename, mode = 'r', options=None, history='', format=''):
...
file = _nio.open_file(filename,mode,options,history,format)

@shoyer
Copy link
Member

shoyer commented Dec 11, 2018

This would be pretty easy to fix if anyone wants to put together a pull request. I think you could just add **kwargs on this line:
https://github.com/pydata/xarray/blob/master/xarray/backends/pynio_.py#L48

@shoyer shoyer added the bug label Dec 11, 2018
shoyer pushed a commit that referenced this issue Feb 7, 2019
* BUG: Pass kwargs to the FileManager for pynio engine (#2380)

* TST: Added test for pynio kwargs passing (#2380)

* Fixed formatting (#2380)
dcherian pushed a commit to yohai/xarray that referenced this issue Feb 14, 2019
* master:
  typo in whats_new (pydata#2763)
  Update computation.py to use Python 3 function signatures (pydata#2756)
  add h5netcdf+dask tests (pydata#2737)
  Fix name loss when masking (pydata#2749)
  fix datetime_to_numeric and Variable._to_numeric (pydata#2668)
  Fix mypy errors (pydata#2753)
  enable internal plotting with cftime datetime (pydata#2665)
  remove references to cyordereddict (pydata#2750)
  BUG: Pass kwargs to the FileManager for pynio engine (pydata#2380) (pydata#2732)
  reintroduce pynio/rasterio/iris to py36 test env (pydata#2738)
  Fix CRS being WKT instead of PROJ.4 (pydata#2715)
  Refactor (part of) dataset.py to use explicit indexes (pydata#2696)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants