Onboard Your Agent
The mesqual package ships a skill that teaches an agent how to understand, navigate and analyze a mesqual study. Install it in your project folder.
Agents work better with a consistent framework. An agent that writes study code against a stable, documented API (fetch, flags, collections, maps) produces consistent code that a human can review. Without a framework, each study gets its own one-off pandas code, and nobody can audit that many codebases. mesqual gives humans and agents the same framework.
1. Install the package
pip install mesqual
2. Install the skill
python -m mesqual.skills install .
For Claude Code, add the --claude flag:
python -m mesqual.skills install . --claude
Modules and Data Classes
MESQUAL gives you atomic building blocks that enable you to build up intuitive representations of real-world energy assets with expressive notation.
StudyManager
StudyManager
.scen
.comp
.scen_comp
Central orchestrator with three-tier DatasetCollection access: scenarios, comparisons, and unified views.
Datasets & Interpreters
PlatformDataset
DatasetMergeCollection
DatasetConcatCollection
"Everything is a Dataset" — unified .fetch(flag) interface with pluggable, platform-agnostic interpreters.
Energy Data Handling
AreaBorderGeometryCalculator
BorderFlowCalculator
TradeBalanceCalculator
Energy-domain utilities for border visualizations, area accounting, trade balances, model mixing and much more.
Time Series Dashboards
TimeSeriesDashboardGenerator
HTMLDashboard
Build faceted heatmap and line dashboards from MultiIndex DataFrames using Plotly.
Folium Viz System
AreaGenerator
PropertyMapper
FeatureResolver
...
Create rich, interactive geospatial maps with KPI-driven styling and animated flows.
KPI Framework
FlagAggKPIBuilder
KPICollection
Aggregations
Fluent builder API for defining, computing, and filtering KPIs across scenarios.
And so many more
Utilities, custom aggregations, color systems, plotting helpers, data export tools, and a growing ecosystem of platform adapters.
Explore the full APIMake It Yours
mesqual's layered architecture lets you leverage the full generic framework while freely adding study-specific logic — custom data sources, variables, KPIs, and visual themes.
Study-specific datasources, custom interpreters, variables, KPIs, color themes, merging fragmented simulations — anything specific to your analysis
CustomRESShareInterpreter
CustomExternalEntsoePriceData
MyStudySpecificFoliumMap
...
Connect your modeling tool — or build your own adapter in a few lines
mesqual.testing
your platform package
Platform-agnostic foundation — StudyManager, KPIs, Visualizations, Utilities
mesqual
.fetch(flag)across all layers
across all layers
for any study
Extend anything with a few lines of Python
Custom Data Sources
Import external data alongside simulation results — ENTSO-E market data, weather feeds, or any DataFrame that is not included in the output of your simulation platform.
class EntsoeHistPriceInterpreter(Interpreter):
accepted_flags = {'BZ.ETP.hist_price'}
def _fetch(self, flag, config):
parent = self.parent_dataset
idx = parent.fetch('BZ.Results.market_price').index
return load_historic_entsoe_data(idx)
# study.scen.fetch('BZ.ETP.hist_price') # now works!
Custom Variables
Every study has unique formulas — compute RES shares, curtailment rates, or any derived metric your way.
class RESCurtailment(Interpreter):
accepted_flags = {'countries_t.res_curtailment'}
def _fetch(self, flag, config):
parent = self.parent_dataset
gen = parent.fetch('countries_t.res_gen')
avail = parent.fetch('generators_t.availability')
return avail - gen
# study.scen.fetch('countries_t.res_curtailment') # now works!
Auto-Generate Border Models
Detect area borders from granular topology — hundreds of individual transmission lines get grouped into clean border objects between countries or bidding zones.
# 500+ branches across 30 countries? No problem.
gen = AreaBorderModelGenerator(
nodes, branches,
area_column='country',
node_from_col='bus0',
node_to_col='bus1',
)
borders = gen.generate_area_border_model()
# → DataFrame: DE-FR, DE-PL, FR-ES, ...
# with direction, opposite_border, sorted_border
# and per-border branch membership
Auto-Compute Border Geometry
Borders know their area pairs, but need positions for visualization. Auto-compute line paths, midpoints, and angles from area geometries — ready for animated flow arrows.
# Borders exist but have no spatial information yet
geo_calc = AreaBorderGeometryCalculator(countries_gdf)
borders = gen.enhance_with_geometry(borders, geo_calc)
# Each border now carries:
# projection_point → optimal arrow/label placement
# azimuth_angle → directional angle for flow arrows
# geo_line_string → LineString connecting the areas
# is_physical → True if areas share a boundary
# Plug directly into folviz.ArrowIconGenerator!
Geo-Enrich Your Model
Extend simulation models with external data — here, an existing country model gets extended with GeoJSON geometries for map visualizations.
class CountriesInterpreter(PyPSAInterpreter):
accepted_flags = {'countries'}
def _fetch(self, flag, config):
countries = self.parent_dataset.fetch('countries')
gdf = gpd.GeoDataFrame(
countries,
geometry=[get_geo(c) for c in countries.index],
)
self.add_projection_point_column(gdf)
return gdf
# study.scen.fetch('countries') → GeoDataFrame with shapes and projection_points
Custom KPI Definition
Define domain-specific KPIs — subclass, implement compute_batch, and the framework handles aggregation, comparison deltas, and collection management.
class AnnualizedRESShare(kpis.CustomKPIDefinition):
def get_unit(self):
return Units.percent
def compute_batch(self, dataset, objects):
gen = dataset.fetch('countries_t.generation')
res = dataset.fetch('countries_t.res_generation')
return (res.sum() / gen.sum() * 100).to_dict()
kpi_def = AnnualizedRESShare(kpi_flag='countries_t.annualized_res_gen')
study.scen.add_kpis_from_definitions_to_all_child_datasets([kpi_def])
Project Family
All open-source projects by Helge Esch for energy system analysis, scenario comparison, and modeling support.
A Pythonic framework for energy scenario comparison and quantitative analysis. Platform-agnostic, fully modular, and built to extend.
Built for humans and agents alike
A unified framework and modular Python package for representative period selection in multi-variate time-series spaces.
Create beautiful, customizable, animated SVG arrows for web interfaces with just a few lines of Python code.