LoginSignup
1
0

More than 3 years have passed since last update.

AVWX (avwx.rest) で空港の気象情報(METAR/TAF)を取得・パースする

Last updated at Posted at 2020-04-02

空港の気象情報は METAR や TAF という書式で公開されています。
今回はOSSとしても公開されているAPIサービス AVWX.rest を見つけたので使ってみます。

image.png

以下は2020年4月時点での情報です。

METAR と TAF

METAR(Meteorological Terminal Aviation Routine Weather Report, 定時飛行場実況気象通報式) は航空機の運航に必要な現在の天候情報を定期的に通報するために定められた書式です。

東京国際空港のMETARの例
RJTT 020700Z 35024G35KT 9999 VCSH FEW040 16/02 Q1009 NOSIG RMK 1CU040 A2979 P/RR

TAF (Terminal Aerodrome Forecast, 運航用飛行場予報気象通報式) はMETARと異なり、気象予報を扱うものです。

東京国際空港のTAFの例
TAF RJTT 020505Z 0206/0312 34028G38KT 9999 FEW030
BECMG 0215/0217 34014KT
BECMG 0221/0300 15006KT
BECMG 0300/0303 19018KT

AVWX

公式サイトによれば、元々はラズパイIoT機器向けとして書かれていたものをパブリックなAPIとして公開したものだそうです。メールアドレスがあれば登録できます。

パイロットでありソフトウェア開発者であるMichael duPont氏が開発・運用しているようです。

データはJSON, XML, YAMLで取得できます。

料金体系

プラン名 Hobby Professional Enterprise
利用可能なサービス
  • 空港情報
  • METAR
  • TAF
  • 空港情報
  • METAR
  • TAF
  • PIREP
  • 複数の空港を同時に取得
  • 座標から付近の空港を取得
  • 空港情報
  • METAR
  • TAF
  • PIREP
  • 複数の空港を同時に取得
  • 座標から付近の空港を取得
  • 過去の情報
  • 優先的なサポート
API呼び出し回数 4,000 calls/day 50,000 calls/day 500,000 calls/day
料金 無料 10USD/month or 110USD/year 40USD/month or 440USD/year

アカウントを取得

https://account.avwx.rest/user/register からアカウントを取得し、APIキーを取得します。
Hobbyプランしか試していないので他のプランはわかりませんが、1ユーザに1つのキーが割り当てられるようです。複数のアプリケーションで利用する場合にもキーが同一のものとなるので留意が必要です。

データを取得する

https://avwx.docs.apiary.io/ にドキュメントがまとまっているので、まずは公式サイトを見ましょう。
以下では要点を抜粋して翻訳し、補足を追加しています。

空港情報 (Station Information)

