Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Page info
infoTypeModified date
prefixLast modified on
typeFlat

Note

Please be aware that the following page is relevant for the CDS API package of the current CDS system. If you are using the new CDS-Beta system, version 0.7.0 or higher of the cdsapi package is required and you must use Python3. Note that your CDS-Beta credentials must be used in your request. 


Info
iconfalse
titleTable of Contents

Table of Contents
maxLevel3

Easy Heading Macro

Note

You only need to go through this procedure once, before you can use the CDS API on

...

macOS to programmatically download data from either the Climate Data Store (CDS) or the Atmosphere Data Store (ADS).

Prerequisites

  1. Have You need to have a CDS or ADS account. If you don't have an account, please self register at the CDS registration page or the ADS registration, whichever is appropriate.
  2. You need Python
    • Option 1: use Python 2

    Have Python (and pip) installed on your Windows environment
    • .

      Expand
      title
    Instructions to install Python (no admin privileges needed)
    1. Download windows installer exe from Python.org download page
    2. Run the exe.
    3. Screen will be shown to chose the installation option.
    4. Uncheck "install for all user" option.
    5. Go for the custom installation.
    6. On next screen specify the directory path for which your user have full access on the computer (take a note of this as you will need it to set the environment variables).
    7. Uncheck "create shortcuts for installed application" option.
    8. Make sure "Add python to environment variable" option is Unchecked .
    9. Complete the installation.

    Add the installation and Script folder path in PATH using set (temporary) or setx (permanent) in a Command Prompt window. This is to make sure that your computer knows where to find the Python interpreter. To do this you will have to modify a setting called PATH, which is a list of directories where Windows will look for programs. Further details and examples are available here. You may choose also to set your environment variables into a batch file (e.g. set-env.bat which you will need to run from the Command Prompt.

    Expand
    titleExample of the content of a batch file to run in Command Prompt window

    @echo off

    set PY_HOME=C:\...\python37

    set PATH=%PY_HOME%;%PY_HOME%\Scripts;%PATH%

    If you have Anaconda installed you can install the CDS API by

    Code Block/<install_path>/conda/anaconda2/bin/conda config --add channels conda-forge /<install_path>/conda/anaconda2/bin/conda install cdsapi
    • Test Python 2 and install pip

      If you want to use Python 2, then it should come with your macOS. Open a Terminal and type command 'python'. You should see something like 'Python 2.7.10 (default, Feb 22 2019, 21:17:52)'. Type 'Control + D' to quit.

      For Python 2, run the 2 commands below to install pip:

      Code Block
      curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
      python get-pip.py



    • Option 2: use Python 3. You are recommended to follow instructions here using Homebrew.xcode-select --install

      Expand
      titleInstall Python3 through Homebrew


      Code Block
      xcode-select --install
      
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
      
      brew install python3



  3. Optional: you are recommended to set up a virtual environment.

Python 3 comes up with this feature. For Python 2, you may want to use Virtualenv. This is out of the scope of this knowledge base article.

Step-by-step guide

  1. Login to CDS (or Login to ADS)
  2. Copy a and copy the 2 line code displayed on this page. The code , which shows a url and your own uid:API key details as follows:
    1. For CDS users, Go to this page and copy the 2 line code displayed in the black box in the "Install the CDS API key" section.
    Paste
    1. For ADS users, Go to this page and copy the 2 line code displayed in the black box in the "Install the CDS API key" section.
  3. Create your key file in your home directory in your Terminal window as follows:

    Code Block
    touch ~/.cdsapirc


  4. Edit your key file and paste the two lines you copied in Step 2 above to your .cdsapirc key file into a  %USERPROFILE%\.cdsapirc file, where in your windows environment, %USERPROFILE% is usually located at C:\Users\Username folder). For instructions on how to create a dot file on Windows, please see here.
  5. Install the CDS API client using pip, by running the following command in

    a Command Prompt

    your Terminal window:

          

    Code Block
    pip
    install cdsapi     (or try pip install --user cdsapi)
     install cdsapi


  6. Once the CDS API client is installed, it can be used to request data from the datasets listed in the CDS catalogueand ADS catalogues. It is necessary to agree to the Terms of Use of every datasets that you intend to download. Attached to each dataset download form, the "'Show API request" ' button displays the python code to be used. Examples are also shown here.


Info

If you are getting connection issues, we recommend that in the first instance you check your proxy settings with your local IT team.


Info
iconfalse

This document has been produced in the context of the Copernicus Climate Change Service (C3S).

The activities leading to these results have been contracted by the European Centre for Medium-Range Weather Forecasts, operator of C3S on behalf of the European Union (Delegation Agreement signed on 11/11/2014 and Contribution Agreement signed on 22/07/2021). All information in this document is provided "as is" and no guarantee or warranty is given that the information is fit for any particular purpose.

For those using Ubuntu on Windows, installing pyopenssl might help.

Code Block
pip install pyopenssl

The users thereof use the information at their sole risk and liability. For the avoidance of all doubt , the European Commission and the European Centre for Medium - Range Weather Forecasts have no liability in respect of this document, which is merely representing the author's view.

Content by Label
showLabelsfalse
max5
spacesCKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "cds" and type = "page" and space = "CKB"
labelscds

...