forked from simonrp84/Satellite_Trajectories
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
157 lines (125 loc) · 4.75 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'''
This library overlays aircraft trajectories onto satellite images.
Useful for examining incidents such as weather encounters.
Currently supported aircraft data:
- Time/Lat/Lon/Alt CSV
Currently supported satellite data:
- Himawari
- GOES-R/S
See the show_usage() function in Utils.py for call information.
This file contains the main routine for running the library,
main_aircraft_processing(), and an example of how to call it.
Currently an 'opts' list must be passed. In this future this will
become a class, which would be easier to use.
'''
from datetime import datetime
import Utils as utils
import Data_Load as indata
import Plotting as acplot
import sys
def main_aircraft_processing(opts):
sat_dir = opts[0]
flt_fil = opts[1]
sensor = opts[2]
flt_typ = opts[3]
out_dir = opts[4]
beg_t = opts[5]
end_t = opts[6]
mode = opts[7]
comp = opts[8]
lat_bnd = opts[9]
lon_bnd = opts[10]
sat_cmap = opts[11]
bg_col = opts[12]
ac_se_col = opts[13]
ac_cmap = opts[14]
ac_mina = opts[15]
ac_maxa = opts[16]
ac_pos_col = opts[17]
txt_col = opts[18]
txt_size = opts[19]
txt_pos = opts[20]
cache_dir = opts[21]
res = opts[22]
linewid = opts[23]
dotsiz = opts[24]
singlep = opts[25]
if (singlep):
print("Beginning processing for single point.")
else:
print("Beginning processing for trajectory.")
if (flt_typ == 'CSV'):
ac_traj = indata.read_aircraft_csv(flt_fil, beg_t, end_t)
ac_traj2 = utils.interp_ac(ac_traj, '30S')
print("\t-\tLoaded aircraft trajectory.")
if (singlep):
plot_bounds = utils.calc_bounds_sp(ac_traj, lat_bnd, lon_bnd)
else:
plot_bounds = utils.calc_bounds_traj(ac_traj, lat_bnd, lon_bnd)
n_traj_pts2 = len(ac_traj2)
area = utils.create_area_def(plot_bounds, res)
start_t, end_t, tot_time = utils.get_startend(ac_traj, sensor, mode)
prev_time = datetime(1850, 1, 1, 0, 0, 0)
old_scn = None
sat_img = None
for i in range(2, n_traj_pts2):
cur_time = ac_traj2.index[i]
print('\t-\tNow processing', cur_time)
sat_time = utils.get_cur_sat_time(cur_time, sensor, mode)
if (sat_time != prev_time):
print('\t-\tLoading satellite data for', sat_time)
sat_img = indata.load_sat(sat_dir, sat_time, comp,
sensor, area, cache_dir, mode)
if (sat_img is None and old_scn is not None):
sat_img = old_scn
elif (sat_img is None):
print("ERROR: No satellite data for", sat_time)
old_scn = sat_img
prev_time = sat_time
else:
print('\t-\tSatellite data already loaded for', sat_time)
print('\t-\tPlotting and saving results')
fig = acplot.setup_plot(plot_bounds, bg_col, linewid)
if (sat_img is not None):
fig = acplot.overlay_sat(fig, sat_img, comp, sat_cmap)
fig = acplot.overlay_startend(fig, ac_traj2, ac_se_col, dotsiz)
if (not singlep):
fig = acplot.overlay_ac(fig, ac_traj2, i, ac_cmap, ac_mina, ac_maxa, linewid)
fig = acplot.add_acpos(fig, ac_traj2, i, ac_pos_col, dotsiz)
fig = acplot.overlay_time(fig, cur_time, txt_col, txt_size, txt_pos)
acplot.save_output_plot(out_dir+str(i-1).zfill(4)+'_'+comp+'.png',
fig, 600)
fig.clf()
fig.close()
print("Completed processing")
cache_dir = '/home/s/Satpy_Cache/'
if (len(sys.argv) < 6 or len(sys.argv) > 8):
utils.show_usage()
s_d, f_f, sen, md, fltt, o_d, b_t, e_t = utils.sort_args(sys.argv)
inopts = [s_d, # Sat dir
f_f, # Flight file
sen, # Sensor
fltt, # Flight type
o_d, # Output directory
b_t, # Initial processing time
e_t, # Ending processing time
md, # Scanning mode
'C02', # Composite mode / band
0.3, # Lat multiplier
0.3, # Lon multiplier
'Greys_r', # Satellite colourmap
'Red', # Coastlines colour
'Red', # Aircraft start/end position colour
'viridis', # Aircraft trajectory colourmap
1000, # Aircraft min altitude for colourmap
35000, # Aircraft max altitude for colourmap
'Green', # Aircraft position colour
'Cyan', # Text colour
7, # Text fontsize
[0.02, 0.95], # Text position
cache_dir, # Cache dir for satpy
0.025, # Output map resolution
1.0, # Linewidth for borders and trajectory
2.0, # Dot size for start / end and current aircraft position
False] # Single point mode, only one aircraft position
main_aircraft_processing(inopts)