plot_flight_borders: add flags for flexibility. tm_wheel_parser.py: plot data distribution

This commit is contained in:
Danila Gamkov
2025-08-07 14:13:43 +03:00
parent cf3c9290b0
commit d91039ca21
12 changed files with 820 additions and 202 deletions

View File

@@ -3,13 +3,18 @@ import os
import re
from pathlib import Path
import matplotlib.pyplot as plt
from matplotlib import dates
from datetime import datetime, timedelta
import sys
import seaborn as sns
tstamp_s = '%d.%m.%Y %H:%M:%S.%f'
ox_dtime_format = '%d.%m.%Y %H:%M'
ox_dtime_format = '%H:%M'
ox_date_format = '%d.%m.%Y'
path_itog_brd_data = '../data/brd_data/'
pict_name = '../plots/' + 'MVN_wheel'
font = 16
class PathFileNotFound(Exception):
@@ -92,23 +97,64 @@ if __name__ == "__main__":
column_list = ['TIME', 'STATE']
column_list_itog = ['TIME', 'timestamp', 'STATE']
collect_tm_brd_wheel_data(root_dir_wheel_data, column_list, column_list_itog)
# collect_tm_brd_wheel_data(root_dir_wheel_data, column_list, column_list_itog)
## parse and plot wheel csv data
print('parse and plot wheel csv data')
border_clr_wheel = 2
border_clr_wheel = 1
fname = path_itog_brd_data + 'mvn_wheel_brd01.csv'
wheel_df = pd.read_csv(fname, sep=';')
wheel_df = pd.read_csv(fname, sep=';', parse_dates=['timestamp'], date_format="%d.%m.%Y %H:%M:%S.%f")
## diff between 0 and 0 - 30 sec
wheel_df['TIME_diff'] = wheel_df['TIME'].diff()
median_tdiff = wheel_df['TIME_diff'].median()
wheel_df_clear = wheel_df[(wheel_df['TIME_diff'] > median_tdiff - border_clr_wheel) &
(wheel_df['TIME_diff'] < median_tdiff + border_clr_wheel)]
## sampling decimation in order to get period 60 sec
wheel_df = wheel_df.iloc[1::2]
wheel_df['TIME_period'] = wheel_df['TIME'].diff()
# print(wheel_df)
median_tdiff = wheel_df['TIME_period'].median()
# print(median_tdiff)
wheel_df_peaks = wheel_df[(wheel_df['TIME_diff'] <= median_tdiff - border_clr_wheel) |
(wheel_df['TIME_diff'] >= median_tdiff + border_clr_wheel)]
## discard outliers of the measured wheel period
wheel_df = wheel_df[
(wheel_df['TIME_period'] > median_tdiff - border_clr_wheel) &
(wheel_df['TIME_period'] < median_tdiff + border_clr_wheel)]
median = wheel_df['TIME_period'].median()
rows, cols = wheel_df.shape
median = pd.Series([median] * rows)
date_format = dates.DateFormatter(ox_date_format)
datetime_format = dates.DateFormatter(ox_dtime_format)
fig, axes = plt.subplots(3, 1, figsize=(18, 20), dpi=300, height_ratios=[1, 1, 1])
axes[0].plot(wheel_df['timestamp'], wheel_df['TIME_period'], '.',
markersize=5)
axes[0].plot(wheel_df['timestamp'], median)
axes[0].set_title("")
axes[0].set_xlabel("Время (ДД.MM.ГГГГ)", fontsize=font)
axes[0].set_ylabel("Полупериод, сек", fontsize=font)
axes[0].grid(True)
axes[0].xaxis.set_major_formatter(date_format)
axes[0].tick_params(axis="both", width=1, labelsize=font)
axes[1].plot(wheel_df['timestamp'][0:400], wheel_df['TIME_period'][0:400], '.', markersize=10)
axes[1].set_title("")
axes[1].set_xlabel("Время (ЧЧ:ММ)", fontsize=font)
axes[1].set_ylabel("Полупериод, сек", fontsize=font)
axes[1].grid(True)
axes[1].xaxis.set_major_formatter(datetime_format)
axes[1].tick_params(axis="both", width=1, labelsize=font)
sns.histplot(wheel_df['TIME_period'], kde=False, bins=300, ax=axes[2], color='red')
axes[2].set_title("")
axes[2].set_xlabel("Полупериод, сек", fontsize=font)
axes[2].set_ylabel("Частота встречаемости", fontsize=font)
axes[2].grid(True)
axes[2].tick_params(axis="both", width=1, labelsize=font)
fig.savefig(pict_name)
plt.plot(wheel_df_clear['TIME'], wheel_df_clear['TIME_diff'], '-')
plt.plot(wheel_df_peaks['TIME'], wheel_df_peaks['TIME_diff'], '.')
plt.show()