Skip to content

Commit e39f59e

Browse files
Mikejmnezpre-commit-ci[bot]dcherian
authored
opendap / dap4 support for pydap backend (#10182)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Deepak Cherian <[email protected]>
1 parent 3816901 commit e39f59e

File tree

7 files changed

+384
-84
lines changed

7 files changed

+384
-84
lines changed

ci/requirements/min-all-deps.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies:
4242
- pandas=2.1
4343
- pint=0.22
4444
- pip
45-
- pydap=3.4
45+
- pydap=3.5.0
4646
- pytest
4747
- pytest-cov
4848
- pytest-env

doc/user-guide/io.rst

+26-19
Original file line numberDiff line numberDiff line change
@@ -1245,37 +1245,44 @@ over the network until we look at particular values:
12451245

12461246
.. image:: ../_static/opendap-prism-tmax.png
12471247

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::
12521254

12531255
import xarray as xr
12541256
import requests
12551257

1256-
session = requests.Session()
1257-
session.auth = ('username', 'password')
1258+
my_session = requests.Session()
12581259

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'
12621261

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")
12661263

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.
12691267

1270-
ds_url = 'https://gpm1.gesdisc.eosdis.nasa.gov/opendap/hyrax/example.nc'
12711268

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::
12741272

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.
12761282

12771283
__ 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
12791286

12801287
.. _io.pickle:
12811288

doc/whats-new.rst

+12
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ New Features
2424

2525
- Added `scipy-stubs <https://github.com/scipy/scipy-stubs>`_ to the ``xarray[types]`` dependencies.
2626
By `Joren Hammudoglu <https://github.com/jorenham>`_.
27+
- Improved compatibility with OPeNDAP DAP4 data model for backend engine ``pydap``. This
28+
includes ``datatree`` support, and removing slashes from dimension names. By
29+
`Miguel Jimenez-Urias <https://github.com/Mikejmnez>`_.
2730

2831
Breaking changes
2932
~~~~~~~~~~~~~~~~
3033

34+
- The minimum versions of some dependencies were changed
35+
36+
===================== ========= =======
37+
Package Old New
38+
===================== ========= =======
39+
pydap 3.4 3.5.0
40+
===================== ========= =======
3141

3242
Deprecations
3343
~~~~~~~~~~~~
@@ -47,6 +57,8 @@ Documentation
4757

4858
- Fix references to core classes in docs (:issue:`10195`, :pull:`10207`).
4959
By `Mattia Almansi <https://github.com/malmans2>`_.
60+
- Fix references to point to updated pydap documentation (:pull:`10182`).
61+
By `Miguel Jimenez-Urias <https://github.com/Mikejmnez>`_.
5062

5163
Internal Changes
5264
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)