-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_telemetry_final.py
More file actions
389 lines (301 loc) · 11.3 KB
/
plot_telemetry_final.py
File metadata and controls
389 lines (301 loc) · 11.3 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 01 17:50:27 2017
@author: Ronan Laker
"""
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import numpy as np
import re
import matplotlib.dates as md
import datetime
import time
import pandas as pd
import simplekml
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
file_text = open('telemetry.txt', 'r')
text = file_text.read()
split_instruction = re.compile(',')
split_text =split_instruction.split(text)
separation = 17
length = len(split_text)
n = length/separation
n = np.ceil(n)
i = 0
number= []
time = []
gps_long = []
gps_lat = []
altitude = []
speed = []
direction = []
satellites = []
internal_temp = []
voltage = []
current = []
temp_bme = []
pres = []
hum = []
uva = []
uvb = []
sound=[]
print length
while i < length:
if i > (length-16):
break
#goes through file and adds each variable to the right list, the last variable needs seperating from the callsign
number.append(split_text[1+i])
time.append(split_text[2+i])
gps_long.append(split_text[4+i])
gps_lat.append(split_text[3+i])
altitude.append(split_text[5+i])
speed.append(split_text[6+i])
direction.append(split_text[7+i])
satellites.append(split_text[8+i])
internal_temp.append(split_text[9+i])
voltage.append(split_text[10+i])
current.append(split_text[11+i])
temp_bme.append(split_text[12+i])
pres.append(split_text[13+i])
hum.append(split_text[14+i])
uva.append(split_text[15+i])
uvb.append(split_text[16+i])
sound.append(split_text[17+i])
i = i + separation
def fix_list(x):
for i in np.arange(0,len(x)):
if x[i][1] == '.':
x[i]=x[i][0:3]
elif x[i][2] == '.':
x[i]=x[i][0:4]
else:
x[i]=x[i][0:5]
return x
def plot_3d(X,Y,Z,zlabel):
X = [ float(x) for x in X ]
Y = [ float(x) for x in Y ]
Z = [ float(x) for x in Z ]
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
ax1.plot_wireframe(X,Y,Z)
ax1.set_xlabel('Latitiude')
ax1.set_ylabel('Longitude')
ax1.set_zlabel(zlabel)
"""plt.figure(8)
plt.plot(gps_long,gps_lat)
plt.xlabel('Long')
plt.ylabel('Lat')"""
def plot_variable(x,y,xlabel,ylabel):
plt.plot(x,y)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
def fix_time():
fixed_time_list = []
for i in time:
hour = int(i[0:2])
mins = int(i[3:5])
secs = int(i[6:8])
fixed_time = datetime.datetime(2017, 8, 19, hour, mins, secs)
fixed_time_list.append(fixed_time)
return fixed_time_list
def get_uv_ratio(uva,uvb):
uv_ratio = []
uva = [ float(x) for x in uva ]
uvb = [ float(x) for x in uvb ]
for i in np.arange(len(uva)):
if uva[i] != 0:
uv_ratio_single = uvb[i]/uva[i]
if uv_ratio_single > 100:
uv_ratio_single = uv_ratio_single/10
uv_ratio.append(uv_ratio_single)
else:
uv_ratio.append(0)
return uv_ratio
def open_image(hours, mins, secs):
image_secs = secs
image_mins = mins
if len(str(image_secs)) == 1:
image_secs = '0' + str(secs)
if len(str(image_mins)) == 1:
image_mins = '0' + str(image_mins)
image = Image.open(str(hours) + '_' + str(image_mins) + '_' + str(image_secs) + '.jpg')
return image, image_mins, image_secs
def data_for_picture(hours, mins, secs):
#finds the data for the nearest time to the picture
# i.e. a picture taken at 18:40:32 but data taken at 18:40:34
open_image(hours, mins, secs)
for i in np.arange(len(time)):
if time[i][0:2] == str(hours):
if len(str(mins)) == 1:
mins = '0' + str(mins)
if time[i][3:5] == str(mins):
list_of_secs = []
if (len(time)-i) <= 6:
for j in np.arange(0,len(time)-i):
list_of_secs.append(int(time[j+i][6:8]))
else:
for j in np.arange(0,11):
list_of_secs.append(int(time[j+i][6:8]))
list_of_secs.append(secs)
list_of_secs.sort()
i = list_of_secs.index(secs)
#print i, list_of_secs, time
if i != len(list_of_secs)-1:
above = int(list_of_secs[i+1]) - int(secs)
below = int(secs) - int(list_of_secs[i-1])
if above > below:
secs = int(list_of_secs[i-1])
if above < below:
secs = int(list_of_secs[i+1])
if above == below:
secs = int(list_of_secs[i+1])
if len(str(secs)) == 1:
secs = '0' + str(secs)
string = str(hours) + ':' + str(mins) + ':' + str(secs)
i = time.index(string)
print 'Nearest Time', time[i]
print 'Altitude', altitude[i]
print 'Internal Temp', internal_temp[i]
print 'External Temp', temp_bme[i]
print 'Pressure', pres[i]
print 'Humidity', hum[i]
print 'UVA', uva[i]
print 'UVB', uvb[i]
print 'Sound', sound[i]
print 'Co-ordinates', gps_lat[i], gps_long[i]
plot_variable(gps_lat, gps_long, 'Lat','Long')
plt.scatter(gps_lat[i], gps_long[i], s=200, color = 'r', marker='+', linewidth = 2)
return time[i], altitude[i], internal_temp[i], temp_bme[i], pres[i], hum[i], uva[i], uvb[i], sound[i], gps_lat[i],gps_long[i]
def data_on_image(hours, mins, secs):
#prints data on image
img = open_image(hours, mins, secs)
draw = ImageDraw.Draw(img[0])
font = ImageFont.truetype("Verdana.ttf",50)
stats = data_for_picture(hours, mins, secs)
string1 = 'Time: ' + stats[0]
string2 = 'Altitude: ' + stats[1]
string3 = 'Internal Temp: ' + stats[2]
string4 = 'External Temp: ' + stats[3]
string5 = 'Pressure: ' + stats[4]
string6 = 'Humidity: ' + stats[5]
string7 = 'UVA: ' + stats[6]
string8 = 'UVB: ' + stats[7]
string9 = 'Sound: ' + stats[8]
string10 = 'Co-ordinates: ' + stats[9] + ', ' + stats[10]
colour = (256,256,256)
top = 1200
draw.text((0, top),string1,colour,font=font)
draw.text((0, top+70),string2,colour,font=font)
draw.text((0, top+140),string3,colour,font=font)
draw.text((0, top+210),string4,colour,font=font)
draw.text((0, top+280),string5,colour,font=font)
draw.text((0, top+350),string6,colour,font=font)
draw.text((0, top+420),string7,colour,font=font)
draw.text((0, top+490),string8,colour,font=font)
draw.text((0, top+560),string9,colour,font=font)
draw.text((0, top+630),string10,colour,font=font)
img[0].save(str(hours) + '_' + str(img[1]) + '_' + str(img[2]) + '_with_data' + '.jpg')
def plot_all(x, xlabel):
#plots all graphs
plt.figure(1)
plt.subplot(211)
plt.plot(x,internal_temp)
plt.xlabel(xlabel)
plt.ylabel('Internal Temp / Celcius')
plt.subplot(212)
plt.plot(x,temp_bme)
plt.xlabel(xlabel)
plt.ylabel('Outside Temp / Celcius')
plt.figure(2)
plt.plot(x,pres)
plt.xlabel(xlabel)
plt.ylabel('Pressure / kPa')
#plt.ylim(100.5,100.9)
plt.figure(3)
plt.plot(x,hum)
plt.xlabel(xlabel)
plt.ylabel('Humidity / %')
plt.figure(4)
plt.plot(x,uva, 'r', label = 'UVA')
plt.plot(x,uvb, 'b', label= 'UVB')
plt.legend()
plt.xlabel(xlabel)
plt.ylabel('UVA')
plt.figure(5)
plt.plot(x,sound)
plt.xlabel(xlabel)
plt.ylabel('Speed of Sound / ms^-1')
plt.figure(6)
plt.plot(x,satellites)
plt.xlabel(xlabel)
plt.ylabel('Satellites')
plt.figure(7)
plt.plot(x,altitude)
plt.xlabel(xlabel)
plt.ylabel('Altitude')
plt.figure(8)
plt.plot(gps_long,gps_lat)
plt.xlabel('Long')
plt.ylabel('Lat')
plt.figure(9)
plt.plot(x,voltage)
plt.xlabel(xlabel)
plt.ylabel('Voltage')
plt.figure(10)
plt.plot(x,current)
plt.xlabel(xlabel)
plt.ylabel('Current')
uv_ratio = get_uv_ratio(uva,uvb)
plt.figure(11)
plt.plot(x,uv_ratio)
plt.xlabel(xlabel)
plt.ylabel('UVB/UVA')
def plot_all3d():
plot_3d(gps_lat,gps_long,altitude, 'Altitude')
plot_3d(gps_lat,gps_long,internal_temp, 'Internal Temp')
plot_3d(gps_lat,gps_long,temp_bme, 'External Temp')
plot_3d(gps_lat,gps_long,pres, 'Pressure')
plot_3d(gps_lat,gps_long,hum, 'Humidity')
plot_3d(gps_lat,gps_long,sound, 'Speed of Sound')
plot_3d(gps_lat,gps_long,uva, 'UVA')
plot_3d(gps_lat,gps_long,uvb, 'UVB')
def export_pins_google_earth(gps_lat,gps_long,altitude):
##exports points to kml so it can be seen on google earth
kml = simplekml.Kml()
for i in np.arange(len(gps_long)):
kml.newpoint(coords=[(gps_long[i],gps_lat[i],altitude[i])])
kml.save(path = "pins_hill.kml")
def export_lines_google_earth_alt(gps_lat,gps_long,altitude):
## exports as lines with an altitude to visualise the flight
kml = simplekml.Kml(open=1)
for i in np.arange(len(gps_long)-1):
linestring = kml.newlinestring(name="Balloon Path")
linestring.coords = [(gps_long[i],gps_lat[i],altitude[i]), (gps_long[i+1],gps_lat[i+1],altitude[i+1])]
linestring.altitudemode = simplekml.AltitudeMode.relativetoground
linstring.style.linestyle.color = 'ff0000ff'
linestring.extrude = 1
kml.save(path = "lines_alt_hill.kml")
def export_lines_google_earth(gps_lat,gps_long):
kml = simplekml.Kml(open=1)
for i in np.arange(len(gps_long)-1):
linestring = kml.newlinestring(name="Balloon Path")
linestring.coords = [(gps_long[i],gps_lat[i], 2), (gps_long[i+1],gps_lat[i+1],2)]
linestring.altitudemode = simplekml.AltitudeMode.relativetoground
linestring.style.linestyle.color = 'ff0000ff'
linestring.extrude = 1
kml.save(path = "lines_hill.kml")
fix_list(sound)
fixed_time_list = fix_time()
#print uva,uvb
#plot_variable(altitude[:351],pres[:351], 'Altitude', 'Pressure')
#sensor stopped working (loose SDA connection) so truncated the list
#plot_all(fixed_time_list, 'Time')
#plot_all(number, 'Time')
#plot_all3d()
#data_for_picture(18,04,57)
#export_lines_google_earth(gps_lat,gps_long, altitude)
#export_lines_google_earth(gps_lat,gps_long)
data_on_image(17,18,40)
plt.show()