summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorb8raoult <53792887+b8raoult@users.noreply.github.com>2020-07-21 12:24:20 +0100
committerGitHub <noreply@github.com>2020-07-21 12:24:20 +0100
commit7b8ac266be9f0843ece82e1bb5e9b2ac41a0be46 (patch)
tree183254dc0898bf8b12ebb92bbc57b0aeddd36ec0
parent702dc6e5bbc79f06df22b5ef0a7ed95293767d69 (diff)
parent593ad32729a6b41689305879561ab3ed09a637c6 (diff)
Merge pull request #20 from fxi/dockerized
Docker image for cdsapi
-rw-r--r--docker/.gitignore2
-rw-r--r--docker/Dockerfile10
-rw-r--r--docker/README.md38
-rw-r--r--docker/request.json15
-rw-r--r--docker/retrieve.py18
5 files changed, 83 insertions, 0 deletions
diff --git a/docker/.gitignore b/docker/.gitignore
new file mode 100644
index 0000000..5814586
--- /dev/null
+++ b/docker/.gitignore
@@ -0,0 +1,2 @@
+output/*
+
diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644
index 0000000..b92e74c
--- /dev/null
+++ b/docker/Dockerfile
@@ -0,0 +1,10 @@
+FROM python:3.7-alpine
+
+RUN pip3 install cdsapi
+WORKDIR /input
+COPY request.json request.json
+WORKDIR /output
+WORKDIR /app
+COPY retrieve.py retrieve.py
+
+CMD ["python", "retrieve.py"]
diff --git a/docker/README.md b/docker/README.md
new file mode 100644
index 0000000..a6555aa
--- /dev/null
+++ b/docker/README.md
@@ -0,0 +1,38 @@
+## Simple wrapper around cdsapi
+
+cdsapi homepage : https://github.com/ecmwf/cdsapi
+
+### How to use the dockerized version ?
+
+1. Write a request in json file – don't forget the file format and name. Eg.
+
+```js
+{
+ "url": "https://cds.climate.copernicus.eu/api/v2",
+ "uuid": "<user id>",
+ "key": "<user key>",
+ "variable": "reanalysis-era5-pressure-levels",
+ "options": {
+ "variable": "temperature",
+ "pressure_level": "1000",
+ "product_type": "reanalysis",
+ "date": "2017-12-01/2017-12-31",
+ "time": "12:00",
+ "format": "grib"
+ },
+ "filename":"test.grib"
+}
+```
+
+2. Run the command
+
+```sh
+docker run -it --rm \
+ -v $(pwd)/request.json:/input/request.json \
+ -v $(pwd)/.:/output \
+ <YOUR REPO>/cdsretrieve
+```
+
+Note : the file will be downloaded in the current folder, if not specified otherwise in the docker command. Inside the container, `/input` folder include the request and `/output` is target folder for the downloaded file.
+
+
diff --git a/docker/request.json b/docker/request.json
new file mode 100644
index 0000000..251210c
--- /dev/null
+++ b/docker/request.json
@@ -0,0 +1,15 @@
+{
+ "url": "https://cds.climate.copernicus.eu/api/v2",
+ "uuid": "< YOUR USER ID >",
+ "key": "< YOUR API KEY >",
+ "variable": "reanalysis-era5-pressure-levels",
+ "options": {
+ "variable": "temperature",
+ "pressure_level": "1000",
+ "product_type": "reanalysis",
+ "date": "2017-12-01/2017-12-31",
+ "time": "12:00",
+ "format": "grib"
+ },
+ "filename":"test.grib"
+}
diff --git a/docker/retrieve.py b/docker/retrieve.py
new file mode 100644
index 0000000..e635e74
--- /dev/null
+++ b/docker/retrieve.py
@@ -0,0 +1,18 @@
+import json, sys, cdsapi
+
+with open('/input/request.json') as req:
+ request = json.load(req)
+
+cds = cdsapi.Client(
+ request.get('url'),
+ request.get('uuid') + ':' + request.get('key')
+ )
+
+cds.retrieve(
+ request.get('variable'),
+ request.get('options'),
+ '/output/' +request.get('filename')
+ )
+
+
+