-
Notifications
You must be signed in to change notification settings - Fork 0
/
sumpolar.sh
executable file
·121 lines (105 loc) · 4.21 KB
/
sumpolar.sh
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
#!/bin/bash
# filename: sumpolar.sh
###############################################################################
# #
# ADS-B_heatmaps: Collection of Linux Scripts for ADS-B data visualization #
# Coded by A.D. Wright - GPLv3 License - github.com/AD-Wright/ADS-B_heatmaps #
# #
###############################################################################
### USER CONFIGURATION ###
# installed directory (update after installation)
INSTALL_DIR=~/Documents/Gits/ADS-B_heatmaps
LOG_DIR=$INSTALL_DIR/log # directory needs to exist or script will fail
# plot configuration
SCALE=4 # 4 recommended
MAX_ALT=60000 # to trim out possible extrananeous or erroneous points
### END USER CONFIGURATION ###
# create intermediate file (each point on newline), remove brackets
cat $LOG_DIR/log.dat | tr -d '\n' | sed 's/\]\[/\]\
\[/g' | sed 's/\[ //g' | sed 's/\]//g' | tr -d ',' > $LOG_DIR/temp.dat
# get receiver position, alt
RLAT=$(awk '{ var=$1 ; print var }' $LOG_DIR/receiver.dat )
RLON=$(awk '{ var=$2 ; print var }' $LOG_DIR/receiver.dat )
RALT=$(awk '{ var=$4 ; print var }' $LOG_DIR/receiver.dat )
# Convert delta in lat, lon, alt to elevation and azimuth
# working formulae, after much searching, found in https://raw.githubusercontent.com/caiusseverus/adsbcompare/master/polar.sh
awk -v rlat=$RLAT -v rlon=$RLON -v ralt=$RALT '
BEGIN {
PI = atan2(0,-1)
R = 20887680
rlat = rlat * PI/180
rlon = rlon * PI/180
}
{
lat = $1 * PI/180; lon = $2 * PI/180; alt = $3; rssi = $4;
dlon = lon - rlon; dlat = lat - rlat;
a = sin(dlat/2)^2 + cos(rlat) * cos(lat) * sin(dlon/2)^2;
d = 2 * atan2(sqrt(a), sqrt(1-a)) * R;
azi = 180/PI * atan2(sin(dlon * cos(lat)),cos(rlat)*sin(lat) - sin(rlat)*cos(lat)*cos(dlon));
azi = (azi + 360) % 360;
ele = 180/PI * atan2((alt - ralt) / d - d / (2 * R), 1);
printf "%.1f %.1f %.1f %.0f %.0f\n", ele, azi, rssi, d, alt
}' $LOG_DIR/temp.dat > $LOG_DIR/converted.dat
# define size of canvas
AZISPAN=$(awk "BEGIN { print 360*$SCALE + 90 }" )
ELESPAN=$(awk "BEGIN { print 100*$SCALE + 220 }" )
# calculate margins
BMAR=$(awk "BEGIN { print 65/$ELESPAN }")
TMAR=$(awk "BEGIN { print 1-15/$ELESPAN }")
LMAR=$(awk "BEGIN { print 80/$AZISPAN }")
RMAR=$(awk "BEGIN { print 1-140/$AZISPAN }")
# sort from strongest signal to weakest (dark colors on top)
cat $LOG_DIR/converted.dat | sort -r -nk3 > $LOG_DIR/polar.dat
# plot azimuth vs. elevation
# use black background because human eye picks out bright on dark better
# inspiration from https://discussions.flightaware.com/t/signal-strength-heatmap/53109/107
gnuplot <<- EOF
set xlabel "Azimuth" tc rgb 'white'
set ylabel "Elevation" tc rgb 'white'
set border lc rgb 'white'
set key tc rgb 'white'
set key noautotitle
set pointsize 1
set term png size $AZISPAN,$ELESPAN background rgb 'black'
set bmargin at screen $BMAR
set tmargin at screen $TMAR
set lmargin at screen $LMAR
set rmargin at screen $RMAR
set cbrange [-10:0]
set autoscale xfix
set autoscale yfix
set output "$LOG_DIR/polar.png"
set palette rgb 34,35,36
plot '$LOG_DIR/polar.dat' using 2:1:3 with points pt 0 palette
EOF
# remove points higher than MAX_ALT
awk -v maxalt=$MAX_ALT '{ if ($5 < maxalt) {print $0; }}' $LOG_DIR/polar.dat > $LOG_DIR/section.dat
# define size of canvas
DISSPAN=$(awk "BEGIN { print 250*$SCALE + 90 }" )
ALTSPAN=$(awk "BEGIN { print 100*$SCALE + 220 }" )
# calculate margins
BMAR=$(awk "BEGIN { print 65/$ALTSPAN }")
TMAR=$(awk "BEGIN { print 1-15/$ALTSPAN }")
LMAR=$(awk "BEGIN { print 110/$DISSPAN }")
RMAR=$(awk "BEGIN { print 1-110/$DISSPAN }")
# plot distance vs. altitude
# inspiration same as above
gnuplot <<- EOF
set xlabel "Distance (mi)" tc rgb 'white'
set ylabel "Altitude (ft)" tc rgb 'white'
set border lc rgb 'white'
set key tc rgb 'white'
set key noautotitle
set pointsize 1
set term png size $DISSPAN,$ALTSPAN background rgb 'black'
set bmargin at screen $BMAR
set tmargin at screen $TMAR
set lmargin at screen $LMAR
set rmargin at screen $RMAR
set cbrange [-10:0]
set autoscale xfix
set autoscale yfix
set output "$LOG_DIR/section.png"
set palette rgb 34,35,36
plot '$LOG_DIR/section.dat' using (\$4/5280):5:3 with points pt 0 palette
EOF