| 1 | [](https://badge.fury.io/py/metar) |
| 2 | [](https://github.com/python-metar/python-metar/actions) |
| 3 | [](https://coveralls.io/r/python-metar/python-metar?branch=master) |
| 4 | [](https://codecov.io/gh/python-metar/python-metar) |
| 5 | |
| 6 | Python-Metar |
| 7 | ============ |
| 8 | |
| 9 | Python-metar is a python package for interpreting METAR and SPECI coded |
| 10 | weather reports. |
| 11 | |
| 12 | METAR and SPECI are coded aviation weather reports. The official |
| 13 | coding schemes are specified in the World Meteorological Organization |
| 14 | (WMO) Manual on Codes, vol I.1, Part A (WMO-306 I.i.A). US conventions |
| 15 | for METAR/SPECI reports vary in a number of ways from the international |
| 16 | standard, and are described in chapter 12 of the Federal Meteorological |
| 17 | Handbook No.1. (FMH-1 1995), issued by the National Oceanic and |
| 18 | Atmospheric Administration (NOAA). General information about the |
| 19 | use and history of the METAR standard can be found [here](https://www.ncdc.noaa.gov/wdc/metar/). |
| 20 | |
| 21 | This module extracts the data recorded in the main-body groups of |
| 22 | reports that follow the WMO spec or the US conventions, except for |
| 23 | the runway state and trend groups, which are parsed but ignored. |
| 24 | The most useful remark groups defined in the US spec are parsed, |
| 25 | as well, such as the cumulative precipitation, min/max temperature, |
| 26 | peak wind and sea-level pressure groups. No other regional conventions |
| 27 | are formally supported, but a large number of variant formats found |
| 28 | in international reports are accepted. |
| 29 | |
| 30 | Current METAR reports |
| 31 | --------------------- |
| 32 | |
| 33 | Current and historical METAR data can be obtained from various places. |
| 34 | The current METAR report for a given airport is available at the URL |
| 35 | |
| 36 | https://tgftp.nws.noaa.gov/data/observations/metar/stations/<station>.TXT |
| 37 | |
| 38 | where `station` is the four-letter ICAO airport station code. The |
| 39 | accompanying script get_report.py will download and decode the |
| 40 | current report for any specified station. |
| 41 | |
| 42 | The METAR reports for all stations (worldwide) for any "cycle" (i.e., hour) |
| 43 | in the last 24 hours are available in a single file at the URL |
| 44 | |
| 45 | https://tgftp.nws.noaa.gov/data/observations/metar/cycles/<cycle>Z.TXT |
| 46 | |
| 47 | where `cycle` is a 2-digit cycle number (`00` thru `23`). |
| 48 | |
| 49 | METAR specifications |
| 50 | -------------------- |
| 51 | |
| 52 | The [Federal Meteorological Handbook No.1. (FMC-H1-2017)](http://www.ofcm.gov/publications/fmh/FMH1/FMH1.pdf) describes the U.S. standards for METAR. The [World Meteorological Organization (WMO) Manual on Codes](http://www.wmo.int/pages/prog/www/WMOCodes.html), vol I.1, Part A (WMO-306 I.i.A) is another good reference. |
| 53 | |
| 54 | Author |
| 55 | ------ |
| 56 | |
| 57 | The `metar` library was orignally authored by [Tom Pollard](https://github.com/tomp) in January 2005, and is now maintained by contributors on Github. |
| 58 | |
| 59 | Installation |
| 60 | ------------------------------------------------------------------------ |
| 61 | |
| 62 | Install this package in the usual way, |
| 63 | |
| 64 | python -m pip install . |
| 65 | |
| 66 | # to install test packages |
| 67 | python -m pip install '.[test]' |
| 68 | |
| 69 | The test suite can be run by: |
| 70 | |
| 71 | pytest |
| 72 | |
| 73 | There are a couple of sample scripts, described briefly below. |
| 74 | |
| 75 | There's no real documentation to speak of, yet, but feel free to |
| 76 | contact me with any questions you might have about how to use this package. |
| 77 | |
| 78 | Current sources |
| 79 | --------------- |
| 80 | You can always obtain the most recent version of this package using git, via |
| 81 | |
| 82 | git clone https://github.com/python-metar/python-metar.git |
| 83 | |
| 84 | Contents |
| 85 | ------------------------------------------------------------------------ |
| 86 | |
| 87 | File | Description |
| 88 | --- | --- |
| 89 | README | this file |
| 90 | parse_metar.py | a simple commandline driver for the METAR parser |
| 91 | get_report.py | a script to download and decode the current reports for one or more stations. |
| 92 | sample.py | a simple script showing how the decoded data can be accessed. (see metar/*.py sources and the test/test_*.py scripts for more examples.) |
| 93 | sample.metar | a sample METAR report (longer than most). Try feeding this to the parse_metar.py script... |
| 94 | metar/Metar.py | the implementation of the Metar class. This class parses and represents a single METAR report. |
| 95 | metar/Datatypes.py | a support module that defines classes representing different types of meteorological data, including temperature, pressure, speed, distance, direction and position. |
| 96 | test/test_*.py | individual test modules |
| 97 | setup.py | installation script |
| 98 | |
| 99 | Example |
| 100 | ------------------------------------------------------------------------ |
| 101 | |
| 102 | See the sample.py script for an annonated demonstration of the use |
| 103 | of this code. Just as an appetizer, here's an interactive example... |
| 104 | |
| 105 | ```python |
| 106 | >>> from metar import Metar |
| 107 | >>> obs = Metar.Metar('METAR KEWR 111851Z VRB03G19KT 2SM R04R/3000VP6000FT TSRA BR FEW015 BKN040CB BKN065 OVC200 22/22 A2987 RMK AO2 PK WND 29028/1817 WSHFT 1812 TSB05RAB22 SLP114 FRQ LTGICCCCG TS OHD AND NW -N-E MOV NE P0013 T02270215') |
| 108 | >>> print obs.string() |
| 109 | station: KEWR |
| 110 | type: routine report, cycle 19 (automatic report) |
| 111 | time: Tue Jan 11 18:51:00 2005 |
| 112 | temperature: 22.7 C |
| 113 | dew point: 21.5 C |
| 114 | wind: variable at 3 knots, gusting to 19 knots |
| 115 | peak wind: WNW at 28 knots |
| 116 | visibility: 2 miles |
| 117 | visual range: runway 04R: 3000 meters to greater than 6000 meters feet |
| 118 | pressure: 1011.5 hPa |
| 119 | weather: thunderstorm with rain; mist |
| 120 | sky: a few clouds at 1500 feet |
| 121 | broken cumulonimbus at 4000 feet |
| 122 | broken clouds at 6500 feet |
| 123 | overcast at 20000 feet |
| 124 | sea-level pressure: 1011.4 hPa |
| 125 | 1-hour precipitation: 0.13in |
| 126 | remarks: |
| 127 | - Automated station (type 2) |
| 128 | - peak wind 28kt from 290 degrees at 18:17 |
| 129 | - wind shift at 18:12 |
| 130 | - frequent lightning (intracloud,cloud-to-cloud,cloud-to-ground) |
| 131 | - thunderstorm overhead and NW |
| 132 | - TSB05RAB22 -N-E MOV NE |
| 133 | METAR: METAR KEWR 111851Z VRB03G19KT 2SM R04R/3000VP6000FT TSRA BR FEW015 BKN040CB BKN065 OVC200 22/22 A2987 RMK AO2 PK WND 29028/1817 WSHFT 1812 TSB05RAB22 SLP114 FRQ LTGICCCCG TS OHD AND NW -N-E MOV NE P0013 T02270215 |
| 134 | >>>> |
| 135 | ``` |
| 136 | |
| 137 | Tests |
| 138 | ------------------------------------------------------------------------ |
| 139 | |
| 140 | The library is tested against Python 3.10-3.14. |
| 141 | |
| 142 | A [tox](https://tox.readthedocs.io/en/latest/) |
| 143 | configuration file is included to easily run tests against each of these |
| 144 | environments. To run tests against all environments, install tox and run: |
| 145 | |
| 146 | >>> tox |
| 147 | |
| 148 | To run against a specific environment, use the `-e` flag: |
| 149 | |
| 150 | >>> tox -e py310 |