Tools for visualizing and analyzing electrical grid network topology
Project description
Network Visualization
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
- World Map Visualization: Global projection with natural earth map (NEW v1.0.3)
- Multi-File Import Support: Resolves Calliope
import:directives across files (NEW v1.0.3) - Scenarios & Overrides: Full support for Calliope scenarios and runtime overrides (NEW v1.0.3)
- 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 directorymax_distance_km(float, optional): Maximum connection distance. Default:100top_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.
๐ Advanced Features (v1.0.3)
Multi-File Imports
The package now automatically resolves Calliope import: directives across multiple files:
# model.yaml
import:
- locations.yaml
- techs.yaml
# locations.yaml
locations:
region1:
coordinates: {lat: 40, lon: -2}
Usage: Just point to your model - imports are handled automatically!
nv.plot_network("path/to/model") # Imports resolved automatically
Scenarios
Apply Calliope scenarios to visualize different configurations:
# Visualize with a specific scenario
nv.plot_network(
model_path="path/to/model",
scenario="high_cost", # Apply 'high_cost' scenario
title="High Cost Scenario"
)
# Analyze with scenario
results = nv.analyze_network(
model_path="path/to/model",
scenario="high_cost"
)
Runtime Overrides
Apply custom overrides without modifying your model files:
# Define overrides
overrides = {
"locations.region1.coordinates.lat": 41.5,
"locations.region1.coordinates.lon": -3.2,
"links.region1,region2.distance": 150
}
# Visualize with overrides
nv.plot_network(
model_path="path/to/model",
override_dict=overrides,
title="Modified Network"
)
# Combine scenario and overrides
nv.plot_network(
model_path="path/to/model",
scenario="high_cost",
override_dict=overrides
)
World Map Projection
All visualizations now use a world map with natural earth projection, perfect for global or multi-regional models.
๐ฏ 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?
- Check Python version:
python --version(needs 3.8+) - Reinstall:
pip uninstall network-visualization && pip install network-visualization - 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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit changes (
git commit -m 'Add improvement') - Push to branch (
git push origin feature/improvement) - Open a Pull Request
๐ License
MIT License - see LICENSE file for details.
๐ Links
- PyPI: https://pypi.org/project/network-visualization/
- GitLab: https://mygit.th-deg.de/thd-spatial-ai/example_models/calliope_plots
- Calliope: https://calliope.readthedocs.io/
๐ Acknowledgments
Built for Calliope energy system modeling framework. Supports any Calliope model structure with universal data extraction.
Version: 1.0.3 | Updated: December 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file network_visualization-1.0.4.tar.gz.
File metadata
- Download URL: network_visualization-1.0.4.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb10cbbdfc7bbeee431bd03d683547b04ec9b6e47d1d10fc560230bae7959a16
|
|
| MD5 |
bab8e1e42b9199bdddd6d7f298cfe49f
|
|
| BLAKE2b-256 |
5bcbd42f314577066d366a11d4f5150e6ba846f10a975bc87ccaeeeb5c365667
|
File details
Details for the file network_visualization-1.0.4-py3-none-any.whl.
File metadata
- Download URL: network_visualization-1.0.4-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a52d2094be22cb97880137255bca3b8e7dc312a9815f3ac021653272d567be2e
|
|
| MD5 |
f971270e66bd05d17432a9cab5941a05
|
|
| BLAKE2b-256 |
e334a113a500727cc032a5430b7f05ca1128cac941512f394865ca48f5f09f9d
|