Step10 Kriging 输出路径强制 14_visualization + Step11 掩膜自动填入

This commit is contained in:
DXC
2026-06-16 14:12:10 +08:00
parent 0238aa66ab
commit 5084f7d049
3 changed files with 176 additions and 7 deletions

View File

@ -1028,11 +1028,11 @@ class WaterQualityInversionPipeline:
skip_dependency_check: bool = False, **kwargs) -> str:
"""
步骤9: 根据采样点的坐标和反演的实测参数,以及水域掩膜,通过插值的方法,得到水质参数的可视化分布图
Args:
prediction_csv_path: 预测结果CSV文件路径前两列为经纬度第三列为预测值
boundary_shp_path: 边界shapefile文件路径
output_image_path: 输出图片路径(如果为None自动生成
output_image_path: 输出图片路径(已废弃:本函数强制写入 self.visualization_dir参数仅保留签名兼容
resolution: 插值网格分辨率(米)
input_crs: 输入坐标系
output_crs: 输出坐标系
@ -1044,13 +1044,34 @@ class WaterQualityInversionPipeline:
diffusion_n_neighbors: 距离扩散时使用的最近邻数量
cmap: 指定的颜色映射名称None表示自动识别
expand_ratio: 边界外扩比例0-1之间
Returns:
可视化分布图文件路径
可视化分布图文件路径(始终位于 self.visualization_dir 下)
"""
if output_image_path is None:
csv_name = Path(prediction_csv_path).stem
output_image_path = str(self.visualization_dir / f"{csv_name}_distribution.png")
# 修复所有分布图PNG与底层 Kriging 输出的派生文件必须落到 14_visualization。
# 不论调用方panel / 主流程 run_full_pipeline / 批量线程)传入什么路径,
# 都在此强制 override 为 self.visualization_dir规避
# (a) 调用方误传 prediction_dir (11_12_13_predictions) 之类错位路径
# (b) 老代码里硬编码字符串残留
# 若调用方传入的路径仍在 self.visualization_dir 内(子目录/不同文件名)则尊重其意图。
csv_name = Path(prediction_csv_path).stem
forced_image_path = str(self.visualization_dir / f"{csv_name}_distribution.png")
viz_dir_resolved = str(self.visualization_dir)
if output_image_path and output_image_path != forced_image_path:
# 判断调用方路径是否落在 visualization_dir 内(用 str.startswith 轻量检查)
norm_user = output_image_path.replace('\\', '/').rstrip('/')
norm_viz = viz_dir_resolved.replace('\\', '/').rstrip('/')
if not norm_user.startswith(norm_viz + '/') and norm_user != norm_viz:
print(
f"⚠️ [step10_map] 调用方传入 output_image_path={output_image_path!r} "
f"不在 {viz_dir_resolved} 下,强制重定向到 {forced_image_path}"
)
output_image_path = forced_image_path
else:
# 调用方路径已在 visualization_dir 内(如子目录),保留意图
output_image_path = output_image_path
else:
output_image_path = forced_image_path
self._notify("started", "步骤9: 生成水质参数可视化分布图")
result = MappingStep.generate_distribution_map(

View File

@ -566,6 +566,39 @@ class Step11MapPanel(QWidget):
if not existing_out or not existing_out.strip():
self.output_dir.set_path(output_dir)
# 4.5. 自动探测 Step1 水体掩膜(修复张冠李戴:原仅找 roi.shp找不到时未尝试 1_water_mask
# 优先调用 main_window.pipeline.get_step_output_dir('step1')(数据真实来源)
# 兜底走 resolve_subdir('water_mask') → <work_dir>/1_water_mask
# Step1 典型产物water_mask_from_ndwi.dat、water_mask_from_shp.dat、xxx.shp
if self.work_dir:
water_mask_dir = None
pipeline = None
try:
_win = self.window()
if _win is not None:
pipeline = getattr(_win, 'pipeline', None)
except Exception:
pipeline = None
if pipeline is not None and hasattr(pipeline, 'get_step_output_dir'):
try:
water_mask_dir = pipeline.get_step_output_dir('step1')
except Exception as e:
print(f"⚠️ [step11_map_panel] pipeline.get_step_output_dir('step1') 失败: {e}")
water_mask_dir = None
if not water_mask_dir:
water_mask_dir = resolve_subdir(self.work_dir, 'water_mask')
existing_boundary = (self.boundary_file.get_path() or "").strip()
if not existing_boundary and water_mask_dir and os.path.isdir(water_mask_dir):
# 优先 .shpgeopandas 读矢量最稳),其次 .dat
mask_candidates = (
sorted(Path(water_mask_dir).glob("*.shp"))
+ sorted(Path(water_mask_dir).glob("*.dat"))
)
if mask_candidates:
self.boundary_file.set_path(str(mask_candidates[0]))
print(f"✅ [step11_map_panel] 自动从 Step1 掩膜目录填入: {mask_candidates[0]}")
# 5. 自动探测原始矢量边界文件(.shp作为专题图底图
# 优先回溯 input-test/roi.shpgeopandas.read_file 仅支持矢量格式
if self.work_dir: