Skip to content

Commit 3810b9b

Browse files
committed
Script Metars_Get_Data.py allows automatic retrieval of metars data
1 parent 589d1bb commit 3810b9b

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

Metars_Get_Data.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import click
2+
import requests
3+
4+
METAR_URL_TEMPLATE = 'https://mesonet.agron.iastate.edu/cgi-bin/request/asos.py?station={station}&data=metar&year1={year1}&month1={month1}&day1={day1}&year2={year2}&month2={month2}&day2={day2}&tz=Etc%2FUTC&format=onlycomma&latlon=no&missing=M&trace=T&direct=no&report_type=1&report_type=2'
5+
6+
7+
@click.command()
8+
@click.option('--station', default='VABB')
9+
@click.option('--start-dt', default='2019-08-10')
10+
@click.option('--end-dt', default='2019-08-21')
11+
@click.option('--outfile', default=None)
12+
def main(station, start_dt, end_dt, outfile):
13+
if outfile is None:
14+
outfile = f'{station}_METAR'
15+
year1, month1, day1 = start_dt.split('-')
16+
year2, month2, day2 = end_dt.split('-')
17+
url = METAR_URL_TEMPLATE.format(
18+
station=station,
19+
year1=year1, month1=month1, day1=day1,
20+
year2=year2, month2=month2, day2=day2,
21+
)
22+
resp = requests.get(url)
23+
resp.raise_for_status()
24+
25+
with open(outfile, 'w') as fout:
26+
fout.writelines(line + '\n' for line in resp.text.splitlines()[1:])
27+
28+
29+
if __name__ == '__main__':
30+
main()

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,33 @@ This tool enables the automatic detection of go-around events in aircraft positi
44
The tool will produce graphics showing the flight path and phase for every detected landing aircraft. Normal landings can be stored in one subdirectory, potential go-arounds in another.
55

66
Requires:
7-
Xavier Olive's `Traffic` library: https://github.com/xoolive/traffic
7+
8+
- Xavier Olive's `Traffic` library: https://github.com/xoolive/traffic
89

9-
Junzi Sun's `flight-data-processor` library: https://github.com/junzis/flight-data-processor
10+
- Junzi Sun's `flight-data-processor` library: https://github.com/junzis/flight-data-processor
11+
12+
- The requests library: `pip install requests`
13+
14+
- The click library: `pip install click`
1015

1116
Usage:
1217
First you must download aircraft data, which can be done using the `OpenSky_Get_Data` script. You can then point `GA_Detect` at the download location to scan for go-arounds.
1318
This tool is in very early development, so has manual tweaks that would ideally be changeable via a config file or directly via the command line call. The most important of these tweaks are listed below:
1419

20+
### `Metars_Get_Data.py`
21+
22+
To download the METARS data for a given station and timespan, use the
23+
`Metars_Get_Data.py` script. This script uses defaults that
24+
correspond to the ones used in the `OpenSky_Get_Data.py` script, thus
25+
these two calls are equivalent:
26+
27+
```bash
28+
python Metars_Get_Data.py
29+
python Metars_Get_Data.py \
30+
--station=VABB --start-dt=2019-08-10 --end-dt=2019-08-21 \
31+
--outfile=VABB_METARS
32+
```
33+
1534
### `OpenSky_Get_Data.py`:
1635

1736
Use the script's `--outdir` option so the the output directory. This defaults to `INDATA` in your current working directory.

0 commit comments

Comments
 (0)