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

Add tqdm to requirements #41

Merged
merged 1 commit into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 5 additions & 23 deletions intake_thredds/source.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import fnmatch

from intake_xarray.base import DataSourceMixin
from tqdm import tqdm

from .cat import ThreddsCatalog

try:
from tqdm import tqdm
except ImportError:
tqdm = None


class THREDDSMergedSource(DataSourceMixin):
"""Merges multiple datasets into a single datasets.
Expand All @@ -29,9 +25,6 @@ class THREDDSMergedSource(DataSourceMixin):
concat_kwargs: dict
kwargs to be passed to xr.concat() filled by files opened by xr.open_dataset
previously
progressbar : bool
If True, will print a progress bar. Requires `tqdm <https://github.com/tqdm/tqdm>`__
to be installed.
metadata : dict or None
To associate with this source.

Expand Down Expand Up @@ -67,7 +60,6 @@ def __init__(
url,
path,
driver='opendap',
progressbar=True,
xarray_kwargs={},
concat_kwargs=None,
metadata=None,
Expand All @@ -82,13 +74,6 @@ def __init__(
self.xarray_kwargs = xarray_kwargs
self.concat_kwargs = concat_kwargs
self._ds = None
self.progressbar = progressbar
if self.progressbar and tqdm is None:
raise ValueError(
"Missing package 'tqdm' required for progress bars."
'You can install tqdm via (1) python -m pip install tqdm or (2) conda install -c conda-forge tqdm.'
"In case you don't want to install tqdm, please use `progressbar=False`."
)

def _open_dataset(self):
import xarray as xr
Expand All @@ -102,13 +87,10 @@ def _open_dataset(self):
else:
break
path = self.path[i:]
if self.progressbar:
data = [
ds(xarray_kwargs=self.xarray_kwargs).to_dask()
for ds in tqdm(_match(cat, path), desc='Dataset(s)', ncols=79)
]
else:
data = [ds(xarray_kwargs=self.xarray_kwargs).to_dask() for ds in _match(cat, path)]
data = [
ds(xarray_kwargs=self.xarray_kwargs).to_dask()
for ds in tqdm(_match(cat, path), desc='Dataset(s)', ncols=79)
]
if self.concat_kwargs:
self._ds = xr.concat(data, **self.concat_kwargs)
else:
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
aiohttp>=3.7
intake-xarray>=0.3
intake>=0.6.0
aiohttp >=3.7
fsspec >=0.8.5
h5netcdf >=0.8.1
intake-xarray >=0.3
intake >=0.6.0
pydap
siphon
h5netcdf>=0.8.1
tqdm
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ select = B,C,E,F,W,T4,B9

[isort]
known_first_party=intake_thredds
known_third_party=intake,intake_xarray,pkg_resources,pytest,setuptools,xarray
known_third_party=intake,intake_xarray,pkg_resources,pytest,setuptools,tqdm,xarray
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
Expand Down