File tree 5 files changed +62
-3
lines changed 5 files changed +62
-3
lines changed Original file line number Diff line number Diff line change @@ -388,6 +388,38 @@ over the network until we look at particular values:
388
388
389
389
.. image :: _static/opendap-prism-tmax.png
390
390
391
+ Some servers require authentication before we can access the data. For this
392
+ purpose we can explicitly create a :py:class: `~xarray.backends.PydapDataStore `
393
+ and pass in a `Requests `__ session object. For example for
394
+ HTTP Basic authentication::
395
+
396
+ import xarray as xr
397
+ import requests
398
+
399
+ session = requests.Session()
400
+ session.auth = ('username', 'password')
401
+
402
+ store = xr.backends.PydapDataStore.open('http://example.com/data',
403
+ session=session)
404
+ ds = xr.open_dataset(store)
405
+
406
+ `Pydap's cas module `__ has functions that generate custom sessions for
407
+ servers that use CAS single sign-on. For example, to connect to servers
408
+ that require NASA's URS authentication::
409
+
410
+ import xarray as xr
411
+ from pydata.cas.urs import setup_session
412
+
413
+ ds_url = 'https://gpm1.gesdisc.eosdis.nasa.gov/opendap/hyrax/example.nc'
414
+
415
+ session = setup_session('username', 'password', check_url=ds_url)
416
+ store = xr.backends.PydapDataStore.open(ds_url, session=session)
417
+
418
+ ds = xr.open_dataset(store)
419
+
420
+ __ http://docs.python-requests.org
421
+ __ http://pydap.readthedocs.io/en/latest/client.html#authentication
422
+
391
423
.. _io.rasterio :
392
424
393
425
Rasterio
Original file line number Diff line number Diff line change @@ -111,6 +111,13 @@ Enhancements
111
111
By `Joe Hamman <https://github.com/jhamman >`_ and
112
112
`Gerrit Holl <https://github.com/gerritholl >`_.
113
113
114
+ - Changed :py:class: `~xarray.backends.PydapDataStore ` to take a Pydap dataset.
115
+ This permits opening Opendap datasets that require authentication, by
116
+ instantiating a Pydap dataset with a session object. Also added
117
+ :py:meth: `xarray.backends.PydapDataStore.open ` which takes a url and session
118
+ object (:issue: `1068 `).
119
+ By `Philip Graae <https://github.com/mrpgraae >`_.
120
+
114
121
- Support applying rolling window operations using bottleneck's moving window
115
122
functions on data stored as dask arrays (:issue: `1279 `).
116
123
By `Joe Hamman <https://github.com/jhamman >`_.
Original file line number Diff line number Diff line change @@ -288,7 +288,7 @@ def maybe_decode_store(store, lock=False):
288
288
store = backends .ScipyDataStore (filename_or_obj ,
289
289
autoclose = autoclose )
290
290
elif engine == 'pydap' :
291
- store = backends .PydapDataStore (filename_or_obj )
291
+ store = backends .PydapDataStore . open (filename_or_obj )
292
292
elif engine == 'h5netcdf' :
293
293
store = backends .H5NetCDFStore (filename_or_obj , group = group ,
294
294
autoclose = autoclose )
Original file line number Diff line number Diff line change @@ -60,9 +60,19 @@ class PydapDataStore(AbstractDataStore):
60
60
This store provides an alternative way to access OpenDAP datasets that may
61
61
be useful if the netCDF4 library is not available.
62
62
"""
63
- def __init__ (self , url ):
63
+ def __init__ (self , ds ):
64
+ """
65
+ Parameters
66
+ ----------
67
+ ds : pydap DatasetType
68
+ """
69
+ self .ds = ds
70
+
71
+ @classmethod
72
+ def open (cls , url , session = None ):
64
73
import pydap .client
65
- self .ds = pydap .client .open_url (url )
74
+ ds = pydap .client .open_url (url , session = session )
75
+ return cls (ds )
66
76
67
77
def open_store_variable (self , var ):
68
78
data = indexing .LazilyIndexedArray (PydapArrayWrapper (var ))
Original file line number Diff line number Diff line change 31
31
assert_identical )
32
32
from .test_dataset import create_test_data
33
33
34
+ from xarray .tests import mock
35
+
34
36
try :
35
37
import netCDF4 as nc4
36
38
except ImportError :
@@ -1509,6 +1511,14 @@ def test_cmp_local_file(self):
1509
1511
self .assertDatasetEqual (actual .isel (j = slice (1 , 2 )),
1510
1512
expected .isel (j = slice (1 , 2 )))
1511
1513
1514
+ def test_session (self ):
1515
+ from pydap .cas .urs import setup_session
1516
+
1517
+ session = setup_session ('XarrayTestUser' , 'Xarray2017' )
1518
+ with mock .patch ('pydap.client.open_url' ) as mock_func :
1519
+ xr .backends .PydapDataStore .open ('http://test.url' , session = session )
1520
+ mock_func .assert_called_with ('http://test.url' , session = session )
1521
+
1512
1522
@requires_dask
1513
1523
def test_dask (self ):
1514
1524
with self .create_datasets (chunks = {'j' : 2 }) as (actual , expected ):
You can’t perform that action at this time.
0 commit comments