Skip to content

Commit da748ce

Browse files
committed
Allow for better parametrisation of GA_Detect.py command-line script
This includes the ability to configure the metars file via the command-line. The loading of the metars file has been moved to the main process to enable this.
1 parent 589d1bb commit da748ce

3 files changed

Lines changed: 56 additions & 35 deletions

File tree

GA_Detect.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
"""A script to process OpenSky ADS-B data in an attempt to detect go-around events at an airport."""
22
from traffic.core import Traffic
33
from datetime import timedelta
4+
import importlib
45
import multiprocessing as mp
5-
from OS_Airports import VABB
6+
import metar_parse as MEP
67
import OS_Funcs as OSF
78
import glob
8-
9-
10-
def main(start_n, fidder, do_write):
9+
import click
10+
11+
12+
@click.command()
13+
@click.option('--top-dir', default='./')
14+
@click.option('--start-n', default=0)
15+
@click.option('--do-write', default=True)
16+
@click.option('--metars-file', default='VABB_METAR')
17+
@click.option('--airport', default='VABB')
18+
@click.option('--n-files-proc', default=55)
19+
@click.option('--pool-proc', default=16)
20+
@click.option('--verbose', default=False)
21+
def main(top_dir, start_n, do_write, metars_file, airport,
22+
n_files_proc, pool_proc, verbose):
1123
"""The main code for detecting go-arounds.
1224
1325
Arguments:
1426
start_n -- The index of the first file to read
15-
fidder -- the id of an open file to write log information into
1627
do_write -- boolean flag specifying whether to output data to textfile
1728
1829
"""
@@ -22,7 +33,6 @@ def main(start_n, fidder, do_write):
2233
# Of which go-arounds
2334
tot_n_ga = 0
2435

25-
top_dir = '/gf2/eodg/SRP002_PROUD_ADSBREP/GO_AROUNDS/VABB/'
2636
# indir stores the opensky data
2737
indir = top_dir + 'INDATA/'
2838

@@ -68,10 +78,9 @@ def main(start_n, fidder, do_write):
6878
colormap = {'GND': 'black', 'CL': 'green', 'CR': 'blue',
6979
'DE': 'orange', 'LVL': 'purple', 'NA': 'red'}
7080

71-
# Number of files to open in one go
72-
n_files_proc = 55
73-
74-
pool_proc = 100
81+
metars = MEP.get_metars(metars_file, verbose=verbose)
82+
rwy_list = getattr(importlib.import_module(f'OS_Airports.{airport}'),
83+
'rwy_list')
7584

7685
f_data = []
7786
pool = mp.Pool(processes=pool_proc)
@@ -80,9 +89,6 @@ def main(start_n, fidder, do_write):
8089
print("Processing batch starting with "
8190
+ str(main_count + 1).zfill(5) + " of "
8291
+ str(fli_len).zfill(5))
83-
fidder.write("Processing batch starting with "
84-
+ str(main_count + 1).zfill(5) + " of "
85-
+ str(fli_len).zfill(5) + '\n')
8692

8793
p_list = []
8894
# First we load several files at once
@@ -113,11 +119,12 @@ def main(start_n, fidder, do_write):
113119
if (flight.stop + timedelta(minutes=5) < end_time):
114120
p_list.append(pool.apply_async(OSF.proc_fl,
115121
args=(flight,
116-
VABB.rwy_list,
122+
metars,
123+
rwy_list,
117124
odirs,
118125
colormap,
119126
True,
120-
False,)))
127+
verbose,)))
121128
else:
122129
f_data.append(flight)
123130

@@ -196,12 +203,5 @@ def main(start_n, fidder, do_write):
196203
nogfid.close()
197204

198205

199-
# Use this to start processing from a given file number.
200-
# Can be helpful if processing fails at some point.
201-
init_num = 0
202-
203-
fid = open('/home/proud/Desktop/log.log', 'w')
204-
205-
main(init_num, fid, False)
206-
207-
fid.close()
206+
if __name__ == '__main__':
207+
main()

OS_Funcs.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from scipy.interpolate import UnivariateSpline as UniSpl
33
from traffic.core import Traffic
44
from datetime import timedelta
5-
import metar_parse as MEP
65
import pandas as pd
76

87
import flightphase as flph
@@ -11,10 +10,6 @@
1110
import numpy as np
1211

1312

14-
# Read METARs from disk
15-
metars = MEP.get_metars('/home/proud/Desktop/GoAround_Paper/VABB_METAR')
16-
17-
1813
def estimate_rwy(df, rwy_list, verbose):
1914
"""Guess which runway a flight is attempting to land on.
2015
@@ -255,11 +250,12 @@ def check_ga(fd, verbose, first_pos=-1):
255250
return ga_flag, bpt
256251

257252

258-
def proc_fl(flight, check_rwys, odirs, colormap, do_save, verbose):
253+
def proc_fl(flight, metars, check_rwys, odirs, colormap, do_save, verbose):
259254
"""Filter, assign phases and determine go-around status for a given flight.
260255
261256
Inputs:
262257
- A 'traffic' flight object
258+
- A dict of METARS, each as a metobs class
263259
- A list storing potential landing runways to check
264260
- A 4-element list specifying various output directories:
265261
- normal plot output

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Requires:
1010

1111
Usage:
1212
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.
13-
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:
1413

1514
### `OpenSky_Get_Data.py`:
1615

@@ -34,9 +33,35 @@ python OpenSky_Get_Data.py \
3433
--outdir=INDATA --n-jobs=1
3534
```
3635

37-
### In `GA_Detect.py`
38-
The directory structure is set at the beginning of `main()`. You will probably want to adjust this to your own requirements.
36+
### `GA_Detect.py`
3937

40-
`n_files_proc` specifies how many files to process simultaneously. This should be changed to the optimal value for your hardware.
38+
The script that runs the actual go-around events.
4139

42-
`pool_proc` specifies the number of multiprocessing threads to use. I have found that this can be set slightly higher than the number of cores available, as cores are not fully utilised anyway.
40+
Data is read and written based on a top-level directory. The default
41+
is the current working directory, which can be overridden by passing
42+
the `--top-dir` command-line option.
43+
44+
The file containing the appropriate METARS data can be passed using
45+
the `--metars-file` option.
46+
47+
The airport can be specified using the `--airport` option. See the
48+
`OS_Airports` subpackage which contains the runway definitions for the
49+
currently supported airports.
50+
51+
The `--n-files-proc` option specifies how many files to process
52+
simultaneously. This should be changed to the optimal value for your
53+
hardware.
54+
55+
The `--pool-proc` option specifies the number of multiprocessing
56+
threads to use. I have found that this can be set slightly higher than
57+
the number of cores available, as cores are not fully utilised anyway.
58+
59+
The `GA_Detect.py` command-line script uses a few defaults. The
60+
defaults are chosen to accommodate the defaults in the data fetching
61+
scripts. As such, these two calls are equivalent:
62+
63+
```bash
64+
python GA_Detect.py # does the same thing as the next command:
65+
python GA_Detect.py \
66+
--top-dir=. --metars-file=VABB_METAR --airport=VABB
67+
```

0 commit comments

Comments
 (0)