Skip to content

Commit eff3190

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 1ece4a4 commit eff3190

3 files changed

Lines changed: 60 additions & 38 deletions

File tree

GA_Detect.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
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 os
89
import glob
9-
10-
11-
def main(start_n, fidder, do_write):
10+
import click
11+
12+
13+
@click.command()
14+
@click.option('--top-dir', default='./')
15+
@click.option('--start-n', default=0)
16+
@click.option('--do-write/--no-write', default=True)
17+
@click.option('--do-plot/--no-plot', default=True)
18+
@click.option('--metars-file', default='VABB_METAR')
19+
@click.option('--airport', default='VABB')
20+
@click.option('--n-files-proc', default=55)
21+
@click.option('--pool-proc', default=16)
22+
@click.option('--verbose', default=False)
23+
def main(top_dir, start_n, do_write, do_plot, metars_file, airport,
24+
n_files_proc, pool_proc, verbose):
1225
"""The main code for detecting go-arounds.
1326
1427
Arguments:
1528
start_n -- The index of the first file to read
16-
fidder -- the id of an open file to write log information into
1729
do_write -- boolean flag specifying whether to output data to textfile
1830
1931
"""
@@ -23,7 +35,6 @@ def main(start_n, fidder, do_write):
2335
# Of which go-arounds
2436
tot_n_ga = 0
2537

26-
top_dir = '/gf2/eodg/SRP002_PROUD_ADSBREP/GO_AROUNDS/VABB/'
2738
# indir stores the opensky data
2839
indir = top_dir + 'INDATA/'
2940

@@ -44,9 +55,9 @@ def main(start_n, fidder, do_write):
4455
os.makedirs(odir, exist_ok=True)
4556

4657
# Output filenames for saving data about go-arounds
47-
out_file_ga = 'GA_MET_NEW.csv'
58+
out_file_ga = top_dir + 'GA_MET_NEW.csv'
4859
# Output filenames for saving data about non-go-arounds
49-
out_file_noga = 'GA_NOGA_NEW.csv'
60+
out_file_noga = top_dir + 'GA_NOGA_NEW.csv'
5061

5162
t_frmt = "%Y/%m/%d %H:%M:%S"
5263

@@ -71,10 +82,9 @@ def main(start_n, fidder, do_write):
7182
colormap = {'GND': 'black', 'GN': 'black', 'CL': 'green', 'CR': 'blue',
7283
'DE': 'orange', 'LVL': 'purple', 'NA': 'red'}
7384

74-
# Number of files to open in one go
75-
n_files_proc = 55
76-
77-
pool_proc = 100
85+
metars = MEP.get_metars(metars_file, verbose=verbose)
86+
rwy_list = getattr(importlib.import_module(f'OS_Airports.{airport}'),
87+
'rwy_list')
7888

7989
f_data = []
8090
pool = mp.Pool(processes=pool_proc)
@@ -83,9 +93,6 @@ def main(start_n, fidder, do_write):
8393
print("Processing batch starting with "
8494
+ str(main_count + 1).zfill(5) + " of "
8595
+ str(fli_len).zfill(5))
86-
fidder.write("Processing batch starting with "
87-
+ str(main_count + 1).zfill(5) + " of "
88-
+ str(fli_len).zfill(5) + '\n')
8996

9097
p_list = []
9198
# First we load several files at once
@@ -116,11 +123,12 @@ def main(start_n, fidder, do_write):
116123
if (flight.stop + timedelta(minutes=5) < end_time):
117124
p_list.append(pool.apply_async(OSF.proc_fl,
118125
args=(flight,
119-
VABB.rwy_list,
126+
metars,
127+
rwy_list,
120128
odirs,
121129
colormap,
122-
True,
123-
False,)))
130+
do_plot,
131+
verbose,)))
124132
else:
125133
f_data.append(flight)
126134

@@ -199,12 +207,5 @@ def main(start_n, fidder, do_write):
199207
nogfid.close()
200208

201209

202-
# Use this to start processing from a given file number.
203-
# Can be helpful if processing fails at some point.
204-
init_num = 0
205-
206-
fid = open('/home/proud/Desktop/log.log', 'w')
207-
208-
main(init_num, fid, False)
209-
210-
fid.close()
210+
if __name__ == '__main__':
211+
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
@@ -15,7 +15,6 @@ Requires:
1515

1616
Usage:
1717
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.
18-
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:
1918

2019
### `Metars_Get_Data.py`
2120

@@ -53,9 +52,35 @@ python OpenSky_Get_Data.py \
5352
--outdir=INDATA --n-jobs=1
5453
```
5554

56-
### In `GA_Detect.py`
57-
The directory structure is set at the beginning of `main()`. You will probably want to adjust this to your own requirements.
55+
### `GA_Detect.py`
5856

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

61-
`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.
59+
Data is read and written based on a top-level directory. The default
60+
is the current working directory, which can be overridden by passing
61+
the `--top-dir` command-line option.
62+
63+
The file containing the appropriate METARS data can be passed using
64+
the `--metars-file` option.
65+
66+
The airport can be specified using the `--airport` option. See the
67+
`OS_Airports` subpackage which contains the runway definitions for the
68+
currently supported airports.
69+
70+
The `--n-files-proc` option specifies how many files to process
71+
simultaneously. This should be changed to the optimal value for your
72+
hardware.
73+
74+
The `--pool-proc` option specifies the number of multiprocessing
75+
threads to use. I have found that this can be set slightly higher than
76+
the number of cores available, as cores are not fully utilised anyway.
77+
78+
The `GA_Detect.py` command-line script uses a few defaults. The
79+
defaults are chosen to accommodate the defaults in the data fetching
80+
scripts. As such, these two calls are equivalent:
81+
82+
```bash
83+
python GA_Detect.py # does the same thing as the next command:
84+
python GA_Detect.py \
85+
--top-dir=. --metars-file=VABB_METAR --airport=VABB
86+
```

0 commit comments

Comments
 (0)