@@ -1245,37 +1245,44 @@ over the network until we look at particular values:
1245
1245
1246
1246
.. image :: ../_static/opendap-prism-tmax.png
1247
1247
1248
- Some servers require authentication before we can access the data. For this
1249
- purpose we can explicitly create a :py:class: `backends.PydapDataStore `
1250
- and pass in a `Requests `__ session object. For example for
1251
- HTTP Basic authentication::
1248
+ Some servers require authentication before we can access the data. Pydap uses
1249
+ a `Requests `__ session object (which the user can pre-define), and this
1250
+ session object can recover `authentication`__` credentials from a locally stored
1251
+ ``.netrc `` file. For example, to connect to a server that requires NASA's
1252
+ URS authentication, with the username/password credentials stored on a locally
1253
+ accessible ``.netrc ``, access to OPeNDAP data should be as simple as this::
1252
1254
1253
1255
import xarray as xr
1254
1256
import requests
1255
1257
1256
- session = requests.Session()
1257
- session.auth = ('username', 'password')
1258
+ my_session = requests.Session()
1258
1259
1259
- store = xr.backends.PydapDataStore.open('http://example.com/data',
1260
- session=session)
1261
- ds = xr.open_dataset(store)
1260
+ ds_url = 'https://gpm1.gesdisc.eosdis.nasa.gov/opendap/hyrax/example.nc'
1262
1261
1263
- `Pydap's cas module `__ has functions that generate custom sessions for
1264
- servers that use CAS single sign-on. For example, to connect to servers
1265
- that require NASA's URS authentication::
1262
+ ds = xr.open_dataset(ds_url, session=my_session, engine="pydap")
1266
1263
1267
- import xarray as xr
1268
- from pydata.cas.urs import setup_session
1264
+ Moreover, a bearer token header can be included in a `Requests `__ session
1265
+ object, allowing for token-based authentication which OPeNDAP servers can use
1266
+ to avoid some redirects.
1269
1267
1270
- ds_url = 'https://gpm1.gesdisc.eosdis.nasa.gov/opendap/hyrax/example.nc'
1271
1268
1272
- session = setup_session('username', 'password', check_url=ds_url)
1273
- store = xr.backends.PydapDataStore.open(ds_url, session=session)
1269
+ Lastly, OPeNDAP servers may provide endpoint URLs for different OPeNDAP protocols,
1270
+ DAP2 and DAP4. To specify which protocol between the two options to use, you can
1271
+ replace the scheme of the url with the name of the protocol. For example::
1274
1272
1275
- ds = xr.open_dataset(store)
1273
+ # dap2 url
1274
+ ds_url = 'dap2://gpm1.gesdisc.eosdis.nasa.gov/opendap/hyrax/example.nc'
1275
+
1276
+ # dap4 url
1277
+ ds_url = 'dap4://gpm1.gesdisc.eosdis.nasa.gov/opendap/hyrax/example.nc'
1278
+
1279
+ While most OPeNDAP servers implement DAP2, not all servers implement DAP4. It
1280
+ is recommended to check if the URL you are using `supports DAP4 `__ by checking the
1281
+ URL on a browser.
1276
1282
1277
1283
__ https://docs.python-requests.org
1278
- __ https://www.pydap.org/en/latest/client.html#authentication
1284
+ __ https://pydap.github.io/pydap/en/notebooks/Authentication.html
1285
+ __ https://pydap.github.io/pydap/en/faqs/dap2_or_dap4_url.html
1279
1286
1280
1287
.. _io.pickle :
1281
1288
0 commit comments