From 27a24ba6a8926a8a7b95ef4f04056ae595955d05 Mon Sep 17 00:00:00 2001 From: Dustella Date: Fri, 21 Feb 2025 00:53:48 +0800 Subject: [PATCH] some fix --- modules/cosmic/__init__.py | 5 ++-- modules/cosmic/planetw_daily.py | 41 ++++++++++++++++++--------------- modules/saber/__init__.py | 5 +++- modules/saber/planetw_plot.py | 39 ++++++++++++++++--------------- 4 files changed, 50 insertions(+), 40 deletions(-) diff --git a/modules/cosmic/__init__.py b/modules/cosmic/__init__.py index 0082169..cb8965a 100644 --- a/modules/cosmic/__init__.py +++ b/modules/cosmic/__init__.py @@ -20,7 +20,8 @@ def get_meta(): @cosmic_module.route('/temp_render') async def render(): T = request.args.get("T", 16) - await run_sync(cosmic_planetw_daily_plot)(T=int(T)) + k = request.args.get("k", 1) + await run_sync(cosmic_planetw_daily_plot)(T=int(T), k=int(k)) buf = BytesIO() plt.savefig(buf, format="png") @@ -61,7 +62,7 @@ async def multiday_render(): day_range=(start_day, end_day)) if mode == "布伦特-维萨拉频率分布": await run_sync(p.plot_heatmap_tempNz)() - elif mode == "位温分布": + elif mode == "不同高度下的逐日统计分析": await run_sync(p.plot_heatmap_tempPtz)() elif mode == "每月浮力频率变化趋势": await run_sync(p.plot_floatage_trend)() diff --git a/modules/cosmic/planetw_daily.py b/modules/cosmic/planetw_daily.py index c4eb349..476a9b1 100644 --- a/modules/cosmic/planetw_daily.py +++ b/modules/cosmic/planetw_daily.py @@ -17,7 +17,11 @@ matplotlib.rcParams['axes.unicode_minus'] = False # 正常显示负号 # 读取一年的数据文件 -def cosmic_planetw_daily_plot(path: str = f"{DATA_BASEPATH.cosmic}/cosmic.txt", T=16): +def cosmic_planetw_daily_plot( + path: str = f"{DATA_BASEPATH.cosmic}/cosmic.txt", + T=16, + k=0 +): def u_func(x, *params): a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, a7, b7, a8, b8, a9, b9 = params return ( @@ -100,23 +104,22 @@ def cosmic_planetw_daily_plot(path: str = f"{DATA_BASEPATH.cosmic}/cosmic.txt", x_values = fit_df.index.to_numpy() # 对每一列生成独立的图 - for k, col in k_to_a.items(): - plt.figure(figsize=(8, 6)) # 创建新的图形 - plt.plot(x_values, fit_df[col].values) - plt.title(f'{k} 振幅图') - plt.xlabel('Day') - plt.ylabel('振幅') + # for k, col in k_to_a.items(): + col = k_to_a[f'k={k}'] + plt.figure(figsize=(8, 6)) # 创建新的图形 + plt.plot(x_values, fit_df[col].values) + plt.title(f'k={k} 振幅图') + plt.xlabel('Day') + plt.ylabel('振幅') - # 设置横坐标的动态调整 - adjusted_x_values = x_values + (3 * T + 1) / 2 - if len(adjusted_x_values) > 50: - step = 30 - tick_positions = adjusted_x_values[::step] # 选择每30个点 - tick_labels = [f'{int(val)}' for val in tick_positions] - else: - tick_positions = adjusted_x_values - tick_labels = [f'{int(val)}' for val in tick_positions] + # 设置横坐标的动态调整 + adjusted_x_values = x_values + (3 * T + 1) / 2 + if len(adjusted_x_values) > 50: + step = 30 + tick_positions = adjusted_x_values[::step] # 选择每30个点 + tick_labels = [f'{int(val)}' for val in tick_positions] + else: + tick_positions = adjusted_x_values + tick_labels = [f'{int(val)}' for val in tick_positions] - plt.xticks(ticks=tick_positions, labels=tick_labels) - - plt.show() # 显示图形 + plt.xticks(ticks=tick_positions, labels=tick_labels) diff --git a/modules/saber/__init__.py b/modules/saber/__init__.py index 121f7d2..85ab01c 100644 --- a/modules/saber/__init__.py +++ b/modules/saber/__init__.py @@ -146,10 +146,13 @@ async def do_year_power_wave_plot(): async def do_gravity_year(): year = request.args.get("year") T = request.args.get("T") + k = request.args.get("k") + H = request.args.get("H") + lat_range = request.args.get("lat_range") year = int(year) T = int(T) if T not in [5, 10, 16]: raise ValueError("T must be in [5, 10, 16]") data = await run_sync(saber_planetw_process)(year) - await run_sync(saber_planetw_plot)(data, T) + await run_sync(saber_planetw_plot)(data, T, k=int(k)) return await extract_payload() diff --git a/modules/saber/planetw_plot.py b/modules/saber/planetw_plot.py index be9c4d4..3c9c138 100644 --- a/modules/saber/planetw_plot.py +++ b/modules/saber/planetw_plot.py @@ -27,7 +27,11 @@ bounds = ( np.inf, np.inf, np.inf]) # 上界 -def saber_planetw_plot(df: pd.DataFrame, T=16): +def saber_planetw_plot( + df: pd.DataFrame, + T=16, + k=0 +): # 定义拟合函数 def u_func(x, *params): a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, a7, b7, a8, b8, a9, b9 = params @@ -96,27 +100,26 @@ def saber_planetw_plot(df: pd.DataFrame, T=16): x_values = fit_df.index.to_numpy() # 创建一个包含多个子图的图形 - fig, axs = plt.subplots(len(k_to_a), 1, figsize=(10, 2 * len(k_to_a))) # 对每一列生成独立的子图 - for ax, (k, col) in zip(axs, k_to_a.items()): - ax.plot(x_values, fit_df[col].values) - ax.set_title(f'{k} 振幅图') - ax.set_xlabel('Day') - ax.set_ylabel('振幅') + col = k_to_a[f'k={k}'] + plt.plot(x_values, fit_df[col].values) + plt.set_title(f'k = {k} 振幅图') + plt.set_xlabel('Day') + plt.set_ylabel('振幅') - # 设置横坐标的动态调整 - adjusted_x_values = x_values + (3 * T + 1) / 2 - if len(adjusted_x_values) > 50: - step = 30 - tick_positions = adjusted_x_values[::step] # 选择每30个点 - tick_labels = [f'{int(val)}' for val in tick_positions] - else: - tick_positions = adjusted_x_values - tick_labels = [f'{int(val)}' for val in tick_positions] + # 设置横坐标的动态调整 + adjusted_x_values = x_values + (3 * T + 1) / 2 + if len(adjusted_x_values) > 50: + step = 30 + tick_positions = adjusted_x_values[::step] # 选择每30个点 + tick_labels = [f'{int(val)}' for val in tick_positions] + else: + tick_positions = adjusted_x_values + tick_labels = [f'{int(val)}' for val in tick_positions] - ax.set_xticks(tick_positions) - ax.set_xticklabels(tick_labels) + plt.set_xticks(tick_positions) + plt.set_xticklabels(tick_labels) plt.tight_layout() # plt.show()