Important
Information: This is a personal development project. It has no official affiliation with GME (Gestore dei Mercati Energetici).
Python pipeline for analyzing Italian electricity markets (GME) with PyPSA-Eur network topology.
- π Network Visualization: PyPSA-Eur zonal network with Italian market zones
- π Price Mapping: MGP, MSD, MB market prices on network topology
- π Flow Analysis: Transmission flows with GME market limits
- π Congestion Analysis: 96-session heatmaps (15-min granularity)
- βοΈ Balancing Markets: MSD and MB (RS/AS) price and volume analysis
- π¬ Animated Flows: 24-hour evolution (96 frames)
# Create virtual environment
python3.10 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtIf you prefer using Docker, you can run the pipeline without installing local dependencies:
# Build the image
docker compose build
# Fetch data for a specific date
docker compose run app python src/main.py --date 2025-12-30
# Run congestion analysis
docker compose run app python src/analyze_congestion.py --date 2025-12-30This project is configured for VS Code Dev Containers.
- Open the project in VS Code.
- Click "Reopen in Container" when prompted, or use the Command Palette (
Ctrl+Shift+P) and selectDev Containers: Reopen in Container. - The environment will be automatically set up with all dependencies and recommended extensions.
Create .env file with your GME API credentials:
GME_USERNAME=your_username
GME_PASSWORD=your_password
# Fetch data for yesterday (default)
python src/main.py
# Or fetch for a specific date
python src/main.py --date 2025-12-30
# === CONGESTION ANALYSIS ===
python src/analyze_congestion.py --date 2025-12-30
# Outputs to workspace/:
# - congestion_heatmap_96sessions.png (>5% avg utilization corridors)
# - corridor_timeseries.png
# - morning_vs_midday.png
# === BALANCING MARKETS ===
python src/analyze_balancing.py --date 2025-12-30
# Outputs (9 total) to workspace/:
# MSD: zone price comparison, buy/sell volumes
# MB_RS: zone price comparison, buy/sell volumes
# MB_AS: zone price comparison, buy/sell volumes
# === FLOW ANIMATION ===
python src/animate_flows.py --date 2025-12-30 --output workspace/mgp_animation.gif
# 96-frame animated GIF showing 24h flow evolution
# === STATIC PLOTS ===
python src/plot_gme.py --market MGP --hour 12 --date 2025-12-30
python src/plot_flows.py --date 2025-12-30 --hour 12gme_api/
βββ src/ # All source code
β βββ gme_api/ # Core API library
β β βββ client.py # GME API client
β β βββ utils.py # Data processing utilities
β βββ plotting/ # Visualization library
β β βββ plotter.py # Base plotter class
β β βββ utils.py # Plot utilities
β βββ main.py # Data fetcher
β βββ analyze_congestion.py # Congestion analysis
β βββ analyze_balancing.py # Balancing markets analysis
β βββ animate_flows.py # Flow animation
β βββ plot_gme.py # Static price plots
β βββ plot_flows.py # Static flow plots
β
βββ data/ # Static data
β βββ network/ # Network topology data
β βββ aggregation/ # Aggregation scripts & data
β
βββ workspace/ # Generated outputs (gitignored)
β βββ *.csv # Market data CSVs
β βββ *.png # Analysis visualizations
β βββ *.gif # Animations
β
βββ documents/ # Documentation & PDFs
βββ archive/ # Archived code
βββ .devcontainer/ # Dev container configuration
βββ requirements.txt # Dependencies
- 96-session heatmap: Shows utilization across all 15-min intervals
- Filters: Only corridors with >5% avg utilization
- Key findings: CSUDβSUD (72% peak), CSUDβSARD (70% peak)
Analyzes three markets:
- MSD: Mercato del Servizio di Dispacciamento (ex-ante)
- MB_RS: Riserva Secondaria (secondary reserve)
- MB_AS: Altro Servizi (other services)
Each market generates:
- Zone-specific price comparison (vs MGP)
- Buy volume bar charts (7 zones)
- Sell volume bar charts (7 zones)
- 96 frames (24 hours Γ 4 periods)
- Dynamic price updates per zone
- Flow utilization coloring (0-100%)
- Zone labels and country borders
The pipeline uses GME transmission limits (not PyPSA s_nom) for accurate utilization:
- GME limits = real-time market constraints (40-60% of physical capacity)
- Accounts for N-1 security, voltage stability, real-time conditions
- Bidirectional corridors: Asymmetric capacities
- Example: NORDβCNOR = 10.5 GW, CNORβNORD = 4.5 GW
- Italian zones: NORD, CNOR, CSUD, SUD, CALA, SICI, SARD
- External borders: AUST, SVIZ, FRAN, SLOV, GREC, MONT
- MSD: Day-ahead balancing (ex-ante)
- Mostly upward regulation (grid shortage)
- MB_RS: Real-time secondary reserve
- Often zero activity
- MB_AS: Real-time other services
- Most active balancing market
All visualizations saved to analysis/:
- Congestion heatmaps (PNG)
- Balancing price/volume charts (PNG)
- Flow animations (GIF)
Note: Output files are gitignored. See cleanup1 branch for example outputs.
- Python 3.10+
- PyPSA 0.35+
- Matplotlib, Cartopy, Seaborn
- GME API access credentials
MIT
Caution
This software is provided "as is" for educational and analytical purposes. The authors cannot be held responsible for the accuracy or timeliness of the data, or for any consequences arising from commercial or operational decisions made using this tool. Users are responsible for complying with GME's data usage terms and conditions.