asotr_csv/data/plot_flight_all.py
2025-04-24 19:09:07 +03:00

146 lines
4.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import matplotlib.pyplot as plt
from matplotlib import dates
import pandas as pd
from datetime import datetime
import sys
font = 4
print_width = 6
print_height = 4
width = 1
plot_windows = 2
channels = [0, 0, 1, 0, 0, 1]
asotr_kit = '01'
xborders=False
begin=0;
end=0;
path_B = '/home/danila/Danila/work/MVN/flight/beta_forecast/'
fname_B = 'beta_2025.xlsx'
path = '/home/danila/Danila/work/MVN/Soft/asotr_csv/data/'
fname = 'asotr' + asotr_kit + '_data_T.csv'
fname_pow = 'asotr' + asotr_kit + '_data_P.csv'
pict_name = path + 'ASOTR' + asotr_kit + '_flight_T_P_all'
ox_dtime_format = '%d.%m %H:%M:%S'
legend=['БРД1', 'БРД2', 'БРД3', 'БРД4', 'плита МУП МВН, датчик1', 'плита МУП МВН, датчик 2']
width=[1, 1, 1, 1, 1, 1]
marker = ['-', '-', '-', '-', '--', '-'];
width_arr = [1, 0.5, 0.2, 0.1, 1, 1]
fname = [path + fname, path + fname_pow]
fname_b = path_B + fname_B
dateparse = lambda x: datetime.strptime(x, "%d.%m.%Y %H:%M:%S.%f")
dparse_b = lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
data_b = pd.read_excel(fname_b,
sheet_name=0,
usecols=[0,1,2],
header=4,
names=['turn_num', 'beta_angle', 'timestamp'],
parse_dates=['timestamp'],
date_parser=dparse_b)
data = [pd.read_csv(fname[0], sep=';', parse_dates=['timestamp'], date_parser=dateparse),
pd.read_csv(fname[1], sep=';', parse_dates=['timestamp'], date_parser=dateparse)]
ch= [[], [], [], [], [], []]
ch_signs = ["temp", "pow"]
data_dict = {"temp": ch, "pow": ch, "time": []}
data_dict["time"] = data[0]['timestamp']
col=['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7']
for j in range(2):
for index, row, in data[j].iterrows():
for i in range(6):
ch[i].append(float(row[col[i]]))
data_dict[ch_signs[j]] = ch
ch= [[], [], [], [], [], []]
len_data = [len(data_dict['temp'][0]), len(data_dict['pow'][0])]
len_ = min(len_data)
if xborders == False:
begin = 0
end = len_ - 1
if plot_windows == 1:
fig, ax = plt.subplots(figsize=(print_width, print_height), dpi=200)
i = 0
for elem in data_dict['temp']:
if channels[i] == 1:
ax.plot(data_dict['time'][begin:end], elem[begin:end], marker[i], linewidth=width[i], label=legend[i])
i += 1
# ax.axvline(x = data['timestamp'][300], color='r', linestyle='-.', label="power=100")
# ax.axvline(x = data['timestamp'][1500], color='b', linestyle='dotted', label="power=0")
ax.tick_params(axis="both", width=1, labelsize=font)
ax.grid(visible=True, linestyle = 'dotted')
ax.set_ylabel('Температура, $^\circ$C', fontsize=font)
ax.set_xlabel('Время', fontsize=font)
ax.legend(fontsize=font)
date_formatter = dates.DateFormatter(ox_dtime_format)
ax.xaxis.set_major_formatter(date_formatter)
plt.tight_layout()
fig.savefig(pict_name)
plt.show()
elif plot_windows == 2:
fig = plt.figure(figsize=(print_width, print_height), dpi=200)
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
i = 0
for elem in data_dict['temp']:
if channels[i] == 1:
ax1.plot(data_dict['time'][begin:end], elem[begin:end], marker[i], linewidth=width[i], label=legend[i])
i += 1
ax3 = ax1.twinx()
ax3.plot(data_b['timestamp'], data_b['beta_angle'], marker[4], color='r', linewidth=width[5], label='угол Бета')
ax3.set_ylabel('Угол Бета', fontsize=font)
ax3.tick_params(axis="y", width=1, labelsize=font)
ax3.legend(fontsize=font, loc='upper right')
i = 0
for elem in data_dict['pow']:
if channels[i] == 1:
ax2.plot(data_dict['time'][begin:end], elem[begin:end], marker[i], linewidth=width[i], label=legend[i])
i += 1
# ax1.axvline(x = data['timestamp'][300], color='r', linestyle='-.', label="power=100")
# ax.axvline(x = data['timestamp'][1500], color='b', linestyle='dotted', label="power=0")
ax1.tick_params(axis="both", width=1, labelsize=font)
ax1.grid(visible=True, linestyle = 'dotted')
ax1.set_ylabel('Температура, $^\circ$C', fontsize=font)
ax1.set_xlabel('Время', fontsize=font)
ax1.legend(fontsize=font, loc='lower right')
date_formatter = dates.DateFormatter(ox_dtime_format)
ax1.xaxis.set_major_formatter(date_formatter)
ax2.tick_params(axis="both", width=1, labelsize=font)
ax2.grid(visible=True, linestyle = 'dotted')
ax2.set_ylabel('Мощность, %', fontsize=font)
ax2.set_xlabel('Время', fontsize=font)
ax2.legend(fontsize=font, loc='lower right')
date_formatter = dates.DateFormatter(ox_dtime_format)
ax2.xaxis.set_major_formatter(date_formatter)
plt.title('АСОТР ' + asotr_kit, fontsize=font)
plt.tight_layout()
fig.savefig(pict_name)
plt.show()