GET: https://avwx.rest/api/station/ICAO空港コード?format=json&token=APIトークン

  • ICAO空港コード: (必須
  • format: APIが返すデータ形式(json, xml, yaml)。デフォルトは json
  • token: 取得したAPIトークン(必須
avwx.rest/api/station/RJTT?format=json&token=YourTokenHere
{
    "city": "Tokyo",
    "country": "JP",
    "elevation_ft": 35,
    "elevation_m": 11,
    "iata": "HND",
    "icao": "RJTT",
    "latitude": 35.552299,
    "longitude": 139.779999,
    "name": "Tokyo Haneda International Airport",
    "note": "TYO, Haneda",
    "reporting": true,
    "runways": [
        {
            "length_ft": 11024,
            "width_ft": 200,
            "ident1": "16L",
            "ident2": "34R"
        },
        {
            "length_ft": 9843,
            "width_ft": 200,
            "ident1": "16R",
            "ident2": "34L"
        },
        {
            "length_ft": 8200,
            "width_ft": 200,
            "ident1": "04",
            "ident2": "22"
        },
        {
            "length_ft": 8200,
            "width_ft": 200,
            "ident1": "05",
            "ident2": "23"
        }
    ],
    "state": "13",
    "type": "large_airport",
    "website": "http://www.haneda-airport.jp/",
    "wiki": "https://en.wikipedia.org/wiki/Tokyo_International_Airport"
}

METAR を取得する

GET: https://avwx.rest/api/metar/ICAO空港コードあるいは座標?options=&airport=true&reporting=true&format=json&onfail=cache&token=APIトークン

  • ICAO空港コードあるいは座標: RJTT のようなコード、もしくは 51.47,-0.4 のような緯度経度 (必須
  • options: 追加情報を取得する場合の項目。サポートされるものは次の通り。
    • info: 空港情報 (Station Information)の内容を含める。
    • translate: METARをパースした結果をシンプルにした内容。実際の内容は下記のデータ例を参照。
    • summary: 英語による要約文。実際の内容は下記のデータ例を参照。
    • sppech: 航空管制で用いられるスタイルに沿った読み上げ用の要約。実際の内容は下記のデータ例を参照。
  • airport: 緯度経度で検索する場合、空港のデータのみを含める。空港コード指定の場合は無効。
    • true(デフォルト)/false
  • reporting:緯度経度で検索する場合、気象情報を通報している地点のデータのみを含める。空港コード指定の場合は無効。
    • true(デフォルト)/false
  • format: APIが返すデータ形式
    • json(デフォルト)
    • xml
    • yaml
  • onfail: 取得に失敗した場合の挙動
    • cache: 最後に正常に取得された状態のキャッシュを返し、meta にその旨を表示する(デフォルト)
    • error: エラーを返す
  • token: 取得したAPIトークン(必須

Response の例

avwx.rest/api/metar/RJTT?options=summary,translate,speech&format=json&onfail=cache&token=YourTokenHere
{
    "meta": {
        "timestamp": "2020-04-02T08:02:12.071206+00:00Z"
    },
    "altimeter": {
        "repr": "Q1010",
        "value": 1010,
        "spoken": "one zero one zero"
    },
    "clouds": [
        {
            "repr": "FEW030",
            "type": "FEW",
            "altitude": 30,
            "modifier": null,
            "direction": null
        }
    ],
    "flight_rules": "VFR",
    "other": [],
    "sanitized": "RJTT 020742Z 34022G32KT 9999 FEW030 15/00 Q1010 RMK 1CU030 A2983",
    "visibility": {
        "repr": "9999",
        "value": 9999,
        "spoken": "nine nine nine nine"
    },
    "wind_direction": {
        "repr": "340",
        "value": 340,
        "spoken": "three four zero"
    },
    "wind_gust": {
        "repr": "32",
        "value": 32,
        "spoken": "three two"
    },
    "wind_speed": {
        "repr": "22",
        "value": 22,
        "spoken": "two two"
    },
    "wx_codes": [],
    "raw": "RJTT 020742Z 34022G32KT 9999 FEW030 15/00 Q1010 RMK 1CU030 A2983",
    "station": "RJTT",
    "time": {
        "repr": "020742Z",
        "dt": "2020-04-02T07:42:00+00:00Z"
    },
    "remarks": "RMK 1CU030 A2983",
    "dewpoint": {
        "repr": "00",
        "value": 0,
        "spoken": "zero"
    },
    "remarks_info": {
        "dewpoint_decimal": null,
        "temperature_decimal": null
    },
    "runway_visibility": [],
    "temperature": {
        "repr": "15",
        "value": 15,
        "spoken": "one five"
    },
    "wind_variable_direction": [],
    "units": {
        "altimeter": "hPa",
        "altitude": "ft",
        "temperature": "C",
        "visibility": "m",
        "wind_speed": "kt"
    },
    "summary": "Winds NNW-340 at 22kt gusting to 32kt, Vis 10km, Temp 15°C, Dew 0°C, Alt 1010 hPa, Few clouds at 3000ft",
    "speech": "Winds three four zero at 22kt gusting to 32kt. Visibility one zero kilometers. Temperature one five degrees Celsius. Dew point unknown. Altimeter one zero one zero. Few clouds at 3000ft",
    "translate": {
        "altimeter": "1010 hPa (29.83 inHg)",
        "clouds": "Few clouds at 3000ft - Reported AGL",
        "wx_codes": "",
        "visibility": "10km (6.2sm)",
        "dewpoint": "0°C (32°F)",
        "remarks": {},
        "temperature": "15°C (59°F)",
        "wind": "NNW-340 at 22kt gusting to 32kt"
    }
}}
}

TAF を取得する

GET: https://avwx.rest/api/taf/ICAO空港コード?options=&airport=true&reporting=true&format=json&onfail=cache&token=APIトークン

  • パラメータは METAR のものと同一。

Response の例

取得に失敗し、キャッシュが取得された例です。

avwx.rest/api/taf/RJTT?options=summary,translate,speech&format=json&onfail=cache&token=YourTokenHere
{
    "meta": {
        "timestamp": "2020-04-02T08:14:01.123672+00:00Z",
        "cache-timestamp": "2020-04-02T03:03:47.012000Z",
        "warning": "Unable to fetch report. This cached data might be out of date. To return an error instead, set ?onfail=error"
    },
    "raw": "RJTT 020126Z 0201/0306 34024G34KT 9999 FEW030 BECMG 0215/0218 34014KT BECMG 0221/0300 18006KT BECMG 0300/0303 18018KT",
    "station": "RJTT",
    "time": {
        "repr": "020126Z",
        "dt": "2020-04-02T01:26:00Z"
    },
    "remarks": "",
    "forecast": [
        {
            "altimeter": "",
            "clouds": [
                {
                    "repr": "FEW030",
                    "type": "FEW",
                    "altitude": 30,
                    "modifier": null,
                    "direction": null
                }
            ],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "0201/0306 34024G34KT 9999 FEW030",
            "visibility": {
                "repr": "9999",
                "value": 9999,
                "spoken": "nine nine nine nine"
            },
            "wind_direction": {
                "repr": "340",
                "value": 340,
                "spoken": "three four zero"
            },
            "wind_gust": {
                "repr": "34",
                "value": 34,
                "spoken": "three four"
            },
            "wind_speed": {
                "repr": "24",
                "value": 24,
                "spoken": "two four"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0215",
                "dt": "2020-04-02T15:00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "0201/0306 34024G34KT 9999 FEW030",
            "start_time": {
                "repr": "0201",
                "dt": "2020-04-02T01:00:00Z"
            },
            "turbulence": [],
            "type": "FROM",
            "wind_shear": null,
            "summary": "Winds NNW-340 at 24kt gusting to 34kt, Vis 10km, Few clouds at 3000ft"
        },
        {
            "altimeter": "",
            "clouds": [],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "BECMG 0215/0218 34014KT",
            "visibility": null,
            "wind_direction": {
                "repr": "340",
                "value": 340,
                "spoken": "three four zero"
            },
            "wind_gust": null,
            "wind_speed": {
                "repr": "14",
                "value": 14,
                "spoken": "one four"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0218",
                "dt": "2020-04-02T18:00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "BECMG 0215/0218 34014KT",
            "start_time": {
                "repr": "0215",
                "dt": "2020-04-02T15:00:00Z"
            },
            "turbulence": [],
            "type": "BECMG",
            "wind_shear": null,
            "summary": "Winds NNW-340 at 14kt"
        },
        {
            "altimeter": "",
            "clouds": [],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "BECMG 0221/0300 18006KT",
            "visibility": null,
            "wind_direction": {
                "repr": "180",
                "value": 180,
                "spoken": "one eight zero"
            },
            "wind_gust": null,
            "wind_speed": {
                "repr": "06",
                "value": 6,
                "spoken": "six"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0300",
                "dt": "2020-04-03T00:00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "BECMG 0221/0300 18006KT",
            "start_time": {
                "repr": "0221",
                "dt": "2020-04-02T21:00:00Z"
            },
            "turbulence": [],
            "type": "BECMG",
            "wind_shear": null,
            "summary": "Winds S-180 at 6kt"
        },
        {
            "altimeter": "",
            "clouds": [],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "BECMG 0300/0303 18018KT",
            "visibility": null,
            "wind_direction": {
                "repr": "180",
                "value": 180,
                "spoken": "one eight zero"
            },
            "wind_gust": null,
            "wind_speed": {
                "repr": "18",
                "value": 18,
                "spoken": "one eight"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0306",
                "dt": "2020-04-03T06:00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "BECMG 0300/0303 18018KT",
            "start_time": {
                "repr": "0300",
                "dt": "2020-04-03T00:00:00Z"
            },
            "turbulence": [],
            "type": "BECMG",
            "wind_shear": null,
            "summary": "Winds S-180 at 18kt"
        }
    ],
    "start_time": {
        "repr": "0201",
        "dt": "2020-04-02T01:00:00Z"
    },
    "end_time": {
        "repr": "0306",
        "dt": "2020-04-03T06:00:00Z"
    },
    "max_temp": "",
    "min_temp": "",
    "alts": null,
    "temps": null,
    "units": {
        "altimeter": "hPa",
        "altitude": "ft",
        "temperature": "C",
        "visibility": "m",
        "wind_speed": "kt"
    },
    "speech": "Starting on April 2nd - From 1 to 15 zulu, Winds three four zero at 24kt gusting to 34kt. Visibility one zero kilometers. Few clouds at 3000ft. At 15 zulu becoming Winds three four zero at 14kt. Sky clear. At 21 zulu becoming Winds one eight zero at 6kt. Sky clear. At midnight zulu becoming Winds one eight zero at 18kt. Sky clear",
    "translate": {
        "forecast": [
            {
                "altimeter": "",
                "clouds": "Few clouds at 3000ft - Reported AGL",
                "wx_codes": "",
                "visibility": "10km (6.2sm)",
                "icing": "",
                "turbulence": "",
                "wind": "NNW-340 at 24kt gusting to 34kt",
                "wind_shear": ""
            },
            {
                "altimeter": "",
                "clouds": null,
                "wx_codes": "",
                "visibility": "",
                "icing": "",
                "turbulence": "",
                "wind": "NNW-340 at 14kt",
                "wind_shear": ""
            },
            {
                "altimeter": "",
                "clouds": null,
                "wx_codes": "",
                "visibility": "",
                "icing": "",
                "turbulence": "",
                "wind": "S-180 at 6kt",
                "wind_shear": ""
            },
            {
                "altimeter": "",
                "clouds": null,
                "wx_codes": "",
                "visibility": "",
                "icing": "",
                "turbulence": "",
                "wind": "S-180 at 18kt",
                "wind_shear": ""
            }
        ],
        "max_temp": "",
        "min_temp": "",
        "remarks": {}
    }
}

取得済み METAR/TAF の文字列をパースする

すでに別のデータソースからMETAR/TAFの文字列を得ている場合、パースだけAVWXに投げることもできます。

METAR

POST: https://avwx.rest/api/parse/metar?options=translate&format=json

  • パラメータ
    • options: METAR/TAFを取得するものと同一
    • format: METAR/TAFを取得するものと同一(json, xml, yaml
  • Request Header
    • Content-Type: text/plain
    • Authorization: APIトークン
  • Request Body
    • METARの内容を記載
    • 例: RJTT 020700Z 35024G35KT 9999 VCSH FEW040 16/02 Q1009 NOSIG RMK 1CU040 A2979 P/RR

Response の例

RJTT 020700Z 35024G35KT 9999 VCSH FEW040 16/02 Q1009 NOSIG RMK 1CU040 A2979 P/RRoptions=translate でパースした例

{
    "altimeter": {
        "repr": "Q1009",
        "value": 1009,
        "spoken": "one zero zero nine"
    },
    "clouds": [
        {
            "repr": "FEW040",
            "type": "FEW",
            "altitude": 40,
            "modifier": null,
            "direction": null
        }
    ],
    "flight_rules": "VFR",
    "other": [],
    "sanitized": "RJTT 020700Z 35024G35KT 9999 VCSH FEW040 16/02 Q1009 NOSIG RMK 1CU040 A2979 P/RR",
    "visibility": {
        "repr": "9999",
        "value": 9999,
        "spoken": "nine nine nine nine"
    },
    "wind_direction": {
        "repr": "350",
        "value": 350,
        "spoken": "three five zero"
    },
    "wind_gust": {
        "repr": "35",
        "value": 35,
        "spoken": "three five"
    },
    "wind_speed": {
        "repr": "24",
        "value": 24,
        "spoken": "two four"
    },
    "wx_codes": [
        {
            "repr": "VCSH",
            "value": "Vicinity Showers"
        }
    ],
    "raw": "RJTT 020700Z 35024G35KT 9999 VCSH FEW040 16/02 Q1009 NOSIG RMK 1CU040 A2979 P/RR",
    "station": "RJTT",
    "time": {
        "repr": "020700Z",
        "dt": "2020-04-02T07:00:00+00:00Z"
    },
    "remarks": "NOSIG RMK 1CU040 A2979 P/RR",
    "dewpoint": {
        "repr": "02",
        "value": 2,
        "spoken": "two"
    },
    "remarks_info": {
        "dewpoint_decimal": null,
        "temperature_decimal": null
    },
    "runway_visibility": [],
    "temperature": {
        "repr": "16",
        "value": 16,
        "spoken": "one six"
    },
    "wind_variable_direction": [],
    "translations": {
        "altimeter": "1009 hPa (29.80 inHg)",
        "clouds": "Few clouds at 4000ft - Reported AGL",
        "wx_codes": "Vicinity Showers",
        "visibility": "10km (6.2sm)",
        "dewpoint": "2°C (36°F)",
        "remarks": {},
        "temperature": "16°C (61°F)",
        "wind": "N-350 at 24kt gusting to 35kt"
    },
    "meta": {
        "timestamp": "2020-04-02T08:22:51.536494+00:00Z"
    }
}

TAF

POST: https://avwx.rest/api/parse/taf?options=translate&format=json

  • パラメータ
    • options: METAR/TAFを取得するものと同一
    • format: METAR/TAFを取得するものと同一(json, xml, yaml
  • Request Header
    • Content-Type: text/plain
    • Authorization: APIトークン
  • Request Body
    • TAFの内容を記載
    • 例: 以下の通り
RJTT 020505Z 0206/0312 34028G38KT 9999 FEW030
BECMG 0215/0217 34014KT
BECMG 0221/0300 15006KT
BECMG 0300/0303 19018KT

Responseの例

上記TAFの例 を options=translate でパースした例

{
    "raw": "RJTT 020505Z 0206/0312 34028G38KT 9999 FEW030\r\nBECMG 0215/0217 34014KT\r\nBECMG 0221/0300 15006KT\r\nBECMG 0300/0303 19018KT",
    "station": "RJTT",
    "time": {
        "repr": "020505Z",
        "dt": "2020-04-02T05:05:00+00:00Z"
    },
    "remarks": "",
    "forecast": [
        {
            "altimeter": "",
            "clouds": [
                {
                    "repr": "FEW030",
                    "type": "FEW",
                    "altitude": 30,
                    "modifier": null,
                    "direction": null
                }
            ],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "0206/0312 34028G38KT 9999 FEW030",
            "visibility": {
                "repr": "9999",
                "value": 9999,
                "spoken": "nine nine nine nine"
            },
            "wind_direction": {
                "repr": "340",
                "value": 340,
                "spoken": "three four zero"
            },
            "wind_gust": {
                "repr": "38",
                "value": 38,
                "spoken": "three eight"
            },
            "wind_speed": {
                "repr": "28",
                "value": 28,
                "spoken": "two eight"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0215",
                "dt": "2020-04-02T15:00:00+00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "0206/0312 34028G38KT 9999 FEW030",
            "start_time": {
                "repr": "0206",
                "dt": "2020-04-02T06:00:00+00:00Z"
            },
            "turbulence": [],
            "type": "FROM",
            "wind_shear": null
        },
        {
            "altimeter": "",
            "clouds": [],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "BECMG 0215/0217 34014KT",
            "visibility": null,
            "wind_direction": {
                "repr": "340",
                "value": 340,
                "spoken": "three four zero"
            },
            "wind_gust": null,
            "wind_speed": {
                "repr": "14",
                "value": 14,
                "spoken": "one four"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0217",
                "dt": "2020-04-02T17:00:00+00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "BECMG 0215/0217 34014KT",
            "start_time": {
                "repr": "0215",
                "dt": "2020-04-02T15:00:00+00:00Z"
            },
            "turbulence": [],
            "type": "BECMG",
            "wind_shear": null
        },
        {
            "altimeter": "",
            "clouds": [],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "BECMG 0221/0300 15006KT",
            "visibility": null,
            "wind_direction": {
                "repr": "150",
                "value": 150,
                "spoken": "one five zero"
            },
            "wind_gust": null,
            "wind_speed": {
                "repr": "06",
                "value": 6,
                "spoken": "six"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0300",
                "dt": "2020-04-03T00:00:00+00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "BECMG 0221/0300 15006KT",
            "start_time": {
                "repr": "0221",
                "dt": "2020-04-02T21:00:00+00:00Z"
            },
            "turbulence": [],
            "type": "BECMG",
            "wind_shear": null
        },
        {
            "altimeter": "",
            "clouds": [],
            "flight_rules": "VFR",
            "other": [],
            "sanitized": "BECMG 0300/0303 19018KT",
            "visibility": null,
            "wind_direction": {
                "repr": "190",
                "value": 190,
                "spoken": "one nine zero"
            },
            "wind_gust": null,
            "wind_speed": {
                "repr": "18",
                "value": 18,
                "spoken": "one eight"
            },
            "wx_codes": [],
            "end_time": {
                "repr": "0312",
                "dt": "2020-04-03T12:00:00+00:00Z"
            },
            "icing": [],
            "probability": null,
            "raw": "BECMG 0300/0303 19018KT",
            "start_time": {
                "repr": "0300",
                "dt": "2020-04-03T00:00:00+00:00Z"
            },
            "turbulence": [],
            "type": "BECMG",
            "wind_shear": null
        }
    ],
    "start_time": {
        "repr": "0206",
        "dt": "2020-04-02T06:00:00+00:00Z"
    },
    "end_time": {
        "repr": "0312",
        "dt": "2020-04-03T12:00:00+00:00Z"
    },
    "max_temp": "",
    "min_temp": "",
    "alts": null,
    "temps": null,
    "translations": {
        "forecast": [
            {
                "altimeter": "",
                "clouds": "Few clouds at 3000ft - Reported AGL",
                "wx_codes": "",
                "visibility": "10km (6.2sm)",
                "icing": "",
                "turbulence": "",
                "wind": "NNW-340 at 28kt gusting to 38kt",
                "wind_shear": ""
            },
            {
                "altimeter": "",
                "clouds": null,
                "wx_codes": "",
                "visibility": "",
                "icing": "",
                "turbulence": "",
                "wind": "NNW-340 at 14kt",
                "wind_shear": ""
            },
            {
                "altimeter": "",
                "clouds": null,
                "wx_codes": "",
                "visibility": "",
                "icing": "",
                "turbulence": "",
                "wind": "SSE-150 at 6kt",
                "wind_shear": ""
            },
            {
                "altimeter": "",
                "clouds": null,
                "wx_codes": "",
                "visibility": "",
                "icing": "",
                "turbulence": "",
                "wind": "S-190 at 18kt",
                "wind_shear": ""
            }
        ],
        "max_temp": "",
        "min_temp": "",
        "remarks": {}
    },
    "meta": {
        "timestamp": "2020-04-02T08:26:55.356410+00:00Z"
    }
}

その他の機能

有料プランではPIREP(操縦士報告)も取得できるようです。

1
0
0

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
1
0