修复所有 Panel 的相对路径传递问题,防止 FileNotFoundError
This commit is contained in:
@ -179,6 +179,9 @@ class Step2Panel(QWidget):
|
|||||||
|
|
||||||
# 填充获取到的路径
|
# 填充获取到的路径
|
||||||
if mask_path:
|
if mask_path:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(mask_path):
|
||||||
|
mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/')
|
||||||
self.water_mask_file.set_path(mask_path)
|
self.water_mask_file.set_path(mask_path)
|
||||||
|
|
||||||
# 3. 自动填充输出路径(基于工作目录)
|
# 3. 自动填充输出路径(基于工作目录)
|
||||||
|
|||||||
@ -294,6 +294,9 @@ class Step3Panel(QWidget):
|
|||||||
mask_path = main_window.step1_panel.mask_file.get_path()
|
mask_path = main_window.step1_panel.mask_file.get_path()
|
||||||
|
|
||||||
if mask_path:
|
if mask_path:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(mask_path):
|
||||||
|
mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/')
|
||||||
self.water_mask_file.set_path(mask_path)
|
self.water_mask_file.set_path(mask_path)
|
||||||
|
|
||||||
# 自动填充输出路径(基于工作目录)
|
# 自动填充输出路径(基于工作目录)
|
||||||
|
|||||||
@ -308,11 +308,17 @@ class Step5_5Panel(QWidget):
|
|||||||
# 优先直接从 Step5 的输出 widget 读取(已运行的最新输出)
|
# 优先直接从 Step5 的输出 widget 读取(已运行的最新输出)
|
||||||
step5_output = main_window.step5_panel.output_file.get_path()
|
step5_output = main_window.step5_panel.output_file.get_path()
|
||||||
if step5_output:
|
if step5_output:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(step5_output):
|
||||||
|
step5_output = os.path.join(self.work_dir or '', step5_output).replace('\\', '/')
|
||||||
self.training_data_widget.set_path(step5_output)
|
self.training_data_widget.set_path(step5_output)
|
||||||
else:
|
else:
|
||||||
# 退而求其次,使用 Step5 的输入 CSV
|
# 退而求其次,使用 Step5 的输入 CSV
|
||||||
step5_csv = main_window.step5_panel.csv_file.get_path()
|
step5_csv = main_window.step5_panel.csv_file.get_path()
|
||||||
if step5_csv:
|
if step5_csv:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(step5_csv):
|
||||||
|
step5_csv = os.path.join(self.work_dir or '', step5_csv).replace('\\', '/')
|
||||||
self.training_data_widget.set_path(step5_csv)
|
self.training_data_widget.set_path(step5_csv)
|
||||||
|
|
||||||
# 如果上述都没找到,尝试从 pipeline.step_outputs 回退
|
# 如果上述都没找到,尝试从 pipeline.step_outputs 回退
|
||||||
|
|||||||
@ -170,9 +170,15 @@ class Step5Panel(QWidget):
|
|||||||
mask_path = main_window.step1_panel.output_file.get_path()
|
mask_path = main_window.step1_panel.output_file.get_path()
|
||||||
else:
|
else:
|
||||||
mask_path = main_window.step1_panel.mask_file.get_path()
|
mask_path = main_window.step1_panel.mask_file.get_path()
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if mask_path and not os.path.isabs(mask_path):
|
||||||
|
mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/')
|
||||||
|
|
||||||
# 填充水体掩膜路径
|
# 填充水体掩膜路径
|
||||||
if mask_path:
|
if mask_path:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(mask_path):
|
||||||
|
mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/')
|
||||||
self.water_mask_file.set_path(mask_path)
|
self.water_mask_file.set_path(mask_path)
|
||||||
|
|
||||||
# 3. 尝试从 Step2 界面读取耀斑掩膜路径
|
# 3. 尝试从 Step2 界面读取耀斑掩膜路径
|
||||||
@ -180,6 +186,9 @@ class Step5Panel(QWidget):
|
|||||||
if hasattr(main_window, 'step2_panel'):
|
if hasattr(main_window, 'step2_panel'):
|
||||||
glint_path = main_window.step2_panel.output_file.get_path()
|
glint_path = main_window.step2_panel.output_file.get_path()
|
||||||
if glint_path:
|
if glint_path:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(glint_path):
|
||||||
|
glint_path = os.path.join(self.work_dir or '', glint_path).replace('\\', '/')
|
||||||
self.glint_mask_file.set_path(glint_path)
|
self.glint_mask_file.set_path(glint_path)
|
||||||
|
|
||||||
# 4. 自动填充输出路径(基于工作目录)
|
# 4. 自动填充输出路径(基于工作目录)
|
||||||
@ -196,6 +205,9 @@ class Step5Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step4_panel'):
|
if main_window and hasattr(main_window, 'step4_panel'):
|
||||||
step4_output_path = main_window.step4_panel.output_file.get_path()
|
step4_output_path = main_window.step4_panel.output_file.get_path()
|
||||||
if step4_output_path:
|
if step4_output_path:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(step4_output_path):
|
||||||
|
step4_output_path = os.path.join(self.work_dir or '', step4_output_path).replace('\\', '/')
|
||||||
existing_csv = self.csv_file.get_path()
|
existing_csv = self.csv_file.get_path()
|
||||||
if not existing_csv or not existing_csv.strip():
|
if not existing_csv or not existing_csv.strip():
|
||||||
self.csv_file.set_path(step4_output_path)
|
self.csv_file.set_path(step4_output_path)
|
||||||
|
|||||||
@ -230,6 +230,9 @@ class Step6_5Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step5_panel'):
|
if main_window and hasattr(main_window, 'step5_panel'):
|
||||||
step5_output_path = main_window.step5_panel.output_file.get_path()
|
step5_output_path = main_window.step5_panel.output_file.get_path()
|
||||||
if step5_output_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.training_csv_file.get_path()
|
existing = self.training_csv_file.get_path()
|
||||||
if not existing or not existing.strip():
|
if not existing or not existing.strip():
|
||||||
self.training_csv_file.set_path(step5_output_path)
|
self.training_csv_file.set_path(step5_output_path)
|
||||||
|
|||||||
@ -148,7 +148,7 @@ class Step6_75Panel(QWidget):
|
|||||||
output_layout = QFormLayout()
|
output_layout = QFormLayout()
|
||||||
|
|
||||||
self.output_dir = QLineEdit()
|
self.output_dir = QLineEdit()
|
||||||
self.output_dir.setText("9_Custom_Regression_Modeling")
|
self.output_dir.setText("") # 路径由 update_from_config 根据 work_dir 自动填充
|
||||||
output_layout.addRow("输出目录名:", self.output_dir)
|
output_layout.addRow("输出目录名:", self.output_dir)
|
||||||
|
|
||||||
output_group.setLayout(output_layout)
|
output_group.setLayout(output_layout)
|
||||||
@ -299,6 +299,9 @@ class Step6_75Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step5_panel'):
|
if main_window and hasattr(main_window, 'step5_panel'):
|
||||||
step5_output_path = main_window.step5_panel.output_file.get_path()
|
step5_output_path = main_window.step5_panel.output_file.get_path()
|
||||||
if step5_output_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()
|
existing = self.csv_file.get_path()
|
||||||
if not existing or not existing.strip():
|
if not existing or not existing.strip():
|
||||||
self.csv_file.set_path(step5_output_path)
|
self.csv_file.set_path(step5_output_path)
|
||||||
|
|||||||
@ -298,12 +298,15 @@ class Step6Panel(QWidget):
|
|||||||
else:
|
else:
|
||||||
self.work_dir = None
|
self.work_dir = None
|
||||||
|
|
||||||
# 1. 尝试从 Step5 界面读取训练数据路径
|
# 1. 尝试从 Step5 界面读取训练数据路径,并确保为绝对路径
|
||||||
main_window = self.window()
|
main_window = self.window()
|
||||||
if hasattr(main_window, 'step5_panel'):
|
if hasattr(main_window, 'step5_panel'):
|
||||||
# 优先直接从 Step5 的输出 widget 读取
|
# 优先直接从 Step5 的输出 widget 读取
|
||||||
step5_output = main_window.step5_panel.output_file.get_path()
|
step5_output = main_window.step5_panel.output_file.get_path()
|
||||||
if step5_output:
|
if step5_output:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(step5_output):
|
||||||
|
step5_output = os.path.join(self.work_dir or '', step5_output).replace('\\', '/')
|
||||||
self.training_csv_file.set_path(step5_output)
|
self.training_csv_file.set_path(step5_output)
|
||||||
elif hasattr(main_window, 'step5_panel') and hasattr(main_window.step5_panel, 'get_config'):
|
elif hasattr(main_window, 'step5_panel') and hasattr(main_window.step5_panel, 'get_config'):
|
||||||
# 回退:从 Step5 的 config 字典中查找可能的键名
|
# 回退:从 Step5 的 config 字典中查找可能的键名
|
||||||
@ -315,6 +318,9 @@ class Step6Panel(QWidget):
|
|||||||
or step5_cfg.get('output_csv')
|
or step5_cfg.get('output_csv')
|
||||||
)
|
)
|
||||||
if step5_csv:
|
if step5_csv:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(step5_csv):
|
||||||
|
step5_csv = os.path.join(self.work_dir or '', step5_csv).replace('\\', '/')
|
||||||
self.training_csv_file.set_path(step5_csv)
|
self.training_csv_file.set_path(step5_csv)
|
||||||
|
|
||||||
# 2. 自动填充输出文件路径(基于工作目录和输入文件名)
|
# 2. 自动填充输出文件路径(基于工作目录和输入文件名)
|
||||||
|
|||||||
@ -145,6 +145,9 @@ class Step7Panel(QWidget):
|
|||||||
deglint_path = main_window.step3_panel.output_file.get_path()
|
deglint_path = main_window.step3_panel.output_file.get_path()
|
||||||
|
|
||||||
if deglint_path:
|
if deglint_path:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(deglint_path):
|
||||||
|
deglint_path = os.path.join(self.work_dir or '', deglint_path).replace('\\', '/')
|
||||||
self.deglint_img_file.set_path(deglint_path)
|
self.deglint_img_file.set_path(deglint_path)
|
||||||
|
|
||||||
# 2. 填充水域掩膜路径(优先从 pipeline.step_outputs 获取绝对路径)
|
# 2. 填充水域掩膜路径(优先从 pipeline.step_outputs 获取绝对路径)
|
||||||
@ -161,6 +164,9 @@ class Step7Panel(QWidget):
|
|||||||
water_mask_path = main_window.step1_panel.output_file.get_path()
|
water_mask_path = main_window.step1_panel.output_file.get_path()
|
||||||
|
|
||||||
if water_mask_path:
|
if water_mask_path:
|
||||||
|
# 若为相对路径,使用 work_dir 合成为绝对路径
|
||||||
|
if not os.path.isabs(water_mask_path):
|
||||||
|
water_mask_path = os.path.join(self.work_dir or '', water_mask_path).replace('\\', '/')
|
||||||
self.water_mask_file.set_path(water_mask_path)
|
self.water_mask_file.set_path(water_mask_path)
|
||||||
|
|
||||||
# 3. 自动填充输出路径(绝对路径)
|
# 3. 自动填充输出路径(绝对路径)
|
||||||
|
|||||||
@ -102,6 +102,9 @@ class Step8_5Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step7_panel'):
|
if main_window and hasattr(main_window, 'step7_panel'):
|
||||||
step7_output_path = main_window.step7_panel.output_file.get_path()
|
step7_output_path = main_window.step7_panel.output_file.get_path()
|
||||||
if step7_output_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()
|
existing = self.sampling_csv_file.get_path()
|
||||||
if not existing or not existing.strip():
|
if not existing or not existing.strip():
|
||||||
self.sampling_csv_file.set_path(step7_output_path)
|
self.sampling_csv_file.set_path(step7_output_path)
|
||||||
@ -110,6 +113,9 @@ class Step8_5Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step6_5_panel'):
|
if main_window and hasattr(main_window, 'step6_5_panel'):
|
||||||
step6_5_models_dir = main_window.step6_5_panel.output_dir.get_path()
|
step6_5_models_dir = main_window.step6_5_panel.output_dir.get_path()
|
||||||
if step6_5_models_dir:
|
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()
|
existing_models = self.models_dir_file.get_path()
|
||||||
if not existing_models or not existing_models.strip():
|
if not existing_models or not existing_models.strip():
|
||||||
self.models_dir_file.set_path(step6_5_models_dir)
|
self.models_dir_file.set_path(step6_5_models_dir)
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class Step8_75Panel(QWidget):
|
|||||||
self.regression_models_dir.label.setText("回归模型目录:")
|
self.regression_models_dir.label.setText("回归模型目录:")
|
||||||
self.regression_models_dir.browse_btn.clicked.disconnect()
|
self.regression_models_dir.browse_btn.clicked.disconnect()
|
||||||
self.regression_models_dir.browse_btn.clicked.connect(self.browse_regression_models_dir)
|
self.regression_models_dir.browse_btn.clicked.connect(self.browse_regression_models_dir)
|
||||||
self.regression_models_dir.set_path("9_Custom_Regression_Modeling")
|
self.regression_models_dir.set_path("") # 路径由 update_from_config 根据 work_dir 自动填充
|
||||||
layout.addWidget(self.regression_models_dir)
|
layout.addWidget(self.regression_models_dir)
|
||||||
|
|
||||||
# 公式CSV文件选择(用于查找index_formula)
|
# 公式CSV文件选择(用于查找index_formula)
|
||||||
@ -95,6 +95,9 @@ class Step8_75Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step7_panel'):
|
if main_window and hasattr(main_window, 'step7_panel'):
|
||||||
step7_output_path = main_window.step7_panel.output_file.get_path()
|
step7_output_path = main_window.step7_panel.output_file.get_path()
|
||||||
if step7_output_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()
|
existing = self.sampling_csv_file.get_path()
|
||||||
if not existing or not existing.strip():
|
if not existing or not existing.strip():
|
||||||
self.sampling_csv_file.set_path(step7_output_path)
|
self.sampling_csv_file.set_path(step7_output_path)
|
||||||
@ -103,11 +106,21 @@ class Step8_75Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step6_75_panel'):
|
if main_window and hasattr(main_window, 'step6_75_panel'):
|
||||||
step6_75_models_dir = main_window.step6_75_panel.output_dir.text().strip()
|
step6_75_models_dir = main_window.step6_75_panel.output_dir.text().strip()
|
||||||
if step6_75_models_dir:
|
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()
|
existing_models = self.regression_models_dir.get_path()
|
||||||
if not existing_models or not existing_models.strip():
|
if not existing_models or not existing_models.strip():
|
||||||
self.regression_models_dir.set_path(step6_75_models_dir)
|
self.regression_models_dir.set_path(step6_75_models_dir)
|
||||||
|
|
||||||
# 3. 自动填充输出目录(自定义回归预测目录)
|
# 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:
|
if self.work_dir:
|
||||||
output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Custom_Regression_Prediction")
|
output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Custom_Regression_Prediction")
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|||||||
@ -99,6 +99,9 @@ class Step8Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step7_panel'):
|
if main_window and hasattr(main_window, 'step7_panel'):
|
||||||
step7_output_path = main_window.step7_panel.output_file.get_path()
|
step7_output_path = main_window.step7_panel.output_file.get_path()
|
||||||
if step7_output_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()
|
existing = self.sampling_csv_file.get_path()
|
||||||
if not existing or not existing.strip():
|
if not existing or not existing.strip():
|
||||||
self.sampling_csv_file.set_path(step7_output_path)
|
self.sampling_csv_file.set_path(step7_output_path)
|
||||||
@ -107,6 +110,9 @@ class Step8Panel(QWidget):
|
|||||||
if main_window and hasattr(main_window, 'step6_panel'):
|
if main_window and hasattr(main_window, 'step6_panel'):
|
||||||
step6_models_dir = main_window.step6_panel.output_dir.get_path()
|
step6_models_dir = main_window.step6_panel.output_dir.get_path()
|
||||||
if step6_models_dir:
|
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()
|
existing_models = self.models_dir_file.get_path()
|
||||||
if not existing_models or not existing_models.strip():
|
if not existing_models or not existing_models.strip():
|
||||||
self.models_dir_file.set_path(step6_models_dir)
|
self.models_dir_file.set_path(step6_models_dir)
|
||||||
|
|||||||
@ -324,12 +324,18 @@ class Step9Panel(QWidget):
|
|||||||
if hasattr(main_window, 'step8_panel'):
|
if hasattr(main_window, 'step8_panel'):
|
||||||
step8_output = main_window.step8_panel.output_file.get_path()
|
step8_output = main_window.step8_panel.output_file.get_path()
|
||||||
if step8_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)
|
pred_dir = str(Path(step8_output).parent)
|
||||||
|
|
||||||
# 2. 备选:从 Step8.5 界面读取非经验预测输出目录
|
# 2. 备选:从 Step8.5 界面读取非经验预测输出目录
|
||||||
if not pred_dir and hasattr(main_window, 'step8_5_panel'):
|
if not pred_dir and hasattr(main_window, 'step8_5_panel'):
|
||||||
step8_5_output = main_window.step8_5_panel.output_file.get_path()
|
step8_5_output = main_window.step8_5_panel.output_file.get_path()
|
||||||
if step8_5_output:
|
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)
|
pred_dir = str(Path(step8_5_output).parent)
|
||||||
|
|
||||||
# 3. 备选:从 Step8.75 界面读取自定义回归预测输出目录
|
# 3. 备选:从 Step8.75 界面读取自定义回归预测输出目录
|
||||||
|
|||||||
Reference in New Issue
Block a user