From d3262ae80d28188b48a9528fb81944978311a932 Mon Sep 17 00:00:00 2001 From: DXC Date: Thu, 11 Jun 2026 14:58:39 +0800 Subject: [PATCH] Rename pipeline method names to match step numbers (Step4) --- src/core/pipeline/runner.py | 14 +++---- src/core/steps/data_preparation_step.py | 2 +- .../water_quality_inversion_pipeline_GUI.py | 38 +++++++++---------- src/gui/core/worker_thread.py | 21 ++++------ src/gui/panels/step14_panel.py | 2 +- src/gui/panels/step6_feature_panel.py | 2 +- 6 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/core/pipeline/runner.py b/src/core/pipeline/runner.py index 288e434..547aa3f 100644 --- a/src/core/pipeline/runner.py +++ b/src/core/pipeline/runner.py @@ -95,14 +95,14 @@ PIPELINE_STEPS: List[StepSpec] = [ description="耀斑去除", ), StepSpec( - step_id="step4", method_name="step4_process_csv", + step_id="step4", method_name="step5_process_csv", requires=["csv_path"], produces=["processed_csv_path"], required_input_files=["csv_path"], output_file="{work_dir}/4_processed_data/processed_data.csv", description="CSV 异常值清洗", ), StepSpec( - step_id="step5", method_name="step5_extract_training_spectra", + step_id="step5", method_name="step6_extract_spectra", requires=["deglint_img_path", "processed_csv_path", "csv_path", "boundary_path", "glint_mask_path"], produces=["training_csv_path"], parameter_map={ @@ -115,14 +115,14 @@ PIPELINE_STEPS: List[StepSpec] = [ description="实测样本点光谱提取", ), StepSpec( - step_id="step7", method_name="step7_water_quality_indices", + step_id="step7", method_name="step7_calc_indices", requires=["training_csv_path"], produces=["indices_path", "trad_indices_dir"], required_input_files=["training_csv_path"], output_file="{work_dir}/6_water_quality_indices/training_spectra_indices.csv", description="水质参数指数计算(双轨输出:A轨宽表 + B轨单文件)", ), StepSpec( - step_id="step8", method_name="step8_ml_modeling", + step_id="step8", method_name="step8_train_ml", requires=["training_csv_path"], produces=["models_dir"], required_input_files=["training_csv_path"], output_file="{work_dir}/7_Supervised_Model_Training/best_models.pkl", @@ -145,14 +145,14 @@ PIPELINE_STEPS: List[StepSpec] = [ description="水色指数反演(BSQ 影像直接处理)", ), StepSpec( - step_id="step10", method_name="step10_sampling", + step_id="step10", method_name="step4_sampling", requires=["deglint_img_path", "water_mask_path"], produces=["sampling_csv_path"], required_input_files=["deglint_img_path", "water_mask_path"], output_file="{work_dir}/4_sampling/sampling_spectra.csv", description="整景密集采样点生成 + 光谱提取", ), StepSpec( - step_id="step11_ml", method_name="step11_ml_prediction", + step_id="step11_ml", method_name="step9_predict_ml", requires=["sampling_csv_path", "models_dir"], produces=["prediction_csv_path"], required_input_files=["sampling_csv_path", "models_dir"], output_file="{work_dir}/11_12_13_predictions/prediction_results.csv", @@ -167,7 +167,7 @@ PIPELINE_STEPS: List[StepSpec] = [ description="非经验模型预测", ), StepSpec( - step_id="step14", method_name="step14_distribution_map", + step_id="step14", method_name="step10_map", requires=["prediction_csv_path", "boundary_shp_path"], produces=["distribution_map_path"], required_input_files=["prediction_csv_path", "boundary_shp_path"], diff --git a/src/core/steps/data_preparation_step.py b/src/core/steps/data_preparation_step.py index 3e5e1ea..db15fac 100644 --- a/src/core/steps/data_preparation_step.py +++ b/src/core/steps/data_preparation_step.py @@ -2,7 +2,7 @@ """ 数据准备步骤 -包含 step4_process_csv, step5_extract_training_spectra, step5_5_calculate_water_quality_indices +包含 step5_process_csv, step6_extract_spectra, step5_5_calculate_water_quality_indices """ import time diff --git a/src/core/water_quality_inversion_pipeline_GUI.py b/src/core/water_quality_inversion_pipeline_GUI.py index ff43bc3..43e6c80 100644 --- a/src/core/water_quality_inversion_pipeline_GUI.py +++ b/src/core/water_quality_inversion_pipeline_GUI.py @@ -585,7 +585,7 @@ class WaterQualityInversionPipeline: status="failed", error=str(e)) raise - def step4_process_csv(self, csv_path: str, skip_dependency_check: bool = False, **kwargs) -> str: + def step5_process_csv(self, csv_path: str, skip_dependency_check: bool = False, **kwargs) -> str: """ 步骤4: 对csv文件进行处理,筛选剔除异常值 @@ -606,7 +606,7 @@ class WaterQualityInversionPipeline: self._notify("completed", f"处理后的CSV文件已保存: {result}") return result - def step5_extract_training_spectra(self, deglint_img_path: Optional[str] = None, + def step6_extract_spectra(self, deglint_img_path: Optional[str] = None, radius: int = 5, source_epsg: int = 4326, csv_path: Optional[str] = None, @@ -657,7 +657,7 @@ class WaterQualityInversionPipeline: self._notify("completed", f"训练光谱数据已保存: {result}") return result - def step6_water_quality_indices(self, + def step7_calc_indices(self, training_csv_path: Optional[str] = None, formula_csv_file: Optional[str] = None, formula_names: Optional[List[str]] = None, @@ -701,7 +701,7 @@ class WaterQualityInversionPipeline: self._notify("completed", f"水质指数已保存: {result}") return result - def step7_ml_modeling(self, feature_start_column: str = "374.285004", + def step8_train_ml(self, feature_start_column: str = "374.285004", preprocessing_methods: List[str] = None, model_names: List[str] = None, split_methods: List[str] = None, @@ -859,7 +859,7 @@ class WaterQualityInversionPipeline: msg = f"Step 9: 浓度反演完毕,结果保存于: {result_csv}" (self.logger.info if hasattr(self, 'logger') else print)(msg) - def step10_sampling(self, deglint_img_path: Optional[str] = None, + def step4_sampling(self, deglint_img_path: Optional[str] = None, interval: int = 50, sample_radius: int = 5, chunk_size: int = 1000, @@ -906,7 +906,7 @@ class WaterQualityInversionPipeline: self._notify("completed", f"采样点光谱数据已保存: {result}") return result - def step11_ml_prediction(self, sampling_csv_path: str, + def step9_predict_ml(self, sampling_csv_path: str, models_dir: Optional[str] = None, metric: str = 'test_r2', prediction_column: str = 'prediction', @@ -947,7 +947,7 @@ class WaterQualityInversionPipeline: self._notify("completed", f"预测完成,结果保存在: {self.prediction_dir}") return result - def step14_distribution_map(self, prediction_csv_path: str, + def step10_map(self, prediction_csv_path: str, boundary_shp_path: str, output_image_path: Optional[str] = None, resolution: float = 30, @@ -1623,7 +1623,7 @@ class WaterQualityInversionPipeline: # 步骤4: 处理CSV文件 if 'step4' in config: self._notify("步骤4: 数据预处理", "start") - self.step4_process_csv(**config['step4']) + self.step5_process_csv(**config['step4']) self._notify("步骤4: 数据预处理", "completed", f"(输出: {self.processed_csv_path})") else: self._notify("步骤4: 数据预处理", "skipped", "未配置") @@ -1631,7 +1631,7 @@ class WaterQualityInversionPipeline: # 步骤5: 提取训练样本点光谱 if 'step5' in config: self._notify("步骤5: 光谱提取", "start") - self.step5_extract_training_spectra(**config['step5']) + self.step6_extract_spectra(**config['step5']) self._notify("步骤5: 光谱提取", "completed", f"(输出: {self.training_csv_path})") else: self._notify("步骤5: 光谱提取", "skipped", "未配置") @@ -1639,7 +1639,7 @@ class WaterQualityInversionPipeline: # 步骤6: 计算水质指数 if 'step6' in config: self._notify("步骤6: 水质光谱指数计算", "start") - self.step6_water_quality_indices(**config['step6']) + self.step7_calc_indices(**config['step6']) self._notify("步骤6: 水质光谱指数计算", "completed", f"(输出: {self.indices_path})") else: self._notify("步骤6: 水质光谱指数计算", "skipped", "未配置") @@ -1647,7 +1647,7 @@ class WaterQualityInversionPipeline: # 步骤7: 训练模型 if 'step7' in config: self._notify("步骤7: 模型训练", "start") - self.step7_ml_modeling(**config['step7']) + self.step8_train_ml(**config['step7']) self._notify("步骤7: 模型训练", "completed", f"(输出: {self.models_dir})") else: self._notify("步骤7: 模型训练", "skipped", "未配置") @@ -1671,7 +1671,7 @@ class WaterQualityInversionPipeline: # 步骤10: 生成预测采样点 if 'step10' in config: self._notify("步骤10: 采样点生成", "start") - sampling_csv_path = self.step10_sampling(**config['step10']) + sampling_csv_path = self.step4_sampling(**config['step10']) self._notify("步骤10: 采样点生成", "completed", f"(输出: {sampling_csv_path})") else: sampling_csv_path = None @@ -1682,7 +1682,7 @@ class WaterQualityInversionPipeline: self._notify("步骤11: 参数预测", "start") step11_ml_config = config['step11_ml'].copy() step11_ml_config['sampling_csv_path'] = sampling_csv_path - prediction_files = self.step11_ml_prediction(**step11_ml_config) + prediction_files = self.step9_predict_ml(**step11_ml_config) self._notify("步骤11: 参数预测", "completed", f"(生成{len(prediction_files)}个预测文件)") else: prediction_files = {} @@ -1724,7 +1724,7 @@ class WaterQualityInversionPipeline: step14_config['prediction_csv_path'] = pred_file if 'output_image_path' not in step14_config: step14_config['output_image_path'] = None - dist_map_path = self.step14_distribution_map(**step14_config) + dist_map_path = self.step10_map(**step14_config) distribution_maps[target_name] = dist_map_path self._notify("步骤14: 分布图生成", "completed", f"(生成{len(distribution_maps)}个分布图)") else: @@ -2426,7 +2426,7 @@ def example_independent_steps(): # 示例3: 独立运行步骤4 - 数据预处理 print("\n示例3: 独立运行步骤4 - 数据预处理") try: - processed_csv = pipeline.step4_process_csv( + processed_csv = pipeline.step5_process_csv( csv_path="path/to/water_quality_data.csv" ) print(f"处理后的CSV文件: {processed_csv}") @@ -2436,7 +2436,7 @@ def example_independent_steps(): # 示例4: 独立运行步骤5 - 光谱提取 print("\n示例4: 独立运行步骤5 - 光谱提取") try: - training_spectra = pipeline.step5_extract_training_spectra( + training_spectra = pipeline.step6_extract_spectra( deglint_img_path="path/to/deglint_image.bsq", csv_path="path/to/processed_data.csv", glint_mask_path="path/to/severe_glint_area.dat", @@ -2460,7 +2460,7 @@ def example_independent_steps(): # 示例6: 独立运行步骤10 - 采样点生成 print("\n示例6: 独立运行步骤10 - 采样点生成") try: - sampling_csv = pipeline.step10_sampling( + sampling_csv = pipeline.step4_sampling( deglint_img_path="path/to/deglint_image.bsq", water_mask_path="path/to/water_mask.dat", skip_dependency_check=True @@ -2472,7 +2472,7 @@ def example_independent_steps(): # 示例7: 独立运行步骤11 - 水质预测 print("\n示例7: 独立运行步骤11 - 水质预测") try: - predictions = pipeline.step11_ml_prediction( + predictions = pipeline.step9_predict_ml( sampling_csv_path="path/to/sampling_spectra.csv", models_dir="path/to/models_directory", skip_dependency_check=True @@ -2484,7 +2484,7 @@ def example_independent_steps(): # 示例8: 独立运行步骤14 - 分布图生成 print("\n示例8: 独立运行步骤14 - 分布图生成") try: - distribution_map = pipeline.step14_distribution_map( + distribution_map = pipeline.step10_map( prediction_csv_path="path/to/prediction_results.csv", boundary_shp_path="path/to/boundary.shp", skip_dependency_check=True diff --git a/src/gui/core/worker_thread.py b/src/gui/core/worker_thread.py index 074530c..a46f78c 100644 --- a/src/gui/core/worker_thread.py +++ b/src/gui/core/worker_thread.py @@ -323,18 +323,17 @@ class WorkerThread(QThread): 'step1': 'step1_generate_water_mask', 'step2': 'step2_find_glint_area', 'step3': 'step3_remove_glint', - 'step4': 'step4_process_csv', - 'step5': 'step5_extract_training_spectra', - 'step7': 'step7_water_quality_indices', - 'step8': 'step8_ml_modeling', + 'step4': 'step5_process_csv', + 'step5': 'step6_extract_spectra', + 'step7': 'step7_calc_indices', + 'step8': 'step8_train_ml', 'step8_non_empirical_modeling': 'step8_non_empirical_modeling', 'step8_qaa': 'step8_qaa_inversion', 'step9': 'step9_watercolor_inversion', - 'step9_concentration': 'step9_concentration_inversion', - 'step10': 'step10_sampling', - 'step11_ml': 'step11_ml_prediction', + 'step10': 'step4_sampling', + 'step11_ml': 'step9_predict_ml', 'step11': 'step11_non_empirical_prediction', - 'step14': 'step14_distribution_map' + 'step14': 'step10_map' } if step_name not in step_method_map: @@ -350,12 +349,6 @@ class WorkerThread(QThread): result = method(**config) return result - # step9_concentration_inversion 同理,必须透传完整 config dict - if step_name == 'step9_concentration': - method = getattr(self.pipeline, method_name) - result = method(**config) - return result - # 透传面板顶层传入的外部预训练模型(GUI step11_prediction_panel 通过 config['_external_model'] 传入) # 非空才覆盖(遵循 feedback_never_overwrite_with_empty 原则) for key in ('_external_model', '_external_model_path', diff --git a/src/gui/panels/step14_panel.py b/src/gui/panels/step14_panel.py index 346b654..d94529d 100644 --- a/src/gui/panels/step14_panel.py +++ b/src/gui/panels/step14_panel.py @@ -68,7 +68,7 @@ class Step14BatchThread(QThread): kw["output_image_path"] = str(Path(self.output_dir_optional) / f"{stem}_distribution.png") else: kw["output_image_path"] = None - pipeline.step14_distribution_map(**kw) + pipeline.step10_map(**kw) self.finished_ok.emit(n) except Exception as e: self.failed.emit(f"{e}\n{traceback.format_exc()}") diff --git a/src/gui/panels/step6_feature_panel.py b/src/gui/panels/step6_feature_panel.py index 5f7e56a..5536254 100644 --- a/src/gui/panels/step6_feature_panel.py +++ b/src/gui/panels/step6_feature_panel.py @@ -124,7 +124,7 @@ class Step6FeaturePanel(QWidget): glint_mask_path = self.glint_mask_file.get_path() if glint_mask_path: config['glint_mask_path'] = glint_mask_path - # 注意:step5_extract_training_spectra 不接受 output_path / training_csv_path + # 注意:step6_extract_spectra 不接受 output_path / training_csv_path # 参数,输出路径由 pipeline 内部根据 training_spectra_dir 自动生成。 return config