fix(gui): step8_panel改用DataPreparationStep计算水质指数,统一pipeline与面板独立运行路径
This commit is contained in:
@ -346,17 +346,38 @@ class Step8Panel(QWidget):
|
|||||||
output_mode = config['output_mode']
|
output_mode = config['output_mode']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from src.utils.water_index import WaterQualityIndexCalculator
|
from src.core.steps.data_preparation_step import DataPreparationStep
|
||||||
|
|
||||||
calculator = WaterQualityIndexCalculator(self.builtin_formula_path)
|
|
||||||
|
|
||||||
spec_df = pd.read_csv(training_path)
|
spec_df = pd.read_csv(training_path)
|
||||||
x_col, y_col = self._get_coord_cols(spec_df)
|
x_col, y_col = self._get_coord_cols(spec_df)
|
||||||
|
|
||||||
results_df = calculator.calculate_many(formula_names, spec_df)
|
# 构建 formula_csv_path(使用内置 waterindex.csv)
|
||||||
output_df = pd.concat([spec_df, results_df], axis=1)
|
import os
|
||||||
|
formula_csv_path = self.builtin_formula_path
|
||||||
|
if not formula_csv_path or not os.path.exists(formula_csv_path):
|
||||||
|
# 尝试从 src/gui/model/ 目录找
|
||||||
|
possible_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'gui', 'model', 'waterindex.csv')
|
||||||
|
if os.path.exists(possible_path):
|
||||||
|
formula_csv_path = possible_path
|
||||||
|
|
||||||
work_dir = self._get_work_dir()
|
work_dir = self._get_work_dir()
|
||||||
|
|
||||||
|
# 调用 DataPreparationStep 的静态方法计算水质指数(宽表输出)
|
||||||
|
indices_csv_path = DataPreparationStep.calculate_water_quality_indices(
|
||||||
|
training_csv_path=training_path,
|
||||||
|
formula_csv_file=formula_csv_path,
|
||||||
|
formula_names=formula_names,
|
||||||
|
output_file=None, # 不在此处指定输出,由下面的双轨输出逻辑接管
|
||||||
|
enabled=True,
|
||||||
|
output_dir=work_dir if work_dir else os.getcwd(),
|
||||||
|
)
|
||||||
|
|
||||||
|
# 读取计算结果(宽表)
|
||||||
|
if indices_csv_path and os.path.exists(indices_csv_path):
|
||||||
|
output_df = pd.read_csv(indices_csv_path)
|
||||||
|
else:
|
||||||
|
output_df = spec_df # fallback
|
||||||
|
|
||||||
track_a_path = None
|
track_a_path = None
|
||||||
track_b_dir = None
|
track_b_dir = None
|
||||||
|
|
||||||
@ -379,12 +400,12 @@ class Step8Panel(QWidget):
|
|||||||
coord_y = spec_df[y_col].values if y_col in spec_df.columns else np.zeros(len(spec_df))
|
coord_y = spec_df[y_col].values if y_col in spec_df.columns else np.zeros(len(spec_df))
|
||||||
|
|
||||||
for formula_name in formula_names:
|
for formula_name in formula_names:
|
||||||
if formula_name not in results_df.columns:
|
if formula_name not in output_df.columns:
|
||||||
continue
|
continue
|
||||||
single_df = pd.DataFrame({
|
single_df = pd.DataFrame({
|
||||||
'x_coord': coord_x,
|
'x_coord': coord_x,
|
||||||
'y_coord': coord_y,
|
'y_coord': coord_y,
|
||||||
'value': results_df[formula_name].values,
|
'value': output_df[formula_name].values,
|
||||||
})
|
})
|
||||||
safe_name = formula_name.replace('/', '_').replace(' ', '_')
|
safe_name = formula_name.replace('/', '_').replace(' ', '_')
|
||||||
out_path = os.path.join(track_b_dir, f"{safe_name}_prediction.csv")
|
out_path = os.path.join(track_b_dir, f"{safe_name}_prediction.csv")
|
||||||
@ -397,7 +418,7 @@ class Step8Panel(QWidget):
|
|||||||
)
|
)
|
||||||
|
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
QMessageBox.critical(self, "依赖错误", f"无法导入 WaterQualityIndexCalculator:\n{e}")
|
QMessageBox.critical(self, "依赖错误", f"无法导入模块:\n{e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
QMessageBox.critical(self, "计算失败", f"原因: {str(e)}\n{traceback.format_exc()}")
|
QMessageBox.critical(self, "计算失败", f"原因: {str(e)}\n{traceback.format_exc()}")
|
||||||
Reference in New Issue
Block a user