-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadsb-angle-altitude.py
90 lines (80 loc) · 2.48 KB
/
adsb-angle-altitude.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
#!/usr/bin/python3
# adsb-speed-altitude.py slicer for speed and altitude
# LICENSE Apache 2.0
# copyright 2023 by coniferconifer
#
import pandas as pd
import matplotlib.pyplot as plt
import csv
import sys
print('adsb-angle-altitude.py angle vs altitude')
speed=''
icao=''
time=''
first_date=''
first_time=''
last_date=''
last_time=''
if len(sys.argv) < 2: # fine not specified
print("specify .csv file from dump1090 port 30003")
sys.exit(1)
try:
f = open(sys.argv[1], 'r', newline='') # open csv file
print(sys.argv[1])
except FileNotFoundError:
print('csv file not found')
sys.exit(2)
print('Phase1: producing output.csv as working file')
reader = csv.reader(f)
writer = csv.writer(open('output.csv', 'w', newline=''),quoting=csv.QUOTE_NONNUMERIC, quotechar=' ')
first_row = next(reader)
last_row = None
icao_dict={}
for row in reader:
last_row = row
if ( row[1]=='4' ): #find MSG,4 where speed is written in row12
# speed=row[12]
angle=row[13]
time=row[9]
icao=row[4]
icao_dict[icao]=angle # make latest icao and speed pair
print(time,'.',icao,',',icao_dict[icao],',','angle')
if row[1]=='3' and row[4] in icao_dict: # if MSG,3
print(row[9],',',row[4],',',icao_dict[row[4]],',',row[11], ',',row[14],',' ,row[15])
arg=row[9]+','+row[4]+','+icao_dict[row[4]]+','+row[11]+ ','+row[14]+','+row[15]
writer.writerow([arg])
# get start and last date/time
first_date = first_row[8]
first_time = first_row[9]
last_date = last_row[8]
last_time = last_row[9]
print(f'First row {first_date} {first_time}')
print(f'Last row {last_date} {last_time}')
f.close()
# output.csv : time, icat , angle, altitude ,lat,lon
print('Phase2: track angle altitude analysis')
dat = pd.read_csv('output.csv',header=None,index_col=0)
delta=0.05
baselon=135.83 # sliced at this longitude
flight=dat
flight2=flight[ flight[5] < baselon+delta]
flight3=flight2[ flight2[5] >= baselon]
x=flight3[2]
print(x)
y=flight3[3]
print(y)
print(flight3)
print('Phase3: making scatter plot')
plt.scatter(x,y,s=200 , alpha=0.10)
Title="Flight track angle vs altitude at Lon="+str(baselon)+" delta="+str(delta)
plt.suptitle(Title)
plt.title(first_date + ' '+first_time + '-' + last_date + ' '+ last_time)
#plt.title("blue: 2022/1/8 17:29-19:29")
plt.ylabel("Altitude(ft)")
plt.xlabel("track angle(degree)")
plt.grid(True)
file_string = 'trackangle-'+first_date+'-'+first_time+'.jpg'
new_string = file_string.replace(":", "-")
datetime_string = new_string.replace("/", "-")
plt.savefig( datetime_string)
print( datetime_string )