科研技能库/绘图技能
图表可视化
未发现用户侧风险

绘图技能

绘制并比较仿真汇总指标。当需要可视化时间序列结果、比较多方案或分析生产动态时使用。支持单指标和多指标绘图、方案对比以及自动指标关键字解析。

文件预览

7 个文件
assets
references
scripts
SKILL.md
5.6 KB · 可预览
---
name: plot_skill
description: Plot and compare simulation summary metrics. Use when visualizing time-series results, comparing multiple cases, or analyzing production performance. Supports single and multi-metric plots, case comparisons, and automatic metric keyword resolution.
license: Apache-2.0
metadata:
  author: sim-agent
  version: "1.0"
  category: simulator
compatibility: Requires matplotlib and simulation output files (.SMSPEC). Uses EclReader for summary (Apache-2.0).
---

# Plotting Skill

This skill provides tools for visualizing and comparing simulation results.

## Overview

The Plotting skill enables agents to:

- **Plot** summary metrics from simulation outputs
- **Compare** multiple cases on the same plot
- **Visualize** time-series data (rates, cumulative production, etc.)
- **Resolve** metric keywords automatically from user requests

## Tools

### plot_summary_metric

Plots one or more summary metrics from simulation outputs on the same plot.

**Usage:**
```python
plot_summary_metric(
    output_dir: str,
    metric_request: str,
    manual_hint: Optional[str] = None,
    save_path: Optional[str] = None
) -> str
```

**Parameters:**
- `output_dir`: Directory containing simulation output files (must contain .SMSPEC file)
- `metric_request`: User request or summary keyword(s). For multiple metrics on one plot, use comma-separated keywords (e.g., "FOPT, FWPT" or "FOPT,FWPT")
- `manual_hint`: Optional manual context or retrieved snippet to help map keywords
- `save_path`: Optional path to save the plot image

**Example:**
```
plot_summary_metric(
    output_dir="/path/to/output",
    metric_request="FOPT, FWPT",
    save_path="/path/to/plot.png"
)
```

**Returns:** Confirmation message with plot details and save path (if provided). Displays the plot.

**When to use:** 
- After simulation run when user asks to plot results (TOOL_DECISION_TREE.md Section 3.1)
- When user requests specific metrics (e.g., "Plot cumulative oil production")
- For visualizing time-series data from completed simulations

**Metric Keywords:**
Common summary keywords include:
- `FOPT`: Cumulative oil production
- `FOPR`: Oil production rate
- `FWPT`: Cumulative water production
- `FWPR`: Water production rate
- `FGPT`: Cumulative gas production
- `FGPR`: Gas production rate
- `WBHP`: Well bottom-hole pressure
- `WOPR`: Well oil production rate

### plot_compare_summary_metric

Plots a summary metric for two or more cases on the same axes for comparison.

**Usage:**
```python
plot_compare_summary_metric(
    output_dir: str,
    metric_request: str,
    case_stems: Optional[str] = None,
    case_paths: Optional[str] = None,
    save_path: Optional[str] = None
) -> str
```

**Parameters:**
- `output_dir`: Directory to save the plot and, when not using case_paths, directory containing .SMSPEC files to compare
- `metric_request`: Summary keyword to compare (e.g., "FOPT" for cumulative oil, "FOPR" for oil rate)
- `case_stems`: Comma-separated case name stems to compare (e.g., "SPE10_TOPLAYER,SPE10_TOPLAYER_AGENT_GENERATED"). If omitted and case_paths not set, all .SMSPEC files in output_dir are compared.
- `case_paths`: Comma-separated paths to simulator input files (or .SMSPEC) for the cases to compare. Use when comparing cases from different directories (e.g., "BASE/SPE10.DATA,INFILL/SPE10_INFILL.DATA").
- `save_path`: Optional path to save the comparison plot image

**Example:**
```
plot_compare_summary_metric(
    output_dir="/path/to/output",
    metric_request="FOPT",
    case_stems="SPE10_TOPLAYER,SPE10_TOPLAYER_AGENT_GENERATED"
)
```

**Returns:** Confirmation message with comparison plot details and save path (if provided). Displays the plot with different line styles for each case.

**When to use:**
- After running multiple cases when user asks to compare (Section 3.1)
- For comparing baseline vs modified scenarios
- When analyzing differences between simulation cases

## Workflow Integration

This skill integrates with the Simulator Agent's decision tree (TOOL_DECISION_TREE.md):

1. **Plot Results (Section 3.1):**
   ```
   User asks to plot → plot_summary_metric (if run_and_heal exists in history)
   ```

2. **Compare Cases (Section 3.1):**
   ```
   User asks to compare → plot_compare_summary_metric (if multiple cases available)
   ```

3. **After Simulation (Section 3.3):**
   ```
   run_and_heal → summarize → "Do you want me to plot the results?"
   ```

## Implementation Details

Tools are implemented as LangChain tools with Pydantic input schemas. The skill uses:

- **EclReader**: Apache-2.0 reader for .SMSPEC/.UNSMRY summary files
- **Matplotlib**: For generating plots
- **Metric resolution**: Automatic keyword mapping from user requests
- **Time axis handling**: Supports both date-based and step-based time axes

## Error Handling

All tools return descriptive error messages if:
- Output directories are not found
- .SMSPEC files are missing
- Requested metrics are not available
- Case files cannot be found
- Plot generation fails

## Metric Resolution

The tool automatically resolves metric keywords from user requests:
- Direct keywords (e.g., "FOPT") are used as-is
- Natural language (e.g., "cumulative oil production") is mapped to keywords
- Manual hints from `simulator_manual` can help with keyword mapping
- Multiple metrics can be plotted together using comma-separated keywords

