From d8eed0615f7346324ed5c9a460f28b393e7ac091 Mon Sep 17 00:00:00 2001 From: Constantin Date: Wed, 22 Apr 2026 17:46:14 +0200 Subject: [PATCH 1/2] mean pressure script for STRATO 3 and 4 --- Skripte/STRATO_pressure.py | 202 +++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 Skripte/STRATO_pressure.py diff --git a/Skripte/STRATO_pressure.py b/Skripte/STRATO_pressure.py new file mode 100644 index 0000000..99a5043 --- /dev/null +++ b/Skripte/STRATO_pressure.py @@ -0,0 +1,202 @@ +import matplotlib.pyplot as plt +import matplotlib.cm as cm +import numpy as np +import scipy.optimize as opt +from numpy import random as rd +import scipy.optimize as opt +import datetime +import argparse +import math + + + +def layout(fig): + plt.title("Mean Speed") + plt.locator_params(axis='x', nbins=10) + fig.legend() + plt.grid() + + +#Reads Time and Altitude columns from log files from Strato3 (.LOG) and Strato4 (.csv) files. Returns List of numpy arrays for time and List of lists of numpy arrays for altitude and speed +def read_data_strato(files): + t = [] + data = [] + 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([]) + data[i].append(np.loadtxt(files[i], usecols=(7),unpack=True,skiprows=7,dtype='str',delimiter=';')) + data[i].append(np.loadtxt(files[i], usecols=(14),unpack=True,skiprows=7,dtype='str',delimiter=';')) + elif files[i][-3:] == 'LOG': + t.append(np.loadtxt(files[i], usecols=(1),unpack=True,skiprows=7,dtype='str',delimiter=';')) + data.append([]) + data[i].append(np.loadtxt(files[i], usecols=(11),unpack=True,skiprows=7,dtype='str',delimiter=';')) + data[i].append(np.loadtxt(files[i], usecols=(15),unpack=True,skiprows=7,dtype='str',delimiter=';')) + return t, data + + +def clear_data(t, data): + #Data preparation: cut-off everything before long time differences (before initialization of STRATO3/4) and remove lines with Invalid entries + for i in range(len(t)): + for j in range(len(t[i])): + try: + t[i][j] = time_to_seconds(t[i][j]) + except: + t[i][j] = float(t[i][j]) + for string in data[i][0]: + if string == "Inval.": + t[i] = t[i][1:] + for j in range(len(data[i])): + data[i][j] = data[i][j][1:] + for j in range(len(data[i])): + k = 0 + while k < len(data[i][j]): + if data[i][j][k] == "Err" or data[i][j][k] == 'NA': + for m in range(len(data[i])): + data[i][m] = np.delete(data[i][m], k) + t[i] = np.delete(t[i], k) + else: + k+=1 + for j in range(len(data[i])): + data[i][j] = data[i][j].astype(float) + t[i] = t[i].astype(float) + return t, data + +def time_to_seconds(time_str): + hh, mm, ss = map(int, time_str.split(':')) + return hh * 3600 + mm * 60 + ss + + +#Legacy plot function (currently not in use in this script) +def plot_data(t, data, altitude, speed, temperature, ax): + colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] + 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.set_xlabel("Time/s") + ax.set_ylabel("Altitude/m", color='r') + ax.tick_params(axis='y', labelcolor='r') + ax2 = ax.twinx() + if speed: + for i in range(len(t)): + ax2.plot(t[i],data[i][1], color=cmap(i/len(t)),label="Speed "+str(i)) + ax2.set_ylabel("Speed/km/h", color='b') + ax2.tick_params(axis='y', labelcolor='b') + elif temperature: + for i in range(len(t)): + ax2.plot(t[i],data[i][2], color=cmap(i/len(t)),label="Temperature "+str(i)) + ax2.set_ylabel("Temperature/(°C)", color='b') + ax2.tick_params(axis='y', labelcolor='b') + + +def f(x,a,b): + return a*x+b + +#function to correct time to set release time to 0s +def onset_correction(t, data, thresh): + for i in range(len(t)): + start=0 + start_found = False + while not start_found and start thresh: + start_found = True + else: + start+=1 + end = np.argmax(data[i][0]) + end = min(start+500,end) + popt,pcov=opt.curve_fit(f,t[i][start:end],data[i][0][start:end]) + a,b=popt + t0 = -b/a + t[i] = t[i].astype(float) + for j in range(len(t[i])): + t[i][j]-=t0 + + +def find_max_altitude(data): + max_val = 0 + for altitude_set in [data_set[0] for data_set in data]: + if max(altitude_set) > max_val: + max_val = max(altitude_set) + return max_val + +def find_min_altitude(data): + min_val = 0 + for altitude_set in [data_set[0] for data_set in data]: + if min(altitude_set) < min_val: + min_val = min(altitude_set) + return min_val + +#computes mean speeds for each histogram bin and finds respective maximum and minimum speeds +def mean_speed_alt(data, bin_width): + begin = find_min_altitude(data) + end = find_max_altitude(data) + bin_val = np.zeros((len(data), math.ceil((end-begin)/bin_width))) + max_arr = np.zeros(math.ceil((end-begin)/bin_width)) + min_arr = np.zeros(math.ceil((end-begin)/bin_width)) + max_arr = np.full(math.ceil((end-begin)/bin_width), -np.inf) + min_arr = np.full(math.ceil((end-begin)/bin_width), np.inf) + alti_arr = np.zeros(math.ceil((end-begin)/bin_width)) + for i in range(len(alti_arr)): + alti_arr[i] = i*bin_width + for i in range(len(data)): + begin_loc = min(data[i][0]) + bin_sum = np.zeros(math.ceil((end-begin)/bin_width)) + count_arr = np.zeros(math.ceil((end-begin)/bin_width), dtype=int) + for j in range(len(data[i][0])): + bin_sum[int((data[i][0][j]-begin_loc)//bin_width)] += data[i][1][j] + if data[i][1][j]>max_arr[int((data[i][0][j]-begin_loc)//bin_width)]: + max_arr[int((data[i][0][j]-begin_loc)//bin_width)] = data[i][1][j] + if data[i][1][j] Date: Wed, 22 Apr 2026 17:46:42 +0200 Subject: [PATCH 2/2] modified title --- Skripte/STRATO_coordinates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Skripte/STRATO_coordinates.py b/Skripte/STRATO_coordinates.py index 9f03389..f42fed9 100644 --- a/Skripte/STRATO_coordinates.py +++ b/Skripte/STRATO_coordinates.py @@ -9,7 +9,7 @@ import re def layout(fig): - plt.title("STRATO3 Altitude Plot") + plt.title("Flightpath with unified starting point") plt.locator_params(axis='x', nbins=10) fig.legend() plt.grid()