LoginSignup
6

More than 5 years have passed since last update.

ECMWFのデータをpythonスクリプトでダウンロードする準備

Posted at

ECMWFのサーバーからデータをダウンロードするのには、ブラウザ上に立派なUIが用意されていてぽちぽちでダウンロード出来るのだけど、やっぱりぽちぽちは面倒なので、スクリプトでダウンロードする準備。
ECMWFのアカウントを持っていて、macportsをインストールしてあることだけが条件。

参考URL

Accessing ECMWF data servers in batch - ECMWF Web API - ECMWF Confluence Wiki https://confluence.ecmwf.int/display/WEBAPI/Accessing+ECMWF+data+servers+in+batch

手順

1.macportsでpipをインストールする。

pipのバージョンはどれでもいいと思うのだけど…とりあえずpy37のをインストールした。

terminal
$ sudo port install py37-pip
--->  Computing dependencies for py37-pip
The following dependencies will be installed:  pip_select
Continue? [Y/n]: Y
--->  Fetching archive for pip_select
--->  Attempting to fetch pip_select-0.1_0.darwin_17.noarch.tbz2 from https://packages.macports.org/pip_select
--->  Attempting to fetch pip_select-0.1_0.darwin_17.noarch.tbz2.rmd160 from https://packages.macports.org/pip_select
--->  Installing pip_select @0.1_0
--->  Activating pip_select @0.1_0
--->  Cleaning pip_select
--->  Fetching archive for py37-pip
--->  Attempting to fetch py37-pip-18.0_0.darwin_17.noarch.tbz2 from https://packages.macports.org/py37-pip
--->  Attempting to fetch py37-pip-18.0_0.darwin_17.noarch.tbz2.rmd160 from https://packages.macports.org/py37-pip
--->  Installing py37-pip @18.0_0
--->  Activating py37-pip @18.0_0
--->  Cleaning py37-pip
--->  Updating database of binaries
--->  Updating database of C++ stdlib usage
--->  Scanning binaries for linking errors
--->  No broken files found.                             
--->  No broken ports found.
--->  Some of the ports you installed have notes:
  py37-pip has the following notes:
    To make the Python 3.7 version of pip the one that is run when you execute the commands without a version suffix, e.g. 'pip', run:

    port select --set pip pip37

とこんなコメントが出てくる。(pip37の場合)

2.コメント通りpip37をActiveにする。

terminal
$ sudo port select --set pip pip37
Selecting 'pip37' for 'pip' succeeded. 'pip37' is now active.

3.インストールしたpipでecmwfのapiLibraryをインストールする。

terminal
$ sudo pip install https://software.ecmwf.int/wiki/download/attachments/56664858/ecmwf-api-client-python.tgz
(中略)
Collecting https://software.ecmwf.int/wiki/download/attachments/56664858/ecmwf-api-client-python.tgz
  Downloading https://software.ecmwf.int/wiki/download/attachments/56664858/ecmwf-api-client-python.tgz
Installing collected packages: ecmwf-api-client
  Running setup.py install for ecmwf-api-client ... done
Successfully installed ecmwf-api-client-1.5.0

4.ECMWF KEYを確認して、.ecmwfapircに書き込む

ECMWFのページにログインして下記のページに行くと、アカウントにヒモ付けられているKEYを確認できる。
ECMWF | Your API key https://api.ecmwf.int/v1/key/
下記を参考に、.ecmwfapircに書き込む。

$HOME/.ecmwfapirc
{
    "url"   : "https://api.ecmwf.int/v1",
    "key"   : "XXXXXXXXXXXXXXXXXXXXXX",
    "email" : "john.smith@example.com"
}

これで準備OK。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6