Compare commits
3 commits
d43a5c4547
...
0c71eb0055
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c71eb0055 | |||
| 9340fd9aee | |||
| 42a2eef1f4 |
3 changed files with 62 additions and 19 deletions
|
|
@ -164,7 +164,7 @@ def main():
|
|||
#Data_preparation for altitude plot
|
||||
t, data = clear_data(t, altitude, args.uptime)
|
||||
if args.onset:
|
||||
onset_correction(t, data, 150)
|
||||
onset_correction(t, data, 300)
|
||||
|
||||
|
||||
fig = plt.figure()
|
||||
|
|
|
|||
|
|
@ -13,24 +13,55 @@ def layout(fig):
|
|||
fig.legend()
|
||||
plt.grid()
|
||||
|
||||
|
||||
def read_data(files, uptime):
|
||||
t = []
|
||||
data = []
|
||||
for fp in files:
|
||||
t.append(np.loadtxt(fp, usecols=(0),unpack=True,skiprows=7,dtype='str',delimiter=';'))
|
||||
for i in range(len(files)):
|
||||
if files[i][-3:] == 'csv':
|
||||
t.append(np.loadtxt(files[i], usecols=(0),unpack=True,skiprows=7,dtype='str',delimiter=';'))
|
||||
data.append(np.loadtxt(files[i], usecols=(7),unpack=True,skiprows=7,dtype='str',delimiter=';'))
|
||||
elif files[i][-3:] == 'LOG':
|
||||
t.append(np.loadtxt(files[i], usecols=(1),unpack=True,skiprows=3,dtype='str',delimiter=';'))
|
||||
data.append(np.loadtxt(files[i], usecols=(11),unpack=True,skiprows=3,dtype='str',delimiter=';'))
|
||||
return t, data
|
||||
|
||||
def time_to_seconds(time_str):
|
||||
hh, mm, ss = map(int, time_str.split(':'))
|
||||
return hh * 3600 + mm * 60 + ss
|
||||
|
||||
def clear_data(t, data, uptime):
|
||||
#Data preparation: cut-off everything before long time differences (before initialization of STRATO4)
|
||||
#print(t, data)
|
||||
for i in range(len(t)):
|
||||
t[i] = t[i].astype(float)
|
||||
for string in data[i]:
|
||||
if string == "Inval.":
|
||||
t[i] = t[i][1:]
|
||||
data[i] = data[i][1:]
|
||||
#print(t[i])
|
||||
for j in range(len(t[i])):
|
||||
try:
|
||||
#time = datetime.datetime.strptime(t[i][j], "%H:%M:%S")
|
||||
#t[i][j] = int(time.hour * 3600 + time.minute * 60 + time.second)
|
||||
t[i][j] = time_to_seconds(t[i][j])
|
||||
except:
|
||||
t[i][j] = float(t[i][j])
|
||||
#for string in data[i]:
|
||||
# if string == "Inval.":
|
||||
# t[i] = t[i][1:]
|
||||
# for j in range(len(data[i])):
|
||||
# data[i] = data[i][1:]
|
||||
#data[i] = data[i][1:]
|
||||
k = 0
|
||||
while k < len(data[i]):
|
||||
#for k in range(len(data[i][j]))
|
||||
if data[i][k] == "Err" or data[i][k] == 'NA' or data[i][k] == "Inval.":
|
||||
#print(data[i][j][k])
|
||||
data[i] = np.delete(data[i], k)
|
||||
t[i] = np.delete(t[i], k)
|
||||
else:
|
||||
k+=1
|
||||
data[i] = data[i].astype(float)
|
||||
#print(data[i][j])
|
||||
#else:
|
||||
# altitude_float.append(float(string))
|
||||
t[i] = t[i].astype(float)
|
||||
return t, data
|
||||
|
||||
|
||||
|
|
@ -39,7 +70,7 @@ def plot_data(t, data, altitude, speed, temperature, ax):
|
|||
cmap = plt.get_cmap("viridis")
|
||||
if altitude:
|
||||
for i in range(len(t)):
|
||||
ax.plot(t[i][::50],data[i][0][::50], '--', color=cmap(i/len(t)),label="Altitude "+str(i))
|
||||
ax.plot(t[i][::50],data[i][::50], '--', color=cmap(i/len(t)),label="Altitude "+str(i))
|
||||
ax.set_xlabel("Time/s")
|
||||
ax.set_ylabel("Altitude/m", color='r')
|
||||
ax.tick_params(axis='y', labelcolor='r')
|
||||
|
|
@ -59,6 +90,7 @@ def onset_correction(t, data, thresh):
|
|||
for i in range(len(t)):
|
||||
start=0
|
||||
start_found = False
|
||||
print(data[i])
|
||||
while not start_found:
|
||||
if data[i][start] > thresh:
|
||||
start_found = True
|
||||
|
|
@ -74,17 +106,27 @@ def onset_correction(t, data, thresh):
|
|||
t0 = -b/a
|
||||
for j in range(len(t[i])):
|
||||
t[i][j]-=t0
|
||||
print(t[i])
|
||||
|
||||
def index_of_first_positive(lst):
|
||||
return next((i for i, x in enumerate(lst) if x > 0), -1)
|
||||
|
||||
#Mean function to compute mean altitude from various flights: current problem: flights have different durations
|
||||
def mean(data):
|
||||
def mean(data, t):
|
||||
offset = []
|
||||
for i in range(len(data)):
|
||||
offset.append(np.argmax(t[i]>0))
|
||||
length = []
|
||||
for part in data:
|
||||
length.append(len(part))
|
||||
mean = []
|
||||
for i in range(min(length)):
|
||||
min_run = []
|
||||
for i in range(len(data)):
|
||||
min_run.append(length[i]-offset[i])
|
||||
for i in range(min(min_run)):
|
||||
sum = 0
|
||||
for j in range(len(data)):
|
||||
sum += data[j][i]
|
||||
sum += data[j][i+offset[j]]
|
||||
mean.append(sum/len(data))
|
||||
return mean
|
||||
|
||||
|
|
@ -109,7 +151,7 @@ def main():
|
|||
|
||||
#Data_preparation for altitude plot
|
||||
t, data = clear_data(t, altitude, args.uptime)
|
||||
if args.onset:
|
||||
#if args.onset:
|
||||
onset_correction(t, data, 150)
|
||||
|
||||
|
||||
|
|
@ -118,8 +160,9 @@ def main():
|
|||
ax.set_xlabel("Time/s")
|
||||
ax.set_ylabel("Altitude/m")
|
||||
plot_data(t, data, args.altitude, args.speed, args.temperature, ax)
|
||||
mean_data = mean(data)
|
||||
plot_mean(t[0], mean_data, ax)
|
||||
mean_data = mean(data, t)
|
||||
min_idx = min(enumerate(t), key=lambda x: len(x[1]))[0]
|
||||
plot_mean(t[2], mean_data, ax)
|
||||
#plt.gcf().autofmt_xdate()
|
||||
|
||||
layout(fig)
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ def onset_correction(t, data, thresh):
|
|||
start=0
|
||||
start_found = False
|
||||
while not start_found:
|
||||
if data[i][start] > thresh:
|
||||
if data[i][0][start] > thresh:
|
||||
start_found = True
|
||||
else:
|
||||
start+=1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue