fix: can choose cosmic planetw day
This commit is contained in:
parent
f05fcd29b5
commit
8c2a919b98
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,6 +19,6 @@ dist
|
|||||||
notebooks
|
notebooks
|
||||||
passcode
|
passcode
|
||||||
data
|
data
|
||||||
|
*.7z
|
||||||
res
|
res
|
||||||
*.txt
|
*.txt
|
||||||
|
|||||||
@ -77,6 +77,6 @@ if __name__ == '__main__':
|
|||||||
env_port = os.getenv("Z_PORT")
|
env_port = os.getenv("Z_PORT")
|
||||||
port = 5000 if env_port is None else int(env_port)
|
port = 5000 if env_port is None else int(env_port)
|
||||||
if 'debug' in args:
|
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:
|
else:
|
||||||
app.run("0.0.0.0", port=port, debug=False)
|
app.run("0.0.0.0", port=port, debug=False)
|
||||||
|
|||||||
@ -55,6 +55,7 @@ async def render_by_mode_single():
|
|||||||
T = request.args.get("T", 16)
|
T = request.args.get("T", 16)
|
||||||
target_h = request.args.get("target_h", 40)
|
target_h = request.args.get("target_h", 40)
|
||||||
target_latitude = request.args.get("target_lat", 30)
|
target_latitude = request.args.get("target_lat", 30)
|
||||||
|
start_day = request.args.get("start_day", 0)
|
||||||
|
|
||||||
# path: str = f"{DATA_BASEPATH.cosmic}/cosmic.txt"
|
# path: str = f"{DATA_BASEPATH.cosmic}/cosmic.txt"
|
||||||
temp_df = await run_sync(cosmic_planet_daily_process)(
|
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)(
|
await run_sync(cosmic_planetw_plot_perday)(
|
||||||
temp_df,
|
temp_df,
|
||||||
T=int(T),
|
T=int(T),
|
||||||
|
start_day=int(start_day)
|
||||||
)
|
)
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
|
|
||||||
|
|||||||
@ -106,7 +106,7 @@ def cosmic_planet_daily_process(
|
|||||||
return pd.read_parquet(cache_path)
|
return pd.read_parquet(cache_path)
|
||||||
|
|
||||||
# 遍历文件夹序号1到365
|
# 遍历文件夹序号1到365
|
||||||
for i in range(1, 165):
|
for i in range(1, 365):
|
||||||
# 根据i的值调整文件夹名称
|
# 根据i的值调整文件夹名称
|
||||||
if i < 10:
|
if i < 10:
|
||||||
folder_name = f"atmPrf_repro2021_2008_00{i}" # 一位数,前面加两个0
|
folder_name = f"atmPrf_repro2021_2008_00{i}" # 一位数,前面加两个0
|
||||||
|
|||||||
@ -24,7 +24,7 @@ bounds = (
|
|||||||
def cosmic_planetw_plot_perday(
|
def cosmic_planetw_plot_perday(
|
||||||
df: pd.DataFrame,
|
df: pd.DataFrame,
|
||||||
T=16,
|
T=16,
|
||||||
|
start_day=0
|
||||||
):
|
):
|
||||||
|
|
||||||
def u_func(x, *params, t):
|
def u_func(x, *params, t):
|
||||||
@ -45,41 +45,48 @@ def cosmic_planetw_plot_perday(
|
|||||||
min_data_points = 36
|
min_data_points = 36
|
||||||
|
|
||||||
# 进行多个时间窗口的拟合
|
# 进行多个时间窗口的拟合
|
||||||
for start_day in range(0, 365 - 3 * T): # 最后一个窗口为[351, 366]
|
# for start_day in range(0, 365 - 3 * T): # 最后一个窗口为[351, 366]
|
||||||
end_day = start_day + 3 * T # 每个窗口的结束时间为 start_day + 3*T
|
end_day = start_day + 3 * T # 每个窗口的结束时间为 start_day + 3*T
|
||||||
|
|
||||||
# 选择当前窗口的数据
|
# 选择当前窗口的数据
|
||||||
df_8 = df[(df['Time'] >= start_day) & (df['Time'] <= end_day)]
|
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值
|
|
||||||
|
|
||||||
|
# 检查当前窗口的数据量
|
||||||
|
if len(df_8) < min_data_points:
|
||||||
|
print(f"数据量不足,无法拟合:{start_day} 到 {end_day},数据点数量:{len(df_8)}")
|
||||||
plt.figure(figsize=(10, 6))
|
plt.figure(figsize=(10, 6))
|
||||||
plt.plot(x_fit, y_fit, label='拟合曲线', color='red', linewidth=2)
|
# write nothing but a title
|
||||||
plt.xlabel('经度(弧度制)')
|
|
||||||
plt.ylabel('温度')
|
|
||||||
plt.title(f'时间窗口:{start_day} 到 {end_day}')
|
plt.title(f'时间窗口:{start_day} 到 {end_day}')
|
||||||
plt.legend()
|
|
||||||
plt.grid(True)
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user