-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_snr.py
executable file
·103 lines (80 loc) · 2.29 KB
/
plot_snr.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import json
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
sats=0
used=0
sat_name=[]
sat_pwr=[]
sat_ena=[]
#json from gpspipe
jsonf='/tmp/gps1.json'
#output
gpspng='/tmp/gps-plot.png'
# all happens here
with open(jsonf) as data_file:
data = json.load(data_file)
for satelita in data:
sats+=1
if(satelita['used']==bool("true")):
used+=1
sat_ena.append("1")
sat_name.append(str(satelita['PRN']))
else:
sat_ena.append("0")
sat_name.append(str(satelita['PRN']))
sat_pwr.append(satelita['ss'])
print(sats)
print(used)
#print(sat_name)
#print(sat_pwr)
#print(sat_ena)
col = []
col_b = []
for index,val in enumerate(sat_pwr):
if((10 > val) and (sat_ena[index]=="1")):
col.append('#D50000')
col_b.append('#ECEFF1')
elif(10 <= val <= 20) and (sat_ena[index]=="1"):
col.append('#DD2C00')
col_b.append('#1B5E20')
elif(20 < val < 27) and (sat_ena[index]=="1"):
col.append('#FF6D00')
col_b.append('#1B5E20')
elif(27 <= val) and (sat_ena[index]=="1"):
col.append('#00C853')
col_b.append('#1B5E20')
else:
col.append('#EDE7F6')
col_b.append('#ECEFF1')
# sat_name[index]=sat_name[index]+"\nD"
matplotlib.rc('axes',edgecolor='#E0E0E0')
plt.rcParams['savefig.facecolor']='#263238'
fig, ax = plt.subplots(figsize=(7.5, 3))
#fig = plt.figure()
g = np.arange(sats)
p1 = ax.bar(g, sat_pwr, width=0.9, align='center', color=col, edgecolor = 'black', label="A")
for index,val in enumerate(sat_pwr):
opis = str(sat_pwr[index])
if(sat_ena[index]=="0"):
opis="DI\n"+opis
else:
opis="OK\n"+opis
ax.text(index-0.35, val/sat_pwr[index]+3 ,opis, fontsize=11,fontweight='bold', color='#212121')
ax.patch.set_facecolor('#263238')
fig.set_facecolor('#37474F')
ax.tick_params(axis='x', colors='#E0E0E0')
ax.tick_params(axis='y', colors='#E0E0E0')
ax.set_ylabel('SNR (dB)', color='#E0E0E0')
ax.set_title('Siła sygnału GPS', color='#E0E0E0')
ax.set_xticks(g)
ax.set_xticklabels((sat_name))
#ax.legend()
#ax.bar_label(p1, label_type='center')
plt.savefig(gpspng, dpi=80)