|
@@ -30,30 +30,50 @@ class DataProcessor:
|
|
|
|
|
|
def load_predictions(self):
|
|
|
"""
|
|
|
- 加载模型预测结果
|
|
|
+ 加载模型预测结果(根据WORKFLOW_CONFIG配置)
|
|
|
|
|
|
@return: 包含预测结果的字典
|
|
|
"""
|
|
|
try:
|
|
|
predictions = {}
|
|
|
|
|
|
+ # 动态读取当前的工作流配置(运行时可能被修改)
|
|
|
+ workflow_config = self._get_current_workflow_config()
|
|
|
+ self.logger.info(f"当前工作流配置: {workflow_config}")
|
|
|
+
|
|
|
+ # 只加载在工作流配置中启用的模型的预测结果
|
|
|
# 加载作物Cd预测结果
|
|
|
- crop_cd_path = os.path.join(
|
|
|
- config.DATA_PATHS["predictions_dir"],
|
|
|
- config.CROP_CD_MODEL["output_file"]
|
|
|
- )
|
|
|
- if os.path.exists(crop_cd_path):
|
|
|
- predictions['crop_cd'] = pd.read_csv(crop_cd_path)
|
|
|
- self.logger.info(f"作物Cd预测结果加载成功: {crop_cd_path}")
|
|
|
+ if workflow_config.get("run_crop_model", False):
|
|
|
+ crop_cd_path = os.path.join(
|
|
|
+ config.DATA_PATHS["predictions_dir"],
|
|
|
+ config.CROP_CD_MODEL["output_file"]
|
|
|
+ )
|
|
|
+ if os.path.exists(crop_cd_path):
|
|
|
+ predictions['crop_cd'] = pd.read_csv(crop_cd_path)
|
|
|
+ self.logger.info(f"作物Cd预测结果加载成功: {crop_cd_path}")
|
|
|
+ else:
|
|
|
+ self.logger.warning(f"作物Cd预测文件不存在: {crop_cd_path}")
|
|
|
+ else:
|
|
|
+ self.logger.info("跳过作物Cd预测结果加载(工作流配置中未启用)")
|
|
|
|
|
|
# 加载有效态Cd预测结果
|
|
|
- effective_cd_path = os.path.join(
|
|
|
- config.DATA_PATHS["predictions_dir"],
|
|
|
- config.EFFECTIVE_CD_MODEL["output_file"]
|
|
|
- )
|
|
|
- if os.path.exists(effective_cd_path):
|
|
|
- predictions['effective_cd'] = pd.read_csv(effective_cd_path)
|
|
|
- self.logger.info(f"有效态Cd预测结果加载成功: {effective_cd_path}")
|
|
|
+ if workflow_config.get("run_effective_model", False):
|
|
|
+ effective_cd_path = os.path.join(
|
|
|
+ config.DATA_PATHS["predictions_dir"],
|
|
|
+ config.EFFECTIVE_CD_MODEL["output_file"]
|
|
|
+ )
|
|
|
+ if os.path.exists(effective_cd_path):
|
|
|
+ predictions['effective_cd'] = pd.read_csv(effective_cd_path)
|
|
|
+ self.logger.info(f"有效态Cd预测结果加载成功: {effective_cd_path}")
|
|
|
+ else:
|
|
|
+ self.logger.warning(f"有效态Cd预测文件不存在: {effective_cd_path}")
|
|
|
+ else:
|
|
|
+ self.logger.info("跳过有效态Cd预测结果加载(工作流配置中未启用)")
|
|
|
+
|
|
|
+ if not predictions:
|
|
|
+ self.logger.warning("没有加载到任何预测结果,请检查WORKFLOW_CONFIG配置和预测文件是否存在")
|
|
|
+ else:
|
|
|
+ self.logger.info(f"根据工作流配置,成功加载了 {len(predictions)} 个模型的预测结果: {list(predictions.keys())}")
|
|
|
|
|
|
return predictions
|
|
|
|
|
@@ -61,6 +81,37 @@ class DataProcessor:
|
|
|
self.logger.error(f"预测结果加载失败: {str(e)}")
|
|
|
raise
|
|
|
|
|
|
+ def _get_current_workflow_config(self):
|
|
|
+ """
|
|
|
+ 动态读取当前的工作流配置
|
|
|
+
|
|
|
+ @return: 当前的工作流配置字典
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ config_file = os.path.join(config.PROJECT_ROOT, "config.py")
|
|
|
+
|
|
|
+ # 读取配置文件内容
|
|
|
+ with open(config_file, 'r', encoding='utf-8') as f:
|
|
|
+ config_content = f.read()
|
|
|
+
|
|
|
+ # 提取WORKFLOW_CONFIG
|
|
|
+ import re
|
|
|
+ pattern = r'WORKFLOW_CONFIG\s*=\s*(\{[^}]*\})'
|
|
|
+ match = re.search(pattern, config_content)
|
|
|
+
|
|
|
+ if match:
|
|
|
+ # 使用eval安全地解析配置(这里是安全的,因为我们控制配置文件内容)
|
|
|
+ workflow_config_str = match.group(1)
|
|
|
+ workflow_config = eval(workflow_config_str)
|
|
|
+ return workflow_config
|
|
|
+ else:
|
|
|
+ self.logger.warning("无法从配置文件中提取WORKFLOW_CONFIG,使用默认配置")
|
|
|
+ return config.WORKFLOW_CONFIG
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ self.logger.error(f"读取工作流配置失败: {str(e)},使用默认配置")
|
|
|
+ return config.WORKFLOW_CONFIG
|
|
|
+
|
|
|
def load_coordinates(self):
|
|
|
"""
|
|
|
加载坐标数据
|