Skip to content

Commit 7fc3ad8

Browse files
Add credential options to polytope source (#363)
1 parent bdc7f23 commit 7fc3ad8

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

docs/guide/sources.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,19 +695,23 @@ mars
695695
polytope
696696
--------
697697

698-
.. py:function:: from_source("polytope", collection, *args, stream=True, batch_size=1, group_by=None, **kwargs)
698+
.. py:function:: from_source("polytope", collection, *args, address=None, user_email=None, user_key=None, stream=True, batch_size=1, group_by=None, **kwargs)
699699
:noindex:
700700

701701
The ``polytope`` source accesses the `Polytope web services <https://polytope-client.readthedocs.io/en/latest/>`_ , using the polytope-client_ package.
702702

703703
:param str collection: the name of the polytope collection
704704
:param tuple *args: specify the request as a dict
705+
:param str address: specify the address of the polytope service
706+
:param str user_email: specify the user email credential. Must be used together with ``user_key``. This is an alternative to using the ``POLYTOPE_USER_EMAIL`` environment variable. *Added in version 0.7.0*
707+
:param str user_key: specify the user key credential. Must be used together with ``user_email``. This is an alternative to using the ``POLYTOPE_USER_KEY`` environment variable. *Added in version 0.7.0*
705708
:param bool stream: when it is ``True`` the data is read as a stream. Otherwise the data is retrieved into a file and stored in the :ref:`cache <caching>`. Stream-based access only works for :ref:`grib` and CoverageJson data.
706709
:param int batch_size: used when ``stream=True`` and ``group_by`` is unset. It defines how many GRIB messages are consumed from the stream and kept in memory at a time. ``batch_size=0`` means all the data is read straight to memory. For details see :ref:`stream source <data-sources-stream>`.
707710
:param group_by: used when ``stream=True`` and can specify one or more metadata keys to control how GRIB messages are read from the stream. For details see :ref:`stream source <data-sources-stream>`.
708711
:type group_by: str, list of str
709712
:param dict **kwargs: other keyword arguments specifying the request
710713
714+
711715
The following example retrieves GRIB data from the "ecmwf-mars" polytope collection:
712716

713717
.. code-block:: python

docs/release_notes/version_0.7_updates.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ New features
1919
- added support for Lambert Conformal projection when using :meth:`Field.projection() <data.core.fieldlist.Field.projection>`
2020
- changed the default of the ``bits_per_value`` option to None in :meth:`NumpyFieldList.save() <data.sources.numpy_list.NumpyFieldList.save>`. None means the original ``bits_per_value`` in the GRIB header is kept when the data is written to disk.
2121
- added the ``model`` option to the :ref:`data-sources-eod` source
22+
- added the ``user_email`` and ``user_key`` options to the :ref:`data-sources-polytope` source
2223
- added the ``prompt`` optional argument to certain retrievals to control whether the prompt is to use. When enabled, the prompt asks the user to provide credentials when none seems to be specified. See e.g. the :ref:`data-sources-cds` or :ref:`data-sources-mars` sources.
24+
- added the
2325
- allowed using :func:`save` without specifying a file name. In this case an attempt is made to generate the filename automatically, when it fails an exception is thrown.
2426
- added the :ref:`data-sources-sample` source to access data used in tests and examples
2527
- :func:`from_source` now fails when trying to load an empty file

earthkit/data/sources/polytope.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ class Polytope(Source):
5959
>>> src.to_xarray() # if datacube
6060
"""
6161

62-
def __init__(self, dataset, request, address=None, stream=True, **kwargs) -> None:
62+
def __init__(
63+
self,
64+
dataset,
65+
request,
66+
stream=True,
67+
**kwargs,
68+
) -> None:
6369
super().__init__()
6470
assert isinstance(dataset, str)
6571

@@ -70,14 +76,30 @@ def __init__(self, dataset, request, address=None, stream=True, **kwargs) -> Non
7076

7177
self.stream = stream
7278

73-
self.request = dict(dataset=dataset, request=request)
74-
75-
credentials = PolytopeWebKeyPrompt().check(load=True)
76-
79+
# Polytope client configuration options
7780
client_kwargs = {}
78-
if address is not None:
79-
client_kwargs = {"address": address}
80-
self.client = polytope.api.Client(**credentials, **client_kwargs)
81+
for k in [
82+
"config_path",
83+
"address",
84+
"port",
85+
"username",
86+
"key_path",
87+
"quiet",
88+
"verbose",
89+
"log_file",
90+
"log_level",
91+
"user_key",
92+
"user_email",
93+
"password",
94+
"insecure",
95+
"skip_tls",
96+
"cli",
97+
]:
98+
if k in kwargs:
99+
client_kwargs[k] = kwargs.pop(k, None)
100+
101+
self.request = dict(dataset=dataset, request=request)
102+
self.client = polytope.api.Client(**client_kwargs)
81103

82104
def __repr__(self) -> str:
83105
return f"{self.__class__.__name__}({self.request['dataset']}, {self.request['request']})"

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
- multiurl
2626
- git+https://github.com/ecmwf/pyfdb
2727
- ecmwf-opendata>=0.1.2
28-
- polytope-client>=0.7.2
28+
- polytope-client>=0.7.4
2929
- earthkit-meteo>=0.0.1
3030
- eccovjson>=0.0.5
3131
- earthkit-geo

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ include = earthkit.*
4646
mars = ecmwf-api-client>=1.6.1
4747
cds = cdsapi
4848
fdb = pyfdb
49-
polytope = polytope-client>=0.7.2
49+
polytope = polytope-client>=0.7.4
5050
wekeo = hda
5151
ecmwf-opendata = ecmwf-opendata>=0.3.3
5252
odb = pyodc

tests/downstream-ci-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cfgrib>=0.9.10.1
44
eccodes>=1.7.0
55
ecmwf-api-client>=1.6.1
66
ecmwf-opendata>=0.3.3
7-
polytope-client>=0.7.2
7+
polytope-client>=0.7.4
88
dask
99
entrypoints
1010
filelock

tests/environment-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies:
2727
- multiurl
2828
- git+https://github.com/ecmwf/pyfdb
2929
- ecmwf-opendata>=0.3.3
30-
- polytope-client>=0.7.2
30+
- polytope-client>=0.7.4
3131
- earthkit-meteo>=0.0.1
3232
- git+https://github.com/ecmwf/earthkit-data-demo-source
3333
- eccovjson>=0.0.5

0 commit comments

Comments
 (0)