## References

- [Tool Decision Tree](references/TOOL_DECISION_TREE.md) - Routing logic
- [Simulation Tools README](../../tools/README.md) - Detailed tool documentation

SKILL.md

元数据
nameplot_skill
description绘制并比较仿真汇总指标。当需要可视化时间序列结果、比较多方案或分析生产动态时使用。支持单指标和多指标绘图、方案对比以及自动指标关键字解析。
licenseApache-2.0
metadata{ "author": "sim-agent", "version": "1.0", "category": "simulator" }
compatibility需要 matplotlib 和仿真输出文件(.SMSPEC)。使用 EclReader 进行汇总读取(Apache-2.0)。

绘图技能

此技能提供了用于可视化和比较仿真结果的工具。

概览

绘图技能使智能体能够:

  • 绘制 仿真输出中的汇总指标
  • 对比 同一图表中的多个方案
  • 可视化 时间序列数据(产量速率、累计产量等)
  • 自动解析 用户请求中的指标关键词

工具

plot_summary_metric

在同一图表上绘制仿真输出中的一个或多个汇总指标。

用法:

python
plot_summary_metric(
    output_dir: str,
    metric_request: str,
    manual_hint: Optional[str] = None,
    save_path: Optional[str] = None
) -> str

参数:

  • output_dir: 包含仿真输出文件的目录(必须包含 .SMSPEC 文件)
  • metric_request: 用户请求或汇总关键词。如需在同一图上绘制多个指标,请使用逗号分隔的关键词(例如,“FOPT, FWPT” 或 “FOPT,FWPT”)
  • manual_hint: 可选的手动上下文或检索到的片段,用于辅助关键词映射
  • save_path: 可选的路径,用于保存绘图图像

示例:

text
plot_summary_metric(
    output_dir="/path/to/output",
    metric_request="FOPT, FWPT",
    save_path="/path/to/plot.png"
)

返回: 确认消息,包含绘图详情和保存路径(若提供)。显示绘图。

使用时机:

  • 仿真运行后,当用户要求绘制结果时(TOOL_DECISION_TREE.md 第 3.1 节)
  • 当用户请求特定指标时(例如,“绘制累计产油量”)
  • 用于可视化已完成仿真的时间序列数据

指标关键词: 常见的汇总关键词包括:

  • FOPT:累计产油量
  • FOPR:产油速率
  • FWPT:累计产水量
  • FWPR:产水速率
  • FGPT:累计产气量
  • FGPR:产气速率
  • WBHP:井底流压
  • WOPR:井产油速率

plot_compare_summary_metric

在同一坐标轴上绘制两个或多个方案的汇总指标以进行比较。

用法:

python
plot_compare_summary_metric(
    output_dir: str,
    metric_request: str,
    case_stems: Optional[str] = None,
    case_paths: Optional[str] = None,
    save_path: Optional[str] = None
) -> str

参数:

  • output_dir:保存绘图的目录,当不使用 case_paths 时,也是包含要比较的 .SMSPEC 文件的目录
  • metric_request:要比较的汇总关键词(例如,“FOPT” 表示累计产油,“FOPR” 表示产油速率)
  • case_stems:逗号分隔的要比较的方案名称主干(例如,“SPE10_TOPLAYER,SPE10_TOPLAYER_AGENT_GENERATED”)。如果省略且未设置 case_paths,则比较 output_dir 中的所有 .SMSPEC 文件。
  • case_paths:逗号分隔的仿真输入文件(或 .SMSPEC)路径,用于比较来自不同目录的方案(例如,“BASE/SPE10.DATA,INFILL/SPE10_INFILL.DATA”)。
  • save_path:可选的路径,用于保存对比绘图图像

示例:

text
plot_compare_summary_metric(
    output_dir="/path/to/output",
    metric_request="FOPT",
    case_stems="SPE10_TOPLAYER,SPE10_TOPLAYER_AGENT_GENERATED"
)

返回: 确认消息,包含对比绘图详情和保存路径(若提供)。显示绘图,不同方案使用不同线型。

使用时机:

  • 运行多个方案后,当用户要求进行比较时(第 3.1 节)
  • 用于比较基准方案和修改后的方案
  • 当分析不同仿真方案之间的差异时

工作流集成

此技能与仿真代理的决策树(TOOL_DECISION_TREE.md)集成:

  1. 绘制结果(第 3.1 节):

    text
    用户要求绘图 → plot_summary_metric(如果历史记录中存在 run_and_heal)
  2. 对比方案(第 3.1 节):

    text
    用户要求对比 → plot_compare_summary_metric(如果有多个方案可用)
  3. 仿真后(第 3.3 节):

    text
    run_and_heal → 总结 → “您需要我绘制结果吗?”

实现细节

工具以 LangChain 工具实现,使用 Pydantic 输入模式。该技能使用:

  • EclReader:用于 .SMSPEC/.UNSMRY 汇总文件的 Apache-2.0 读取器
  • Matplotlib:用于生成绘图
  • 指标解析:根据用户请求自动映射关键词
  • 时间轴处理:支持基于日期和基于步长的时间轴

错误处理

所有工具在以下情况下返回描述性错误消息:

  • 未找到输出目录
  • 缺少 .SMSPEC 文件
  • 请求的指标不可用
  • 找不到方案文件
  • 绘图生成失败

指标解析

该工具自动从用户请求中解析指标关键词:

  • 直接关键词(例如,“FOPT”)按原样使用
  • 自然语言(例如,“累计产油量”)被映射为关键词
  • 来自 simulator_manual 的手动提示可以帮助关键词映射
  • 可以使用逗号分隔的关键词将多个指标绘制在一起

参考