From d15a7a1e2b831baee42073e64b63371fdaf4bc14 Mon Sep 17 00:00:00 2001 From: DXC Date: Sun, 10 May 2026 16:34:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(step7):=20=E5=8E=BB=E9=99=A4=E8=80=80?= =?UTF-8?q?=E6=96=91=E8=B7=AF=E5=BE=84=E6=99=BA=E8=83=BD=E5=9B=9E=E6=BA=AF?= =?UTF-8?q?=20=E2=80=94=20.dat=E5=8D=A0=E4=BD=8D=E7=AC=A6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=8B=A6=E6=88=AA=E6=94=B9=E4=B8=BAglob=E6=90=9C?= =?UTF-8?q?=E7=B4=A23=5Fdeglint=E7=9C=9F=E5=AE=9E.bsq=E4=BA=A7=E7=89=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/steps/prediction_step.py | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/core/steps/prediction_step.py b/src/core/steps/prediction_step.py index 30c218c..333acdd 100644 --- a/src/core/steps/prediction_step.py +++ b/src/core/steps/prediction_step.py @@ -47,21 +47,47 @@ class PredictionStep: if deglint_img_path is None: raise ValueError("必须提供 deglint_img_path 参数") - # 强制后缀校验:无论用户 UI 传入 .dat/.tif/.bsq,统一规范为 .bsq - deglint_img_path = str(Path(deglint_img_path).with_suffix('.bsq')) + from pathlib import Path + import os + + # 1. 初始归一化与安全转换 + original_path = Path(deglint_img_path) + final_deglint_path = original_path + + # 2. 智能回溯探测:如果当前路径不存在,或者后缀是前端死板的 .dat + if not final_deglint_path.exists() or final_deglint_path.suffix.lower() == '.dat': + print(f"🔍 智能探测:输入去耀斑路径不存在或为 .dat 占位符 ({final_deglint_path}),正在向上搜索真实产物...") + + # 定位到预期的 3_deglint 根目录 + possible_dir = original_path.parent + if possible_dir.name != '3_deglint' and Path(output_path).parent.parent.exists(): + possible_dir = Path(output_path).parent.parent / "3_deglint" + + if possible_dir.exists(): + # 搜寻该目录下所有真实存在的 .bsq 文件(接管 goodman/sugar/kutser/hedley 的硬编码产物) + existing_bsqs = list(possible_dir.glob("*.bsq")) + if existing_bsqs: + final_deglint_path = existing_bsqs[0] + print(f"💡 智能拦截成功:自动寻回底层真实去耀斑影像: {final_deglint_path}") + else: + final_deglint_path = original_path.with_suffix('.bsq') + else: + final_deglint_path = original_path.with_suffix('.bsq') + + deglint_img_str = str(final_deglint_path) if Path(output_path).exists(): print(f"检测到已存在的采样点光谱数据文件,直接使用: {output_path}") notify("skipped", f"采样点光谱数据已设置: {output_path}") return output_path - # 允许外部显式传入 glint_mask_path 覆盖内部默认值 glint_mask_to_use = glint_mask_path if glint_mask_to_use is None: print("未检测到耀斑掩膜,将在采样点生成时不做耀斑区域剔除。") + # 传递极度安全的 deglint_img_str 进底层 get_spectral_sampling_points_chunked( - deglint_img_path, water_mask_path, glint_mask_to_use, + deglint_img_str, water_mask_path, glint_mask_to_use, output_path, interval, sample_radius, chunk_size )