liveBook · Manning

Piping and instrumentation diagram

As explained in Digital Twins in Action

A piping diagram is a technical drawing showing the pipes, connected equipment, and flow relationships in a process or facility.

A piping and instrumentation diagram (P&ID) is an engineering drawing that uses standardized symbols to show relationships among equipment, piping, and instruments. It gives a more detailed engineering view than a process flow diagram, which maps the sequence of process actions and material flows. section 2.3.4

A P&ID emphasizes topology—how components connect—rather than their physical locations. This abstraction makes system logic easier to understand than an accurate 3D layout when the operational question is how equipment and instruments interact. section 6.2.3

Figure 2.6 A sample piping and instrumentation diagram (P&ID) showing how complex physical systems can be represented logically. Source: Wikipedia. Licensed under CC BY-SA 3.0
figure

The sample P&ID shows how a physical system can be represented as a logical diagram. section 2.3.4

P&IDs can support digital twins in two ways: their symbols and relationships can be digitized into a structured model, and diagram identifiers can be linked to organizational information. For example, an interactive P&ID can connect equipment and instrument identifiers to time-series data sources. section 2.3.4 section 6.2.3

Extracting a structured representation

A vision-capable model can process a P&ID image and return JSON describing equipment, instruments, lines, and control systems. One example identifies a storage tank as T001 and records its dimensions, design conditions, and an inlet connection. This output is a candidate extraction, not a verified model. section 2.3.4

Listing 2.4 Transforming P&ID document to JSON representation with Claude Sonnet 4
import base64, requests

def analyze_image(api_key, image_path, prompt):
  with open(image_path, "rb") as f:
    image_data = base64.b64encode(f.read()).decode('utf-8')

  response = requests.post(
    "https://api.anthropic.com/v1/messages",
    headers={
      "x-api-key": api_key,
      "anthropic-version": "2023-06-01",
      "content-type": "application/json"
    },
    json={
      "model": "claude-sonnet-4-20250514",
      "max_tokens": 5000,  #1
      "messages": [{
        "role": "user",
        "content": [
          {"type": "text", "text": prompt},
          {"type": "image", "source": {
            "type": "base64",
            "media_type": "image/png",
            "data": image_data
          }}
        ]
      }]
    }
  )
  return response.json()["content"][0]["text"]

api_key = "sk_***"

result = analyze_image(
  api_key,
  "images/pid.png",
  "Convert this diagram to JSON"  #2
 )

The Python listing sends a base64-encoded PNG and a prompt to Claude Sonnet 4 for analysis. section 2.3.4

Scanned documents may contain revision layers, handwritten annotations, overlapping symbols, or ambiguous elements. Have a domain expert validate computer-vision and LLM extractions, and align the resulting data with interoperable standards rather than relying on ad hoc JSON alone. section 2.3.4

Figure 6.7 A P&ID in Cognite Data Fusion™ showing equipment on the Valhall oil production platform. Image © Cognite™ (https://www.cognite.com/en), reproduced with permission.
figure

An interactive P&ID illustrates a schematic view of equipment on an oil production platform. section 6.2.3

How Digital Twins in Action covers it

How deep it goes
Defines the diagram and demonstrates image-to-JSON extraction and contextualized visualization, while requiring expert validation of extracted data.
Examples
Uses a tank-and-pump diagram, a storage-tank JSON extraction, and an interactive oil-platform P&ID.
What you can do after
Evaluate candidate P&ID extractions and recognize their need for expert validation and alignment with interoperable standards.
How it connects
Connects P&IDs with process flow diagrams, digital twins, computer vision, data contextualization, and time-series data.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Digital Twins in Action. The section links point to the parts of the book it draws on.