Compare commits
No commits in common. "0c71eb0055377be485adc319f396b58b55d7a84f" and "d43a5c4547aaccd27744f8eca0321830d377bec2" have entirely different histories.
0c71eb0055
...
d43a5c4547
3 changed files with 19 additions and 62 deletions
|
|
@ -164,7 +164,7 @@ def main():
|
||||||
#Data_preparation for altitude plot
|
#Data_preparation for altitude plot
|
||||||
t, data = clear_data(t, altitude, args.uptime)
|
t, data = clear_data(t, altitude, args.uptime)
|
||||||
if args.onset:
|
if args.onset:
|
||||||
onset_correction(t, data, 300)
|
onset_correction(t, data, 150)
|
||||||
|
|
||||||
|
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
|
|
|
||||||
|
|
@ -13,55 +13,24 @@ def layout(fig):
|
||||||
fig.legend()
|
fig.legend()
|
||||||
plt.grid()
|
plt.grid()
|
||||||
|
|
||||||
|
|
||||||
def read_data(files, uptime):
|
def read_data(files, uptime):
|
||||||
t = []
|
t = []
|
||||||
data = []
|
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)):
|
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=';'))
|
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
|
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):
|
def clear_data(t, data, uptime):
|
||||||
#Data preparation: cut-off everything before long time differences (before initialization of STRATO4)
|
#Data preparation: cut-off everything before long time differences (before initialization of STRATO4)
|
||||||
#print(t, data)
|
|
||||||
for i in range(len(t)):
|
for i in range(len(t)):
|
||||||
#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)
|
t[i] = t[i].astype(float)
|
||||||
|
for string in data[i]:
|
||||||
|
if string == "Inval.":
|
||||||
|
t[i] = t[i][1:]
|
||||||
|
data[i] = data[i][1:]
|
||||||
|
data[i] = data[i].astype(float)
|
||||||
return t, data
|
return t, data
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,7 +39,7 @@ def plot_data(t, data, altitude, speed, temperature, ax):
|
||||||
cmap = plt.get_cmap("viridis")
|
cmap = plt.get_cmap("viridis")
|
||||||
if altitude:
|
if altitude:
|
||||||
for i in range(len(t)):
|
for i in range(len(t)):
|
||||||
ax.plot(t[i][::50],data[i][::50], '--', color=cmap(i/len(t)),label="Altitude "+str(i))
|
ax.plot(t[i][::50],data[i][0][::50], '--', color=cmap(i/len(t)),label="Altitude "+str(i))
|
||||||
ax.set_xlabel("Time/s")
|
ax.set_xlabel("Time/s")
|
||||||
ax.set_ylabel("Altitude/m", color='r')
|
ax.set_ylabel("Altitude/m", color='r')
|
||||||
ax.tick_params(axis='y', labelcolor='r')
|
ax.tick_params(axis='y', labelcolor='r')
|
||||||
|
|
@ -90,7 +59,6 @@ def onset_correction(t, data, thresh):
|
||||||
for i in range(len(t)):
|
for i in range(len(t)):
|
||||||
start=0
|
start=0
|
||||||
start_found = False
|
start_found = False
|
||||||
print(data[i])
|
|
||||||
while not start_found:
|
while not start_found:
|
||||||
if data[i][start] > thresh:
|
if data[i][start] > thresh:
|
||||||
start_found = True
|
start_found = True
|
||||||
|
|
@ -106,27 +74,17 @@ def onset_correction(t, data, thresh):
|
||||||
t0 = -b/a
|
t0 = -b/a
|
||||||
for j in range(len(t[i])):
|
for j in range(len(t[i])):
|
||||||
t[i][j]-=t0
|
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
|
#Mean function to compute mean altitude from various flights: current problem: flights have different durations
|
||||||
def mean(data, t):
|
def mean(data):
|
||||||
offset = []
|
|
||||||
for i in range(len(data)):
|
|
||||||
offset.append(np.argmax(t[i]>0))
|
|
||||||
length = []
|
length = []
|
||||||
for part in data:
|
for part in data:
|
||||||
length.append(len(part))
|
length.append(len(part))
|
||||||
mean = []
|
mean = []
|
||||||
min_run = []
|
for i in range(min(length)):
|
||||||
for i in range(len(data)):
|
|
||||||
min_run.append(length[i]-offset[i])
|
|
||||||
for i in range(min(min_run)):
|
|
||||||
sum = 0
|
sum = 0
|
||||||
for j in range(len(data)):
|
for j in range(len(data)):
|
||||||
sum += data[j][i+offset[j]]
|
sum += data[j][i]
|
||||||
mean.append(sum/len(data))
|
mean.append(sum/len(data))
|
||||||
return mean
|
return mean
|
||||||
|
|
||||||
|
|
@ -151,7 +109,7 @@ def main():
|
||||||
|
|
||||||
#Data_preparation for altitude plot
|
#Data_preparation for altitude plot
|
||||||
t, data = clear_data(t, altitude, args.uptime)
|
t, data = clear_data(t, altitude, args.uptime)
|
||||||
#if args.onset:
|
if args.onset:
|
||||||
onset_correction(t, data, 150)
|
onset_correction(t, data, 150)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -160,9 +118,8 @@ def main():
|
||||||
ax.set_xlabel("Time/s")
|
ax.set_xlabel("Time/s")
|
||||||
ax.set_ylabel("Altitude/m")
|
ax.set_ylabel("Altitude/m")
|
||||||
plot_data(t, data, args.altitude, args.speed, args.temperature, ax)
|
plot_data(t, data, args.altitude, args.speed, args.temperature, ax)
|
||||||
mean_data = mean(data, t)
|
mean_data = mean(data)
|
||||||
min_idx = min(enumerate(t), key=lambda x: len(x[1]))[0]
|
plot_mean(t[0], mean_data, ax)
|
||||||
plot_mean(t[2], mean_data, ax)
|
|
||||||
#plt.gcf().autofmt_xdate()
|
#plt.gcf().autofmt_xdate()
|
||||||
|
|
||||||
layout(fig)
|
layout(fig)
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ def onset_correction(t, data, thresh):
|
||||||
start=0
|
start=0
|
||||||
start_found = False
|
start_found = False
|
||||||
while not start_found:
|
while not start_found:
|
||||||
if data[i][0][start] > thresh:
|
if data[i][start] > thresh:
|
||||||
start_found = True
|
start_found = True
|
||||||
else:
|
else:
|
||||||
start+=1
|
start+=1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue