diff --git a/src/gui/panels/step6_75_panel.py b/src/gui/panels/step6_75_panel.py index aaf8504..130387c 100644 --- a/src/gui/panels/step6_75_panel.py +++ b/src/gui/panels/step6_75_panel.py @@ -287,32 +287,45 @@ class Step6_75Panel(QWidget): work_dir: 工作目录路径 pipeline: Pipeline 实例(未使用,保留接口兼容性) """ - if work_dir: - self.work_dir = work_dir - elif hasattr(self, 'work_dir') and self.work_dir: - pass - else: - self.work_dir = None + try: + import traceback - # 1. 尝试从 Step5 界面读取训练光谱 CSV 路径 - main_window = self.window() - if main_window and hasattr(main_window, 'step5_panel'): - step5_output_path = main_window.step5_panel.output_file.get_path() - if step5_output_path: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step5_output_path): - step5_output_path = os.path.join(self.work_dir or '', step5_output_path).replace('\\', '/') - existing = self.csv_file.get_path() - if not existing or not existing.strip(): - self.csv_file.set_path(step5_output_path) + if work_dir: + self.work_dir = work_dir + elif hasattr(self, 'work_dir') and self.work_dir: + pass + else: + self.work_dir = None - # 2. 自动填充输出目录(9_Custom_Regression_Modeling) - if self.work_dir: - output_dir = os.path.join(self.work_dir, "9_Custom_Regression_Modeling") - os.makedirs(output_dir, exist_ok=True) - existing_out = self.output_dir.text().strip() - if not existing_out: - self.output_dir.setText(output_dir) + # 1. 尝试从 Step5 界面读取训练光谱 CSV 路径 + main_window = self.window() + if main_window and hasattr(main_window, 'step5_panel'): + step5_widget = getattr(main_window.step5_panel, 'output_file', None) + step5_output_path = "" + if hasattr(step5_widget, 'get_path'): + step5_output_path = step5_widget.get_path() or "" + elif hasattr(step5_widget, 'text'): + step5_output_path = step5_widget.text() or "" + + if step5_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step5_output_path): + step5_output_path = os.path.join(self.work_dir or '', step5_output_path).replace('\\', '/') + existing = self.csv_file.get_path() + if not existing or not existing.strip(): + self.csv_file.set_path(step5_output_path) + + # 2. 自动填充输出目录(9_Custom_Regression_Modeling) + if self.work_dir: + output_dir = os.path.join(self.work_dir, "9_Custom_Regression_Modeling") + os.makedirs(output_dir, exist_ok=True) + existing_out = self.output_dir.text().strip() + if not existing_out: + self.output_dir.setText(output_dir) + except Exception as e: + import traceback + print(f"【{self.__class__.__name__}】自动填充失败,跳过: {e}") + traceback.print_exc() def run_step(self): """独立运行步骤6.75""" diff --git a/src/gui/panels/step8_5_panel.py b/src/gui/panels/step8_5_panel.py index 82914db..74e8520 100644 --- a/src/gui/panels/step8_5_panel.py +++ b/src/gui/panels/step8_5_panel.py @@ -89,44 +89,63 @@ class Step8_5Panel(QWidget): work_dir: 工作目录路径 pipeline: Pipeline 实例(未使用,保留接口兼容性) """ - if work_dir: - self.work_dir = work_dir - elif hasattr(self, 'work_dir') and self.work_dir: - pass - else: - self.work_dir = None + try: + import traceback - main_window = self.window() + if work_dir: + self.work_dir = work_dir + elif hasattr(self, 'work_dir') and self.work_dir: + pass + else: + self.work_dir = None - # 1. 尝试从 Step7 界面读取全湖采样点 CSV 路径 - if main_window and hasattr(main_window, 'step7_panel'): - step7_output_path = main_window.step7_panel.output_file.get_path() - if step7_output_path: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step7_output_path): - step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') - existing = self.sampling_csv_file.get_path() - if not existing or not existing.strip(): - self.sampling_csv_file.set_path(step7_output_path) + main_window = self.window() - # 2. 尝试从 Step6.5 界面读取回归模型目录 - if main_window and hasattr(main_window, 'step6_5_panel'): - step6_5_models_dir = main_window.step6_5_panel.output_dir.get_path() - if step6_5_models_dir: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step6_5_models_dir): - step6_5_models_dir = os.path.join(self.work_dir or '', step6_5_models_dir).replace('\\', '/') - existing_models = self.models_dir_file.get_path() - if not existing_models or not existing_models.strip(): - self.models_dir_file.set_path(step6_5_models_dir) + # 1. 尝试从 Step7 界面读取全湖采样点 CSV 路径 + if main_window and hasattr(main_window, 'step7_panel'): + step7_widget = getattr(main_window.step7_panel, 'output_file', None) + step7_output_path = "" + if hasattr(step7_widget, 'get_path'): + step7_output_path = step7_widget.get_path() or "" + elif hasattr(step7_widget, 'text'): + step7_output_path = step7_widget.text() or "" - # 3. 自动填充输出路径(非经验模型预测目录) - if self.work_dir: - output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Non_Empirical_Prediction") - os.makedirs(output_dir, exist_ok=True) - existing_out = self.output_file.get_path() - if not existing_out or not existing_out.strip(): - self.output_file.set_path(output_dir) + if step7_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step7_output_path): + step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') + existing = self.sampling_csv_file.get_path() + if not existing or not existing.strip(): + self.sampling_csv_file.set_path(step7_output_path) + + # 2. 尝试从 Step6.5 界面读取回归模型目录 + if main_window and hasattr(main_window, 'step6_5_panel'): + step6_5_widget = getattr(main_window.step6_5_panel, 'output_dir', None) + step6_5_models_dir = "" + if hasattr(step6_5_widget, 'get_path'): + step6_5_models_dir = step6_5_widget.get_path() or "" + elif hasattr(step6_5_widget, 'text'): + step6_5_models_dir = step6_5_widget.text() or "" + + if step6_5_models_dir: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step6_5_models_dir): + step6_5_models_dir = os.path.join(self.work_dir or '', step6_5_models_dir).replace('\\', '/') + existing_models = self.models_dir_file.get_path() + if not existing_models or not existing_models.strip(): + self.models_dir_file.set_path(step6_5_models_dir) + + # 3. 自动填充输出路径(非经验模型预测目录) + if self.work_dir: + output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Non_Empirical_Prediction") + os.makedirs(output_dir, exist_ok=True) + existing_out = self.output_file.get_path() + if not existing_out or not existing_out.strip(): + self.output_file.set_path(output_dir) + except Exception as e: + import traceback + print(f"【{self.__class__.__name__}】自动填充失败,跳过: {e}") + traceback.print_exc() def _get_default_work_dir(self): """获取 work_dir,优先用 panel 自身缓存的,否则尝试从主窗口取""" diff --git a/src/gui/panels/step8_75_panel.py b/src/gui/panels/step8_75_panel.py index 809ce6b..fb37d53 100644 --- a/src/gui/panels/step8_75_panel.py +++ b/src/gui/panels/step8_75_panel.py @@ -82,51 +82,71 @@ class Step8_75Panel(QWidget): work_dir: 工作目录路径 pipeline: Pipeline 实例(未使用,保留接口兼容性) """ - if work_dir: - self.work_dir = work_dir - elif hasattr(self, 'work_dir') and self.work_dir: - pass - else: - self.work_dir = None + try: + import traceback - main_window = self.window() + if work_dir: + self.work_dir = work_dir + elif hasattr(self, 'work_dir') and self.work_dir: + pass + else: + self.work_dir = None - # 1. 尝试从 Step7 界面读取全湖采样点 CSV 路径 - if main_window and hasattr(main_window, 'step7_panel'): - step7_output_path = main_window.step7_panel.output_file.get_path() - if step7_output_path: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step7_output_path): - step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') - existing = self.sampling_csv_file.get_path() - if not existing or not existing.strip(): - self.sampling_csv_file.set_path(step7_output_path) + main_window = self.window() - # 2. 尝试从 Step6.75 界面读取自定义回归模型目录 - if main_window and hasattr(main_window, 'step6_75_panel'): - step6_75_models_dir = main_window.step6_75_panel.output_dir.text().strip() - if step6_75_models_dir: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step6_75_models_dir): - step6_75_models_dir = os.path.join(self.work_dir or '', step6_75_models_dir).replace('\\', '/') - existing_models = self.regression_models_dir.get_path() - if not existing_models or not existing_models.strip(): - self.regression_models_dir.set_path(step6_75_models_dir) + # 1. 尝试从 Step7 界面读取全湖采样点 CSV 路径 + if main_window and hasattr(main_window, 'step7_panel'): + step7_widget = getattr(main_window.step7_panel, 'output_file', None) + step7_output_path = "" + if hasattr(step7_widget, 'get_path'): + step7_output_path = step7_widget.get_path() or "" + elif hasattr(step7_widget, 'text'): + step7_output_path = step7_widget.text() or "" - # 3. 自动填充回归模型目录(如果 step6_75 未提供) - if self.work_dir: - models_dir = self.regression_models_dir.get_path().strip() - if not models_dir: - default_models_dir = os.path.join(self.work_dir, "9_Custom_Regression_Modeling").replace('\\', '/') - self.regression_models_dir.set_path(default_models_dir) + if step7_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step7_output_path): + step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') + existing = self.sampling_csv_file.get_path() + if not existing or not existing.strip(): + self.sampling_csv_file.set_path(step7_output_path) - # 4. 自动填充输出目录(自定义回归预测目录) - if self.work_dir: - output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Custom_Regression_Prediction") - os.makedirs(output_dir, exist_ok=True) - existing_out = self.output_dir_widget.get_path() - if not existing_out or not existing_out.strip(): - self.output_dir_widget.set_path(output_dir) + # 2. 尝试从 Step6.75 界面读取自定义回归模型目录 + if main_window and hasattr(main_window, 'step6_75_panel'): + step6_75_widget = getattr(main_window.step6_75_panel, 'output_dir', None) + step6_75_models_dir = "" + if hasattr(step6_75_widget, 'get_path'): + step6_75_models_dir = step6_75_widget.get_path() or "" + elif hasattr(step6_75_widget, 'text'): + step6_75_models_dir = step6_75_widget.text() or "" + step6_75_models_dir = step6_75_models_dir.strip() + + if step6_75_models_dir: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step6_75_models_dir): + step6_75_models_dir = os.path.join(self.work_dir or '', step6_75_models_dir).replace('\\', '/') + existing_models = self.regression_models_dir.get_path() + if not existing_models or not existing_models.strip(): + self.regression_models_dir.set_path(step6_75_models_dir) + + # 3. 自动填充回归模型目录(如果 step6_75 未提供) + if self.work_dir: + models_dir = self.regression_models_dir.get_path().strip() + if not models_dir: + default_models_dir = os.path.join(self.work_dir, "9_Custom_Regression_Modeling").replace('\\', '/') + self.regression_models_dir.set_path(default_models_dir) + + # 4. 自动填充输出目录(自定义回归预测目录) + if self.work_dir: + output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Custom_Regression_Prediction") + os.makedirs(output_dir, exist_ok=True) + existing_out = self.output_dir_widget.get_path() + if not existing_out or not existing_out.strip(): + self.output_dir_widget.set_path(output_dir) + except Exception as e: + import traceback + print(f"【{self.__class__.__name__}】自动填充失败,跳过: {e}") + traceback.print_exc() def _get_default_work_dir(self): """获取 work_dir,优先用 panel 自身缓存的,否则尝试从主窗口取""" diff --git a/src/gui/panels/step8_panel.py b/src/gui/panels/step8_panel.py index d1ae65a..06f41ec 100644 --- a/src/gui/panels/step8_panel.py +++ b/src/gui/panels/step8_panel.py @@ -86,44 +86,63 @@ class Step8Panel(QWidget): work_dir: 工作目录路径 pipeline: Pipeline 实例(未使用,保留接口兼容性) """ - if work_dir: - self.work_dir = work_dir - elif hasattr(self, 'work_dir') and self.work_dir: - pass - else: - self.work_dir = None + try: + import traceback - main_window = self.window() + if work_dir: + self.work_dir = work_dir + elif hasattr(self, 'work_dir') and self.work_dir: + pass + else: + self.work_dir = None - # 1. 尝试从 Step7 界面读取全湖采样点 CSV 路径 - if main_window and hasattr(main_window, 'step7_panel'): - step7_output_path = main_window.step7_panel.output_file.get_path() - if step7_output_path: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step7_output_path): - step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') - existing = self.sampling_csv_file.get_path() - if not existing or not existing.strip(): - self.sampling_csv_file.set_path(step7_output_path) + main_window = self.window() - # 2. 尝试从 Step6 界面读取监督模型目录 - if main_window and hasattr(main_window, 'step6_panel'): - step6_models_dir = main_window.step6_panel.output_dir.get_path() - if step6_models_dir: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step6_models_dir): - step6_models_dir = os.path.join(self.work_dir or '', step6_models_dir).replace('\\', '/') - existing_models = self.models_dir_file.get_path() - if not existing_models or not existing_models.strip(): - self.models_dir_file.set_path(step6_models_dir) + # 1. 尝试从 Step7 界面读取全湖采样点 CSV 路径 + if main_window and hasattr(main_window, 'step7_panel'): + step7_widget = getattr(main_window.step7_panel, 'output_file', None) + step7_output_path = "" + if hasattr(step7_widget, 'get_path'): + step7_output_path = step7_widget.get_path() or "" + elif hasattr(step7_widget, 'text'): + step7_output_path = step7_widget.text() or "" - # 3. 自动填充输出路径(机器学习预测目录) - if self.work_dir: - output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Machine_Learning_Prediction") - os.makedirs(output_dir, exist_ok=True) - existing_out = self.output_file.get_path() - if not existing_out or not existing_out.strip(): - self.output_file.set_path(output_dir) + if step7_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step7_output_path): + step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') + existing = self.sampling_csv_file.get_path() + if not existing or not existing.strip(): + self.sampling_csv_file.set_path(step7_output_path) + + # 2. 尝试从 Step6 界面读取监督模型目录 + if main_window and hasattr(main_window, 'step6_panel'): + step6_widget = getattr(main_window.step6_panel, 'output_dir', None) + step6_models_dir = "" + if hasattr(step6_widget, 'get_path'): + step6_models_dir = step6_widget.get_path() or "" + elif hasattr(step6_widget, 'text'): + step6_models_dir = step6_widget.text() or "" + + if step6_models_dir: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step6_models_dir): + step6_models_dir = os.path.join(self.work_dir or '', step6_models_dir).replace('\\', '/') + existing_models = self.models_dir_file.get_path() + if not existing_models or not existing_models.strip(): + self.models_dir_file.set_path(step6_models_dir) + + # 3. 自动填充输出路径(机器学习预测目录) + if self.work_dir: + output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Machine_Learning_Prediction") + os.makedirs(output_dir, exist_ok=True) + existing_out = self.output_file.get_path() + if not existing_out or not existing_out.strip(): + self.output_file.set_path(output_dir) + except Exception as e: + import traceback + print(f"【{self.__class__.__name__}】自动填充失败,跳过: {e}") + traceback.print_exc() def _get_default_work_dir(self): """获取 work_dir,优先用 panel 自身缓存的,否则尝试从主窗口取""" diff --git a/src/gui/panels/step9_panel.py b/src/gui/panels/step9_panel.py index 74c8531..507d9a6 100644 --- a/src/gui/panels/step9_panel.py +++ b/src/gui/panels/step9_panel.py @@ -308,57 +308,82 @@ class Step9Panel(QWidget): work_dir: 工作目录路径 pipeline: Pipeline 实例(未使用,保留接口兼容性) """ - if work_dir: - self.work_dir = work_dir - elif hasattr(self, 'work_dir') and self.work_dir: - pass - else: - self.work_dir = None + try: + import traceback - main_window = self.window() - if not main_window: - return + if work_dir: + self.work_dir = work_dir + elif hasattr(self, 'work_dir') and self.work_dir: + pass + else: + self.work_dir = None - # 1. 尝试从 Step8 界面读取机器学习预测输出目录(优先) - pred_dir = None - if hasattr(main_window, 'step8_panel'): - step8_output = main_window.step8_panel.output_file.get_path() - if step8_output: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step8_output): - step8_output = os.path.join(self.work_dir or '', step8_output).replace('\\', '/') - pred_dir = str(Path(step8_output).parent) + main_window = self.window() + if not main_window: + return - # 2. 备选:从 Step8.5 界面读取非经验预测输出目录 - if not pred_dir and hasattr(main_window, 'step8_5_panel'): - step8_5_output = main_window.step8_5_panel.output_file.get_path() - if step8_5_output: - # 若为相对路径,使用 work_dir 合成为绝对路径 - if not os.path.isabs(step8_5_output): - step8_5_output = os.path.join(self.work_dir or '', step8_5_output).replace('\\', '/') - pred_dir = str(Path(step8_5_output).parent) + # 1. 尝试从 Step8 界面读取机器学习预测输出目录(优先) + pred_dir = None + if hasattr(main_window, 'step8_panel'): + step8_widget = getattr(main_window.step8_panel, 'output_file', None) + step8_output = "" + if hasattr(step8_widget, 'get_path'): + step8_output = step8_widget.get_path() or "" + elif hasattr(step8_widget, 'text'): + step8_output = step8_widget.text() or "" - # 3. 备选:从 Step8.75 界面读取自定义回归预测输出目录 - if not pred_dir and hasattr(main_window, 'step8_75_panel'): - step8_75_output = main_window.step8_75_panel.output_dir_widget.get_path() - if step8_75_output: - pred_dir = step8_75_output + if step8_output: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step8_output): + step8_output = os.path.join(self.work_dir or '', step8_output).replace('\\', '/') + pred_dir = str(Path(step8_output).parent) - # 自动填入"预测CSV目录"(文件夹批量模式) - if pred_dir: - existing_dir = (self.prediction_csv_dir_edit.text() or "").strip() - if not existing_dir: - self.prediction_csv_dir_edit.setText(pred_dir) - # 切换到文件夹批量模式 - self.mode_folder_rb.setChecked(True) + # 2. 备选:从 Step8.5 界面读取非经验预测输出目录 + if not pred_dir and hasattr(main_window, 'step8_5_panel'): + step8_5_widget = getattr(main_window.step8_5_panel, 'output_file', None) + step8_5_output = "" + if hasattr(step8_5_widget, 'get_path'): + step8_5_output = step8_5_widget.get_path() or "" + elif hasattr(step8_5_widget, 'text'): + step8_5_output = step8_5_widget.text() or "" - # 4. 自动填充输出目录(14_visualization) - if self.work_dir: - output_dir = os.path.join(self.work_dir, "14_visualization") - os.makedirs(output_dir, exist_ok=True) - existing_out = self.output_dir.get_path() - if not existing_out or not existing_out.strip(): - self.output_dir.set_path(output_dir) + if step8_5_output: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step8_5_output): + step8_5_output = os.path.join(self.work_dir or '', step8_5_output).replace('\\', '/') + pred_dir = str(Path(step8_5_output).parent) + + # 3. 备选:从 Step8.75 界面读取自定义回归预测输出目录 + if not pred_dir and hasattr(main_window, 'step8_75_panel'): + step8_75_widget = getattr(main_window.step8_75_panel, 'output_dir_widget', None) + step8_75_output = "" + if hasattr(step8_75_widget, 'get_path'): + step8_75_output = step8_75_widget.get_path() or "" + elif hasattr(step8_75_widget, 'text'): + step8_75_output = step8_75_widget.text() or "" + + if step8_75_output: + pred_dir = step8_75_output + + # 自动填入"预测CSV目录"(文件夹批量模式) + if pred_dir: + existing_dir = (self.prediction_csv_dir_edit.text() or "").strip() + if not existing_dir: + self.prediction_csv_dir_edit.setText(pred_dir) + # 切换到文件夹批量模式 + self.mode_folder_rb.setChecked(True) + + # 4. 自动填充输出目录(14_visualization) + if self.work_dir: + output_dir = os.path.join(self.work_dir, "14_visualization") + os.makedirs(output_dir, exist_ok=True) + existing_out = self.output_dir.get_path() + if not existing_out or not existing_out.strip(): + self.output_dir.set_path(output_dir) + except Exception as e: + import traceback + print(f"【{self.__class__.__name__}】自动填充失败,跳过: {e}") + traceback.print_exc() def browse_output_dir(self): """浏览输出目录"""