Skip to main content

Tools for visualizing and analyzing electrical grid network topology

Project description

Network Visualization

PyPI Python License

Interactive visualization and analysis tools for Calliope energy system models. Extract and visualize network topology with a single line of code.

โœจ Features

  • Universal Data Extraction: Handles ANY Calliope naming structure and format
  • One-Line Visualization: Create interactive HTML visualizations instantly
  • Connectivity Analysis: Identify isolated nodes and network components
  • Flexible Format Support: Works with any coordinate system (lat/lon, x/y, custom)
  • Smart Type Detection: Automatically classifies generation, demand, and transmission nodes

๐Ÿš€ Quick Start

Installation

pip install network-visualization

That's it! No configuration needed.

Usage in Your Script

Option 1: Single import, one line

import network_visualization as nv

# Visualize (creates interactive HTML file)
nv.plot_network("path/to/your/calliope/model")

Option 2: Complete analysis

import network_visualization as nv

# Analyze your model
results = nv.analyze_network("path/to/your/calliope/model")

# Check results
print(f"Network has {results['num_components']} components")
print(f"Isolated nodes: {results['isolated_nodes']}")

Option 3: Copy-paste ready example

# Save this as visualize.py and run: python visualize.py
import network_visualization as nv

# Replace with your model path
MODEL_PATH = "C:/path/to/your/calliope/model"

# Create visualization
nv.plot_network(
    model_path=MODEL_PATH,
    output_file="my_network.html",
    title="My Energy Network"
)

print("โœ“ Visualization saved as my_network.html")

Real Example with Your Model

import network_visualization as nv

# Your model path (where locations.yaml is located)
model_path = "C:/Users/YourName/my_calliope_model"

# Option A: Quick visualization
nv.quick_viz(model_path)  # Opens in browser automatically

# Option B: Detailed analysis
analysis = nv.analyze_network(model_path)
print(f"Total locations: {analysis['total_nodes']}")
print(f"Total connections: {analysis['total_edges']}")
print(f"Network components: {analysis['num_components']}")
print(f"Isolated nodes: {analysis['isolated_nodes']}")

๐Ÿ“– Complete API Reference

All Functions

import network_visualization as nv

# Main functions (most commonly used)
nv.plot_network(model_path, ...)        # Create visualization
nv.analyze_network(model_path, ...)     # Analyze connectivity
nv.quick_viz(model_path)                # Fast visualization
nv.find_isolated_nodes(model_path)      # Find isolated nodes
nv.suggest_connections(model_path, ...) # Get connection suggestions

plot_network() - Create Visualization

Simple usage:

nv.plot_network("path/to/model")  # Creates network_visualization.html

Advanced usage:

nv.plot_network(
    model_path="C:/my_models/chile",    # Required: your model path
    output_file="my_network.html",       # Optional: output filename
    auto_open=True,                      # Optional: open in browser
    title="Chile Energy Network"         # Optional: custom title
)

Returns: String with path to created HTML file


analyze_network() - Analyze Connectivity

Simple usage:

results = nv.analyze_network("path/to/model")
print(results['num_components'])   # How many disconnected parts
print(results['isolated_nodes'])   # List of isolated nodes

Advanced usage:

results = nv.analyze_network(
    model_path="C:/my_models/chile",
    save_report=True,                  # Save report to file
    output_dir="my_reports"            # Where to save report
)

