ECCopernicus

HDA Python library

In this page

As an alternative to using the HDA API directly (see this guide) or the sample Jupyter notebooks, you can use the Python client library hda, that abstracts away the details of the API.

The following example explains how to download files into a virtual machine instance, or a Jupyter Notebook environment.

  • First of all, this library needs to be installed in the environment. Open a terminal and type :

pip install hda

  • Afterwards, a configuration file needs to be created, in order to store the data-broker url, and the WEkEO credentials.
  • Create a file in the root location of the current user
  • Click File -> new -> Text File fill it with the following
 url: https://wekeo-broker.apps.mercator.dpi.wekeo.eu/databroker
 user: [your_wekeo_username]
 password: [your_wekeo_password]
  • Click : File ->Save As -> enter .hdarc as the name
  • Move your file .hdarc to /home/jovyan

Note : No brackets, commas ,or quotation marks are to be used around the username and password.

  • Here is an example of a Python script to query and download data. It is advised to store it in a Python file, and run it using Python3. The variable query contains the data descriptor. It can be generated by selecting the product and the region of interest in the HDA API. In this example, the Dataset used is "OLCI Land Colour Full Resolution - Sentinel-3" .
#The following line imports the HDA python library

from hda import Client

c = Client(debug=True)

#The following line contains the descriptor query. Think about changing it to the dataset, region and parameters needed

query = {
  "datasetId": "EO:ESA:DAT:SENTINEL-3:OL_2_LFR___",
  "boundingBoxValues": [
    {
      "name": "bbox",
      "bbox": [
        -7.499583333333334,
        42.3020216796485,
        11.999333333333333,
        54.75429195536845
      ]
    }
  ],
  "dateRangeSelectValues": [
    {
      "name": "position",
      "start": "2021-01-01T00:00:00.000Z",
      "end": "2021-01-15T00:00:00.000Z"
    }
  ],
  "stringChoiceValues": [
    {
      "name": "productType",
      "value": "LFR"
    },
    {
      "name": "processingLevel",
      "value": "LEVEL2"
    }
  ]
}

# The following line runs the query
matches = c.search(query)

# The following line prints the products returned by the query
print(matches)

#The download starts. All the products found in the query are downloaded consecutively
matches.download()

For more details on how to install and use the library, download a selection of products or download from an FTP repository, please refer to its documentation.

Note :

If the user encounters the following error :

requests.exceptions.HTTPError: 401 Client Error: UNAUTHORIZED for url: https://wekeo-broker.apps.mercator.dpi.wekeo.eu/databroker/datarequest

then it is likely that the WEkEO account lacks terms and conditions acceptation.

The solution is to run the PUT command to accept them, i.e. the command in: https://www.wekeo.eu/docs/harmonised-data-access-api#accepting-the-terms-and-conditions (i.e. first create a token from your credentials, and then use it to accept the Terms and Conditions.)

You can do so by opening a terminal on your Jupyter environment or VM, or by using the os.system library on Python.