-
Notifications
You must be signed in to change notification settings - Fork 36
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 for no authentication and NASA Earthdata (URS) authentication for OPeNDAP #57
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ dependencies: | |
- zarr | ||
- pytest | ||
- netcdf4 | ||
- pydap | ||
- rasterio | ||
- scikit-image |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ dependencies: | |
- zarr | ||
- pytest | ||
- netcdf4 | ||
- pydap | ||
- rasterio | ||
- scikit-image |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,44 @@ class OpenDapSource(DataSourceMixin): | |
Chunks is used to load the new dataset into dask | ||
arrays. ``chunks={}`` loads the dataset with dask using a single | ||
chunk for all arrays. | ||
auth: None, "esgf" or "urs" | ||
Method of authenticating to the OPeNDAP server. | ||
Choose from one of the following: | ||
'esgf' - [Default] Earth System Grid Federation. | ||
'urs' - NASA Earthdata Login, also known as URS. | ||
None - No authentication. | ||
Note that you will need to set your username and password respectively using the | ||
environment variables DAP_USER and DAP_PASSWORD. | ||
""" | ||
name = 'opendap' | ||
|
||
def __init__(self, urlpath, chunks, xarray_kwargs=None, metadata=None, | ||
def __init__(self, urlpath, chunks, auth="esgf", xarray_kwargs=None, metadata=None, | ||
**kwargs): | ||
self.urlpath = urlpath | ||
self.chunks = chunks | ||
self.auth = auth | ||
self._kwargs = xarray_kwargs or kwargs | ||
self._ds = None | ||
super(OpenDapSource, self).__init__(metadata=metadata) | ||
|
||
def _get_session(self): | ||
from pydap.cas.esgf import setup_session | ||
username = os.getenv('DAP_USER', None) | ||
password = os.getenv('DAP_PASSWORD', None) | ||
return setup_session( | ||
username, | ||
password, | ||
check_url=self.urlpath) | ||
if self.auth is None: | ||
session = None | ||
else: | ||
if self.auth == "esgf": | ||
from pydap.cas.esgf import setup_session | ||
elif self.auth == "urs": | ||
from pydap.cas.urs import setup_session | ||
else: | ||
raise ValueError( | ||
"Authentication method should either be None, 'esgf' or 'urs', " | ||
f"got '{self.auth}' instead." | ||
) | ||
username = os.getenv('DAP_USER', None) | ||
password = os.getenv('DAP_PASSWORD', None) | ||
session = setup_session(username, password, check_url=self.urlpath) | ||
|
||
return session | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's the default. https://github.com/pydata/xarray/blob/master/xarray/backends/pydap_.py#L75 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes session can be |
||
|
||
def _open_dataset(self): | ||
import xarray as xr | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you want the default auth to be
esgf
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESGF
was the 'default' authentication method in the original code. Personally I would prefer usingURS
as the default, but might be good to preserve backward compatibility here. Edit: Or do you mean we should set the default toNone
i.e. no authentication?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaults are hard. Perhaps, @danielballan or @jsignell care to weigh in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with @martindurant's comment in the main thread. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Same for me