**Returns:** Dictionary with analysis results:
```python
{
    'num_components': int,         # Number of connected components
    'isolated_nodes': list,        # List of isolated node names
    'demand_isolated': set,        # Demand substations that are isolated
    'is_fully_connected': bool,    # Whether network is fully connected
    'total_nodes': int,            # Total nodes in graph
    'total_edges': int,            # Total edges in graph
    'components': list             # List of component sets
}

find_isolated_nodes(model_path)

Find all isolated nodes in the network.

Returns: Dictionary with isolated node lists:

{
    'all_isolated': list,          # All isolated nodes
    'isolated_with_demand': list   # Isolated nodes with demand
}

suggest_connections(model_path, max_distance_km, top_n)

Get smart connection suggestions based on proximity.

Parameters:

  • model_path (str): Path to Calliope model directory
  • max_distance_km (float, optional): Maximum connection distance. Default: 100
  • top_n (int, optional): Number of suggestions to return. Default: 10

Returns: List of suggested connections with distances


quick_viz(model_path)

Fastest way to visualize - one function call with all defaults.


๐ŸŽฏ Calliope Format Support

This package handles any Calliope model structure:

Standard Format

locations:
  region1:
    coordinates: {lat: 40, lon: -2}
    techs: {ccgt:, demand_power:}

Split Coordinates

locations:
  region1-1.coordinates:  # or region1:coords, region1_position, etc.
    lat: 41
    lon: -2

Shared Technologies

locations:
  "region1-1, region1-2, region1-3":  # or region1-1|region1-2|region1-3
    techs: {csp:}

Any Coordinate System

  • Geographic: lat/lon, latitude/longitude
  • Cartesian: x/y
  • Custom: Any numeric coordinate pairs

Flexible Naming

No restrictions on naming patterns:

  • Delimiters: ., :, _, -, |, ,
  • Suffixes: coordinates, coords, position, latlon, etc.
  • Patterns: Any naming convention (regions, nodes, stations, areas, etc.)

The parser automatically detects and handles all patterns!

๐Ÿ“Š Example Output

Visualization

Interactive HTML with:

  • Color-coded nodes (generation, demand, transmission)
  • Hover info showing technologies
  • Zoom and pan navigation
  • Network statistics overlay

Analysis Report

================================================================================
NETWORK ANALYSIS REPORT
================================================================================

1. NETWORK SUMMARY
   Total Locations: 9
     - Power Plants: 5
     - Substations with Demand: 0
     - Transmission Nodes: 1

   Total Connections: 9
     - Power Links: 2
     - Transmission Links: 7

2. CONNECTIVITY ANALYSIS
   Connected Components: 1
   [OK] Network is fully connected
   [OK] No isolated nodes

3. DEMAND SUBSTATIONS STATUS
   [OK] All demand substations are connected
================================================================================

๐Ÿ“ Project Structure

network_visualization/
โ”œโ”€โ”€ network_visualization.py    # Main API module
โ”œโ”€โ”€ setup.py                    # Package configuration
โ”œโ”€โ”€ requirements.txt            # Dependencies
โ”œโ”€โ”€ README.md                   # This file
โ”‚
โ”œโ”€โ”€ utils/                      # Core utilities
โ”‚   โ”œโ”€โ”€ load_data.py           # Universal data loader
โ”‚   โ”œโ”€โ”€ graph_builder.py       # Network graph construction
โ”‚   โ”œโ”€โ”€ geo_utils.py           # Geographic calculations
โ”‚   โ””โ”€โ”€ report_generator.py    # Report generation
โ”‚
โ”œโ”€โ”€ scripts/                    # Command-line tools
โ”‚   โ”œโ”€โ”€ visualize_network.py
โ”‚   โ”œโ”€โ”€ analyze_isolated.py
โ”‚   โ””โ”€โ”€ suggest_connections.py
โ”‚
โ””โ”€โ”€ examples/                   # Usage examples
    โ””โ”€โ”€ basic_visualization.py

๐Ÿ› ๏ธ Requirements

  • Python 3.8+
  • All dependencies install automatically with pip install network-visualization

โ“ Troubleshooting

"Module not found"

# Make sure it's installed in your current environment
pip install network-visualization

# Check installation
pip show network-visualization

"Can't find my model"

Make sure you point to the model directory (the folder containing model_config/):

# โœ“ Correct - points to model directory
nv.plot_network("C:/my_models/national_scale")

# โœ— Wrong - points to locations.yaml file
nv.plot_network("C:/my_models/national_scale/model_config/locations.yaml")

Model structure requirements

Your Calliope model should have this structure:

your_model/
โ””โ”€โ”€ model_config/
    โ””โ”€โ”€ locations.yaml    # Required

Import error in script

If you get import errors, use the full import:

import network_visualization as nv
# Not: from network_visualization import plot_network

Still having issues?

  1. Check Python version: python --version (needs 3.8+)
  2. Reinstall: pip uninstall network-visualization && pip install network-visualization
  3. Try the simple example from examples/simple_example.py

๐Ÿ“ Development

# Clone repository
git clone https://mygit.th-deg.de/thd-spatial-ai/example_models/calliope_plots.git
cd calliope_plots

# Install in development mode
pip install -e .

# Run tests
python -m pytest tests/

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Commit changes (git commit -m 'Add improvement')
  4. Push to branch (git push origin feature/improvement)
  5. Open a Pull Request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ”— Links

๐Ÿ™ Acknowledgments

Built for Calliope energy system modeling framework. Supports any Calliope model structure with universal data extraction.


Version: 1.0.1 | Updated: November 2025

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

network_visualization-1.0.2.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

network_visualization-1.0.2-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file network_visualization-1.0.2.tar.gz.

File metadata

  • Download URL: network_visualization-1.0.2.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for network_visualization-1.0.2.tar.gz
Algorithm Hash digest
SHA256 01d5d255ab30db77a3c7c4b4a6615b002b4b94a5d57a6d30d3de699a3d10081b
MD5 0a4eac31974b253243aecdc59b5ffa2d
BLAKE2b-256 a3adda58a12c7d073d418b61ab813ca0b6f2372f4cbe9a1f6492819d5e4406d4

See more details on using hashes here.

File details

Details for the file network_visualization-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for network_visualization-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cb3e93a233434ba79998b7e03a6f4807cbbeb0df91caac65720a6d262e42158b
MD5 0e64e0d91c3aec1887ad17a190929813
BLAKE2b-256 1f3a1d9ef9d13cf065df50e381ea132e491c1f1d2239d47617c487362161fa95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page