fix(interpolation.py): 修复 krig_variables 变量先使用后定义的 NameError

ordinary_kriging() 函数存在两个问题:

1. krig_variables 先使用后定义(NameError 被 try/except 静默吞掉):
   - 原代码: 第103-114行绘图调用引用了 krig_variables,
     但该字典在第121-133行才创建
   - 修复: 将 krig_variables 字典构造移至绘图调用之前(第103行之前),
     确保 contour_krig()、heatmap_krig()、semivariogram_plot() 可正常获取数据

2. 启用克里金图表输出:
   - 原代码: contour_plot = None; grid_plot = None; semivariogram_plot = None
   - 修复: 分别调用 plotting.contour_krig()、plotting.heatmap_krig()、
     plotting.semivariogram_plot(),每个调用独立 try/except 保护

影响范围:克里金等高线图和热力图从永远空白变为正常显示
This commit is contained in:
DXC
2026-07-10 14:49:09 +08:00
parent 408e1660fc
commit e5f43f0297

View File

@ -99,11 +99,6 @@ def ordinary_kriging(
# np.nan_to_num(error_1s, copy=False, nan=0)
volume_error = simpsonintegrate(error_1s, x_cell_size, y_cell_size)
# Plots disabled
contour_plot = None
grid_plot = None
semivariogram_plot = None
output_text = (
f"The emissions flux of {gas.upper()} is {volume:.3f}kgh⁻¹; "
f"the cut and fill volumes of the grid are {volumepos:.3f} and {volumeneg:.3f}kgh⁻¹. "
@ -123,6 +118,20 @@ def ordinary_kriging(
"volume_error": volume_error,
}
# Generate plots (must be after krig_variables is defined)
try:
contour_plot = plotting.contour_krig(krig_variables)
except Exception:
contour_plot = None
try:
grid_plot = plotting.heatmap_krig(krig_variables)
except Exception:
grid_plot = None
try:
semivariogram_plot = plotting.semivariogram_plot(semivariogram, gas)
except Exception:
semivariogram_plot = None
return krig_variables, output_text, contour_plot, grid_plot, semivariogram_plot