Skip to content

Commit

Permalink
Script Metars_Get_Data.py allows automatic retrieval of metars data
Browse files Browse the repository at this point in the history
  • Loading branch information
dnouri committed Jun 26, 2020
1 parent 589d1bb commit 3810b9b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
30 changes: 30 additions & 0 deletions Metars_Get_Data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import click
import requests

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'


@click.command()
@click.option('--station', default='VABB')
@click.option('--start-dt', default='2019-08-10')
@click.option('--end-dt', default='2019-08-21')
@click.option('--outfile', default=None)
def main(station, start_dt, end_dt, outfile):
if outfile is None:
outfile = f'{station}_METAR'
year1, month1, day1 = start_dt.split('-')
year2, month2, day2 = end_dt.split('-')
url = METAR_URL_TEMPLATE.format(
station=station,
year1=year1, month1=month1, day1=day1,
year2=year2, month2=month2, day2=day2,
)
resp = requests.get(url)
resp.raise_for_status()

with open(outfile, 'w') as fout:
fout.writelines(line + '\n' for line in resp.text.splitlines()[1:])


if __name__ == '__main__':
main()
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@ This tool enables the automatic detection of go-around events in aircraft positi
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.

Requires:
Xavier Olive's `Traffic` library: https://github.com/xoolive/traffic

- Xavier Olive's `Traffic` library: https://github.com/xoolive/traffic

Junzi Sun's `flight-data-processor` library: https://github.com/junzis/flight-data-processor
- Junzi Sun's `flight-data-processor` library: https://github.com/junzis/flight-data-processor

- The requests library: `pip install requests`

- The click library: `pip install click`

Usage:
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.
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:

### `Metars_Get_Data.py`

To download the METARS data for a given station and timespan, use the
`Metars_Get_Data.py` script. This script uses defaults that
correspond to the ones used in the `OpenSky_Get_Data.py` script, thus
these two calls are equivalent:

```bash
python Metars_Get_Data.py
python Metars_Get_Data.py \
--station=VABB --start-dt=2019-08-10 --end-dt=2019-08-21 \
--outfile=VABB_METARS
```

### `OpenSky_Get_Data.py`:

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

0 comments on commit 3810b9b

Please sign in to comment.