diff --git a/.gitignore b/.gitignore index a690175..477fa91 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,6 @@ dist notebooks passcode data - +*.7z res *.txt diff --git a/backend.py b/backend.py index 6f8f722..8489a7f 100644 --- a/backend.py +++ b/backend.py @@ -77,6 +77,6 @@ if __name__ == '__main__': env_port = os.getenv("Z_PORT") port = 5000 if env_port is None else int(env_port) if 'debug' in args: - app.run("0.0.0.0", port=18200, debug=True) + app.run("0.0.0.0", port=58620, debug=True) else: app.run("0.0.0.0", port=port, debug=False) diff --git a/modules/cosmic/__init__.py b/modules/cosmic/__init__.py index 5816493..a1851aa 100644 --- a/modules/cosmic/__init__.py +++ b/modules/cosmic/__init__.py @@ -55,6 +55,7 @@ async def render_by_mode_single(): T = request.args.get("T", 16) target_h = request.args.get("target_h", 40) target_latitude = request.args.get("target_lat", 30) + start_day = request.args.get("start_day", 0) # path: str = f"{DATA_BASEPATH.cosmic}/cosmic.txt" temp_df = await run_sync(cosmic_planet_daily_process)( @@ -66,6 +67,7 @@ async def render_by_mode_single(): await run_sync(cosmic_planetw_plot_perday)( temp_df, T=int(T), + start_day=int(start_day) ) buf = BytesIO() diff --git a/modules/cosmic/planetw_daily_process.py b/modules/cosmic/planetw_daily_process.py index e885087..f8be828 100644 --- a/modules/cosmic/planetw_daily_process.py +++ b/modules/cosmic/planetw_daily_process.py @@ -106,7 +106,7 @@ def cosmic_planet_daily_process( return pd.read_parquet(cache_path) # 遍历文件夹序号1到365 - for i in range(1, 165): + for i in range(1, 365): # 根据i的值调整文件夹名称 if i < 10: folder_name = f"atmPrf_repro2021_2008_00{i}" # 一位数,前面加两个0 diff --git a/modules/cosmic/planetw_perday.py b/modules/cosmic/planetw_perday.py index bd3fa2f..e9d34b9 100644 --- a/modules/cosmic/planetw_perday.py +++ b/modules/cosmic/planetw_perday.py @@ -24,7 +24,7 @@ bounds = ( def cosmic_planetw_plot_perday( df: pd.DataFrame, T=16, - + start_day=0 ): def u_func(x, *params, t): @@ -45,41 +45,48 @@ def cosmic_planetw_plot_perday( min_data_points = 36 # 进行多个时间窗口的拟合 - for start_day in range(0, 365 - 3 * T): # 最后一个窗口为[351, 366] - end_day = start_day + 3 * T # 每个窗口的结束时间为 start_day + 3*T + # for start_day in range(0, 365 - 3 * T): # 最后一个窗口为[351, 366] + end_day = start_day + 3 * T # 每个窗口的结束时间为 start_day + 3*T - # 选择当前窗口的数据 - df_8 = df[(df['Time'] >= start_day) & (df['Time'] <= end_day)] - - # 检查当前窗口的数据量 - if len(df_8) < min_data_points: - print(f"数据量不足,无法拟合:{start_day} 到 {end_day},数据点数量:{len(df_8)}") - continue # 跳过当前时间窗口,继续下一个窗口 - - # 提取时间、经度、温度数据 - t = np.array(df_8['Time']) # 时间 - x = np.array(df_8['Longitude_Radians']) # 经度弧度制 - temperature = np.array(df_8['Temperature']) # 温度,因变量 - - # `tempeture` 为因变量,`x` 为自变量,`t` 为参数 - # tempeture is possible to contain NaNs, so we need to drop them - mask = ~np.isnan(temperature) - x = x[mask] - temperature = temperature[mask] - - # 用T进行拟合 - popt, pcov = curve_fit(lambda x, *params: u_func(x, *params, t=t), - x, temperature, p0=initial_guess, bounds=bounds, maxfev=50000) - - # 绘制拟合曲线 - t_fixed = (start_day + end_day) / 2 # 窗口的中间时间 - x_fit = np.linspace(min(x), max(x), 100) # 生成用于绘制拟合曲线的x值 - y_fit = u_func(x_fit, *popt, t=t_fixed) # 计算拟合曲线的y值 + # 选择当前窗口的数据 + df_8 = df[(df['Time'] >= start_day) & (df['Time'] <= end_day)] + # 检查当前窗口的数据量 + if len(df_8) < min_data_points: + print(f"数据量不足,无法拟合:{start_day} 到 {end_day},数据点数量:{len(df_8)}") plt.figure(figsize=(10, 6)) - plt.plot(x_fit, y_fit, label='拟合曲线', color='red', linewidth=2) - plt.xlabel('经度(弧度制)') - plt.ylabel('温度') + # write nothing but a title plt.title(f'时间窗口:{start_day} 到 {end_day}') - plt.legend() plt.grid(True) + # add a label, says unable to fit + plt.text(0.5, 0.5, "数据量不足,无法拟合", ha='center', va='center', + transform=plt.gca().transAxes, fontsize=20) # 跳过当前时间窗口,继续下一个窗口 + + # 提取时间、经度、温度数据 + t = np.array(df_8['Time']) # 时间 + x = np.array(df_8['Longitude_Radians']) # 经度弧度制 + temperature = np.array(df_8['Temperature']) # 温度,因变量 + + # `tempeture` 为因变量,`x` 为自变量,`t` 为参数 + # tempeture is possible to contain NaNs, so we need to drop them + mask = ~np.isnan(temperature) + x = x[mask] + temperature = temperature[mask] + t = t[mask] + + # 用T进行拟合 + popt, pcov = curve_fit(lambda x, *params: u_func(x, *params, t=t), + x, temperature, p0=initial_guess, bounds=bounds, maxfev=50000) + + # 绘制拟合曲线 + t_fixed = (start_day + end_day) / 2 # 窗口的中间时间 + x_fit = np.linspace(min(x), max(x), 100) # 生成用于绘制拟合曲线的x值 + y_fit = u_func(x_fit, *popt, t=t_fixed) # 计算拟合曲线的y值 + + plt.figure(figsize=(10, 6)) + plt.plot(x_fit, y_fit, label='拟合曲线', color='red', linewidth=2) + plt.xlabel('经度(弧度制)') + plt.ylabel('温度') + plt.title(f'时间窗口:{start_day} 到 {end_day}') + plt.legend() + plt.grid(True) diff --git a/run.sh b/run.sh index 309574a..4dd45bc 100644 --- a/run.sh +++ b/run.sh @@ -1,3 +1,10 @@ #!/bin/bash -./dist/backend/backend +while true; do + # 运行你的程序 + ./dist/backend/backend + + # 程序退出后等待5秒 + echo "程序已退出,5秒后重新启动..." + sleep 5 +done