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

Allow xr_kwargs #32

Merged
merged 13 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions intake_thredds/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class ThreddsCatalog(Catalog):
def __init__(self, url: str, driver: str = 'opendap', **kwargs):
self.url = url
self.driver = driver
if "decode_times" in kwargs:
aaronspring marked this conversation as resolved.
Show resolved Hide resolved
self.xarray_kwargs = {"xarray_kwargs": {"decode_times": kwargs["decode_times"]}}
else:
self.xarray_kwargs = {}
super().__init__(**kwargs)

def _load(self):
Expand Down
4 changes: 2 additions & 2 deletions intake_thredds/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def _open_dataset(self):
break
path = self.path[i:]
if self.progressbar:
data = [ds.to_dask() for ds in tqdm(_match(cat, path), desc='Dataset(s)', ncols=79)]
data = [ds(**self.xarray_kwargs).to_dask() for ds in tqdm(_match(cat, path), desc='Dataset(s)', ncols=79)]
else:
data = [ds.to_dask() for ds in _match(cat, path)]
data = [ds(**self.xarray_kwargs).to_dask() for ds in _match(cat, path)]
self._ds = xr.combine_by_coords(data, combine_attrs='override')


Expand Down
3 changes: 2 additions & 1 deletion tests/test_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ def test_ThreddsCatalog_init_catalog(thredds_cat_url):
assert 'random_attribute' in cat.metadata


@pytest.mark.parametrize('decode_times', [True, False])
@pytest.mark.parametrize('driver', ['netcdf', 'opendap'])
def test_ThreddsCatalog(thredds_cat_url, driver):
"""Test entry.to_dask() is xr.Dataset and allows opendap and netcdf as source."""
cat = intake.open_thredds_cat(thredds_cat_url, driver=driver)
cat = intake.open_thredds_cat(thredds_cat_url, driver=driver, decode_times=decode_times)
entry = cat['sst.mon.19712000.ltm.v3.nc']
if driver == 'opendap':
assert isinstance(entry, intake_xarray.opendap.OpenDapSource)
Expand Down