Skip to main content

Copernicus Data API Install

From scratch

Install mini conda

https://docs.anaconda.com/miniconda/miniconda-install/

source ~/.bashrc

Install the CDS API dependencies

conda create --name cdsapi

conda activate cdsapi

conda install -c conda-forge cdsapi

With this the steps to get a download going will be the following:

1) create the .cdsapirc file in your home directory with the data key
2) create the python script to download the data that you want

You can do these from the command line on hammer.eri.ucsb.edu. If you login to the copernicus website it will give you the two lines with the data key that get pasted into the .cdsapirc file at this link: https://cds.climate.copernicus.eu/api-how-to

The simplest to use command line editor on linux is probably nano, so to accomplish 1):

nano ~/.cdsapirc

then paste in the info on the right that looks similar to this:
url: https://cds.climate.copernicus.eu/api/v2
key: 327150:8d92b4a2- <etc >

Similarly, to create the python script, you can use the copernicus website, and find the data you want to download. At the bottom, they give you the python code that you can copy and paste into a .py file to run the data download. Save this in a directory where you want to save the data (probably not your home directory). 

Once that is done, here's how you can run the data download:

1) run this in a screen so you can detach very long downloads (name the screen 'run_download')
screen -S run_download


2) activate the conda environment for python
conda activate cdsapi

3) run your python code (say the file is called download_data.py)
cd /home/lab-data-space     # change directory to where you saved the code
python download_data.py # run the code

4) if it's running a while you can detach from the screen:
type 'ctrl-a d'   (hit 'ctrl-a' at the same time, then hit  the d key)

... and reattach later:
screen -r run_download

when done

(cdsapi) username@hammer:~$ conda deactivate
(base) username@hammer:~$ conda deactivate