- 新增 6 个 Handler:Step2GlintDetection / Step3GlintRemoval / Step4Sampling / Step5ProcessCsv / Step6ExtractSpectra / Step7CalcIndices - 新增 register_handlers.py:register_all_handlers() 一键注册 Step1~Step7 - 更新 __init__.py:导出全部 7 个 Handler - 重构 worker_thread.py:移除旧 WaterQualityInversionPipeline 导入,改用 PipelineScheduler + register_all_handlers - run_single_step 改为 scheduler.run_step() 调用,保留外部模型透传逻辑
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
Step4 处理器:预测采样点生成
|
||
|
||
将原 WaterQualityInversionPipeline.step4_sampling() 方法
|
||
剥离为独立的 Step4SamplingHandler。
|
||
"""
|
||
|
||
import time
|
||
from typing import Any, Dict
|
||
|
||
from src.core.handlers.base import BaseStepHandler, PipelineContext
|
||
from src.core.steps.prediction_step import PredictionStep
|
||
|
||
|
||
class Step4SamplingHandler(BaseStepHandler):
|
||
"""步骤4:生成预测采样点并提取光谱。
|
||
|
||
对应 config key: 'step4_sampling'
|
||
委托类: PredictionStep.generate_sampling_points()
|
||
"""
|
||
|
||
step_key = 'step4_sampling'
|
||
|
||
def execute(self, context: PipelineContext, config: dict) -> Dict[str, Any]:
|
||
step_start_time = time.time()
|
||
|
||
deglint_img_path = self._resolve_path(
|
||
config.get('deglint_img_path'), context.deglint_img_path, 'deglint_img'
|
||
)
|
||
water_mask_path = self._resolve_path(
|
||
config.get('water_mask_path'), context.water_mask_path, 'water_mask'
|
||
)
|
||
glint_mask_path = self._resolve_path(
|
||
config.get('glint_mask_path'), context.glint_mask_path, 'glint_mask'
|
||
)
|
||
|
||
try:
|
||
result = PredictionStep.generate_sampling_points(
|
||
deglint_img_path=deglint_img_path,
|
||
interval=config.get('interval', 50),
|
||
sample_radius=config.get('sample_radius', 5),
|
||
chunk_size=config.get('chunk_size', 1000),
|
||
water_mask_path=water_mask_path,
|
||
glint_mask_path=glint_mask_path,
|
||
output_dir=str(context.sampling_dir),
|
||
use_adaptive_sampling=config.get('use_adaptive_sampling', True),
|
||
)
|
||
|
||
step_end_time = time.time()
|
||
context.record_step_time(
|
||
"步骤4: 生成预测采样点", step_start_time, step_end_time
|
||
)
|
||
|
||
return {'sampling_csv_path': result}
|
||
|
||
except Exception as e:
|
||
step_end_time = time.time()
|
||
context.record_step_time(
|
||
"步骤4: 生成预测采样点", step_start_time, step_end_time,
|
||
status="failed", error=str(e)
|
||
)
|
||
raise
|