fix(step7): 去除耀斑路径智能回溯 — .dat占位符自动拦截改为glob搜索3_deglint真实.bsq产物

This commit is contained in:
DXC
2026-05-10 16:34:04 +08:00
parent 6d4d802ffe
commit d15a7a1e2b

View File

@ -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
)