diff options
author | fxi <f@fxi.io> | 2020-07-20 12:01:56 +0200 |
---|---|---|
committer | fxi <f@fxi.io> | 2020-07-20 12:01:56 +0200 |
commit | 75f47f62253b51066302cdb443c263c5c931959a (patch) | |
tree | 14cf596d556fbf239fd16d79643c32ddd3b427d6 | |
parent | d2d2fb0a91d4bf9569f7e5335c77551854b978cf (diff) |
Dockerized
-rw-r--r-- | docker/.gitignore | 2 | ||||
-rw-r--r-- | docker/Dockerfile | 10 | ||||
-rw-r--r-- | docker/README.md | 38 | ||||
-rw-r--r-- | docker/request.json | 15 | ||||
-rw-r--r-- | docker/retrieve.py | 18 |
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..282c329 --- /dev/null +++ b/docker/request.json @@ -0,0 +1,15 @@ +{ + "url": "https://cds.climate.copernicus.eu/api/v2", + "uuid": "51446", + "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') + ) + + + |