From 31cb99ec0cd22e4e474f789027f44bc8d741094d Mon Sep 17 00:00:00 2001 From: Danila Gamkov Date: Fri, 25 Apr 2025 12:33:44 +0300 Subject: [PATCH] correct find_best_time_interval function. Create Readme --- README.markdown | 68 ++++++++++++++++++++++++++++++++++++++++++ asotr.py | 16 ++++++---- plot_flight_borders.py | 34 +++++++++++++-------- temp_peaks_forecast.py | 14 ++++----- 4 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 README.markdown diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..b87de52 --- /dev/null +++ b/README.markdown @@ -0,0 +1,68 @@ +# asotr_flight + +The asotr_flight python scripts is designed to analyze ASOTR flight data + +## Contents + +- **Setup** +- **Using** +- Plot ASOTR data in specified date borders (for MVN reports) +- **Contacts** + +**Note**: \ - path where is asotr_flight scripts is cloned from heagit +**Note**: \ - path where is asotr_csv program is cloned from heagit + +## Setup +1. Install python 3.10 or newest. + +2. Clone the repo to your computer: +``` +git clone http://heagit.cosmos.ru/gamkov/asotr_flight.git +``` + +3. Enter the repo: +``` +cd +``` + +## Using +### Plot ASOTR data in specified date borders (for MVN reports) +1. Donwload data from science data server to directory \. +If you don't have MVN data, you might download it from server with science SRG data (IP: 193.232.11.95). +For questions about downloading science data contact Shtykovsky A. (a.shtykovsky@cosmos.ru) or Chelovekov I. (chelovekov@cosmos.ru) + +2. Parse all raw data from ASOTR into csv files and plot all csv data: +``` +cd +./asotr_all_unzip_auto.sh / +``` +csv data will be in directory: +``` +/data/ +``` + +3. plot ASOTR data in specified data borders +You might plot data by using shell-script (for MVN reports), for example: +``` +cd +./plot_flight_borders.sh / 10.03.2025 23.04.2025 14 0 +``` +where: +10.03.2025 - start date +23.04.2025 - end date +14 - font size for plot +0 - display commands flag (not display) + +Or you might plot data by using python script directly, for example: +``` +cd +python3 plot_flight_borders.py -s -c 100000 -a 01 -b 10.03.2025 -e 15.03.2025 -f 14 -d 0 -p 0 +``` + +Graphs with data are in the directory: +``` +/reports +``` + +## Contatcs +For questions about the program, please contact Danila Gamkov, email: danila_gamkov@cosmos.ru diff --git a/asotr.py b/asotr.py index 8eb8959..fce7cfb 100644 --- a/asotr.py +++ b/asotr.py @@ -146,12 +146,12 @@ def find_best_time_idx(time_arr, user_time, accuracy='minutes') -> int: elif accuracy == 'seconds': delta = timedelta(seconds=30) - low = 0 - high = len(time_arr) - 1 - mid = len(time_arr) // 2 + low = time_arr.idxmin() + high = time_arr.idxmax() + mid = time_arr.idxmin() + (time_arr.idxmax() - time_arr.idxmin()) // 2 if mid not in time_arr.index: - # print(f'mid not in time_arr: {mid}') + # print(f'mid not in time_arr: {mid}, {time_arr.index}, {time_arr.idxmin()}') return -1 a = time_arr[mid] @@ -160,7 +160,7 @@ def find_best_time_idx(time_arr, user_time, accuracy='minutes') -> int: low = mid + 1 else: high = mid - 1 - mid = (low + high) // 2 + mid = low + (high - low) // 2 # print(f'mid: (low + high)/2: {mid}') if mid not in time_arr.index: @@ -186,8 +186,14 @@ def find_best_time_idx(time_arr, user_time, accuracy='minutes') -> int: # print(f'{time_arr[j]} > {tstamp}: {j}') return j + if mid <= low + 1 or mid >= high - 1: + return -1 + return mid +class TimeIndexNotFound(Exception): + pass + def find_time_idx(data_list, keys_list, timestamp, accuracy): out_dict = dict.fromkeys(keys_list, -1) diff --git a/plot_flight_borders.py b/plot_flight_borders.py index 5a42998..b36e237 100644 --- a/plot_flight_borders.py +++ b/plot_flight_borders.py @@ -16,7 +16,7 @@ def convert_to_str(lst): res += f"_{idx + 1}" return res -def plot_asotr_borders(path_with_data, ch, asotr_kit, begin, end, font=14, cmd=0, show_flag=False): +def plot_asotr_borders(path_with_data, ch, asotr_kit, begin, end, font=14, cmd=0, show_flag=True): print_width = 20 print_height = 12 width = 1 @@ -74,7 +74,8 @@ def plot_asotr_borders(path_with_data, ch, asotr_kit, begin, end, font=14, cmd=0 plt.tight_layout() fig.savefig(pict_name) - plt.show() + if show_flag == True: + plt.show() elif plot_windows == 2: @@ -85,22 +86,29 @@ def plot_asotr_borders(path_with_data, ch, asotr_kit, begin, end, font=14, cmd=0 if cmd == '1': fname = './flight_cmd_human.txt' try: - cmd_human = pd.read_csv('./flight_cmd_human.txt', + cmd_human = pd.read_csv('./data/cmd_human.csv', delimiter=';', names=['timestamp', 'cmd']) except Exception as e: print(f'Error parsing file: {e}') return + max_temp = max(data_dict['temp'].iloc[:,1]) + min_temp = min(data_dict['temp'].iloc[:,1]) + # print(cmd_human) + step = 0 for i, row in cmd_human.iterrows(): - if i > 20: - row_time = row['timestamp'][0:len(row['timestamp']) - 4] - idx = asotr.find_best_time_idx(data_dict['time_temp'], - row_time, accuracy='minutes') - if idx != -1: - ax1.axvline(x = data_dict['time_temp'][idx], color='r', - linestyle='-.') - ax1.text(data_dict['time_temp'][idx], 30, row['cmd'], - rotation=45, va='bottom', fontsize=font) + row_time = row['timestamp'][0:len(row['timestamp']) - 4] + # print(row_time) + idx = asotr.find_best_time_idx(data_dict['time_temp'], + row_time, accuracy='minutes') + + # print(idx) + if idx != -1: + ax1.axvline(x = data_dict['time_temp'][idx], color='r', + linestyle='-.') + ax1.text(data_dict['time_temp'][idx], max_temp - step, row['cmd'], + rotation=45, va='bottom', fontsize=font) + step += (max_temp - min_temp)/20 if plot_task["temp"] == 1: for i in range(len(channels)): @@ -176,6 +184,6 @@ if __name__ == '__main__': argparser.add_argument('-p', '--plot', required=False, help='display data in plot flag (0/1)') args = argparser.parse_args() - + plot_asotr_borders(args.source, args.channel, args.asotr, args.begin, args.end, args.font, args.cmd, args.plot) diff --git a/temp_peaks_forecast.py b/temp_peaks_forecast.py index d0f0ab1..c43ea6f 100644 --- a/temp_peaks_forecast.py +++ b/temp_peaks_forecast.py @@ -12,19 +12,19 @@ from datetime import timedelta path = '/home/danila/Danila/work/MVN/Soft/asotr_csv/data/' channel = 'ch1' asotr_kit = '01' -start_date = '23.04.2025 00:00:00' +start_date = '22.04.2025 00:00:00' +end_date = '23.04.2025 01:20:00' forecast_days = 20 -# end_date = '26.03.2025 01:20:00' + timeformat = '%d.%m.%Y %H:%M:%S' -delta_date = datetime.strptime(start_date, timeformat) + timedelta(days=forecast_days) -end_date = delta_date.strftime(timeformat) num_peaks_forecast = forecast_days * 20 -# start_date = '06.01.2025 22:40:00' -# end_date = '21.01.2025 01:20:00' shift = True -raw_data, data_dict = asotr.get_data(path, asotr_kit, start_date, end_date, 'minutes') +try: + raw_data, data_dict = asotr.get_data(path, asotr_kit, start_date, end_date, 'minutes') +except Exception as e: + sys.exit() data1 = data_dict['temp'][channel] time1 = data_dict['time_temp']