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 logic for remote or local files in NetCDFSource #93

Merged
merged 7 commits into from
Nov 24, 2020
Merged
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion intake_xarray/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def __init__(self, urlpath, chunks=None, combine=None, concat_dim=None,
self.storage_options = storage_options or {}
self.xarray_kwargs = xarray_kwargs or {}
self._ds = None
if isinstance(self.urlpath, list):
self._can_be_local = fsspec.utils.can_be_local(self.urlpath[0])
else:
self._can_be_local = fsspec.utils.can_be_local(self.urlpath)
super(NetCDFSource, self).__init__(metadata=metadata, **kwargs)

def _open_dataset(self):
Expand All @@ -76,7 +80,11 @@ def _open_dataset(self):
kwargs.update(concat_dim=self.concat_dim)
else:
_open_dataset = xr.open_dataset
url = fsspec.open_local(url, **self.storage_options)

if self._can_be_local:
url = fsspec.open_local(self.urlpath, **self.storage_options)
else:
url = fsspec.open(self.urlpath, **self.storage_options)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the difference here, in #82 for RasterIOSource I just pass the URLs to xr.open_rasterio() but i think we need to pass file-like objects to xr.open_dataset()

if self._can_be_local:
files = fsspec.open_local(self.urlpath, **self.storage_options)
else:
files = self.urlpath


self._ds = _open_dataset(url, chunks=self.chunks, **kwargs)

Expand Down