supplyforge 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- supplyforge/__init__.py +27 -0
- supplyforge/create_pommes_craft_model.py +754 -0
- supplyforge/result_process.py +208 -0
- supplyforge/utils.py +101 -0
- supplyforge-0.1.0.dist-info/METADATA +151 -0
- supplyforge-0.1.0.dist-info/RECORD +9 -0
- supplyforge-0.1.0.dist-info/WHEEL +5 -0
- supplyforge-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- supplyforge-0.1.0.dist-info/top_level.txt +1 -0
supplyforge/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
supplyforge
|
|
3
|
+
-----------
|
|
4
|
+
|
|
5
|
+
A Python package for generating country-level electricity supply datasets for power system analysis.
|
|
6
|
+
|
|
7
|
+
This package provides a reproducible Snakemake workflow to build a consistent and transparent
|
|
8
|
+
data foundation describing the generation infrastructure and resources of European electricity systems.
|
|
9
|
+
It integrates data primarily from ENTSO-E to create validated, ready-to-use datasets for
|
|
10
|
+
scenario analysis and planning models.
|
|
11
|
+
|
|
12
|
+
For more information, please visit the [GitLab repository](https://git.persee.minesparis.psl.eu/energy-alternatives/supplyforge).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
import pandas as pd
|
|
19
|
+
from dotenv import load_dotenv
|
|
20
|
+
load_dotenv()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
ROOT_DIR = Path(__file__).parent.parent
|
|
25
|
+
RESULTS_DIR = ROOT_DIR / "results"
|
|
26
|
+
|
|
27
|
+
pd.set_option('future.no_silent_downcasting', True)
|
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module to create a pommes_craft EnergyModel for a given country and year.
|
|
3
|
+
|
|
4
|
+
This script leverages pre-calculated data from the Snakemake workflow for:
|
|
5
|
+
- Installed capacities
|
|
6
|
+
- Availability for dispatchable plants (e.g., nuclear)
|
|
7
|
+
- Capacity factors for intermittent renewables (e.g., wind, solar)
|
|
8
|
+
- Hydro inflows for reservoir hydro plants
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
import urllib
|
|
14
|
+
|
|
15
|
+
import polars as pl
|
|
16
|
+
from pommes_craft import (
|
|
17
|
+
Area,
|
|
18
|
+
ConversionTechnology,
|
|
19
|
+
EnergyModel,
|
|
20
|
+
NetImport,
|
|
21
|
+
Spillage,
|
|
22
|
+
StorageTechnology,
|
|
23
|
+
TimeStepManager,
|
|
24
|
+
EconomicHypothesis,
|
|
25
|
+
LoadShedding,
|
|
26
|
+
TransportTechnology,
|
|
27
|
+
Link
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
from supplyforge.fetch.day_ahead_prices import COUNTRY_BIDDING_ZONE_MAPPING
|
|
31
|
+
from supplyforge import RESULTS_DIR
|
|
32
|
+
from supplyforge.fetch.eraa_study import fetch_eraa_data
|
|
33
|
+
from supplyforge.utils import get_electricity_import_prices, _get_input_data_file
|
|
34
|
+
|
|
35
|
+
DISPATCHABLE_TECH_DICT = {
|
|
36
|
+
"Nuclear": "Nuclear",
|
|
37
|
+
"Lignite": "Lignite",
|
|
38
|
+
"Coal": "Fossil Hard coal",
|
|
39
|
+
"Gas": "Fossil Gas",
|
|
40
|
+
"Oil": "Fossil Oil",
|
|
41
|
+
"Biomass": "Biomass",
|
|
42
|
+
"Waste": "Waste",
|
|
43
|
+
"Other": "Other"
|
|
44
|
+
}
|
|
45
|
+
INTERMITTENT_TECH_DICT = {
|
|
46
|
+
"Solar": "Solar",
|
|
47
|
+
"Wind_Onshore": "Wind Onshore",
|
|
48
|
+
"Wind_Offshore": "Wind Offshore",
|
|
49
|
+
"RoR_Pondage": "Hydro Run-of-river and poundage",
|
|
50
|
+
}
|
|
51
|
+
DISPATCHABLE_DEFAULT_COSTS = {
|
|
52
|
+
"Nuclear": 10.0,
|
|
53
|
+
"Lignite": 180.0,
|
|
54
|
+
"Coal": 250.0,
|
|
55
|
+
"Gas": 200.0,
|
|
56
|
+
"Oil": 300.0,
|
|
57
|
+
"Biomass": 50.0,
|
|
58
|
+
"Waste": 30.0,
|
|
59
|
+
"Other": 40.0,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
DISPATCHABLE_RAMP_RATES = {
|
|
63
|
+
"Nuclear": 0.1,
|
|
64
|
+
"Lignite": 0.2,
|
|
65
|
+
"Coal": 0.4,
|
|
66
|
+
"Gas": 0.8,
|
|
67
|
+
"Oil": 1.,
|
|
68
|
+
"Biomass": 1.,
|
|
69
|
+
"Waste": 1.,
|
|
70
|
+
"Other": 1.,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
FIXED_COSTS = {
|
|
74
|
+
"Nuclear": 120_000.0,
|
|
75
|
+
"Lignite": 50_000.0,
|
|
76
|
+
"Coal": 45_000.0,
|
|
77
|
+
"Gas": 20_000.0,
|
|
78
|
+
"Oil": 25_000.0,
|
|
79
|
+
"Biomass": 60_000.0,
|
|
80
|
+
"Waste": 70_000.0,
|
|
81
|
+
"Other": 30_000.0,
|
|
82
|
+
"Solar": 12_000.0,
|
|
83
|
+
"Wind_Onshore": 35_000.0,
|
|
84
|
+
"Wind_Offshore": 85_000.0,
|
|
85
|
+
"RoR_Pondage": 25_000.0,
|
|
86
|
+
"Pumped_Hydro": 14_000.0,
|
|
87
|
+
"Reservoir_Hydro": 30_000.0
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# Investment costs (CAPEX) in €/MW
|
|
91
|
+
INVEST_COSTS = {
|
|
92
|
+
"Nuclear": 7500000.0, # Very high initial capital (e.g., EPR reactors)
|
|
93
|
+
"Lignite": 2000000.0, # High due to complex fuel handling/boiler
|
|
94
|
+
"Coal": 1800000.0, # Standard hard coal plant
|
|
95
|
+
"Gas": 900000.0, # Combined Cycle (CCGT) - cheaper to build
|
|
96
|
+
"Oil": 500000.0, # Peaking units/Engines - low CAPEX, high OPEX
|
|
97
|
+
"Biomass": 3500000.0, # High due to feedstock logistics and scale
|
|
98
|
+
"Waste": 6000000.0, # Very high due to filtration/fume treatment
|
|
99
|
+
"Other": 4000000.0, # Generic estimate for misc. thermal technologies
|
|
100
|
+
"Reservoir_Hydro": 4000000.0, # High civil engineering costs (dams)
|
|
101
|
+
"Solar": 700000.0, # Utility-scale PV (prices have dropped significantly)
|
|
102
|
+
"Wind_Onshore": 1300000.0, # Mature technology
|
|
103
|
+
"Wind_Offshore": 3200000.0,# Higher due to marine foundations & grid connection
|
|
104
|
+
"RoR_Pondage": 3500000.0, # Run-of-river hydro (civil works)
|
|
105
|
+
"Pumped_Hydro": 2000000.0, # Site specific, but generally high civil costs
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
# Technical lifetime in years
|
|
109
|
+
LIFETIMES = {
|
|
110
|
+
"Nuclear": 60, # Modern Gen III+ plants are designed for 60 years
|
|
111
|
+
"Lignite": 40, # Standard thermal plant life
|
|
112
|
+
"Coal": 40,
|
|
113
|
+
"Gas": 30, # Gas turbines have shorter lives than steam turbines
|
|
114
|
+
"Oil": 30,
|
|
115
|
+
"Biomass": 25, # Corrosion can limit life compared to coal
|
|
116
|
+
"Waste": 25,
|
|
117
|
+
"Other": 30,
|
|
118
|
+
"Reservoir_Hydro": 80, # Civil structures (dams) last very long
|
|
119
|
+
"Solar": 25, # Standard PV module warranty/life
|
|
120
|
+
"Wind_Onshore": 25, # Modern turbines
|
|
121
|
+
"Wind_Offshore": 25, # Harsh marine environment limits life
|
|
122
|
+
"RoR_Pondage": 60, # Long-lived civil works
|
|
123
|
+
"Pumped_Hydro": 80 # Very long life (mostly civil engineering)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# Configure logging
|
|
128
|
+
logger = logging.getLogger(__name__)
|
|
129
|
+
|
|
130
|
+
def _eraa_study_data(file_name: str):
|
|
131
|
+
|
|
132
|
+
"""
|
|
133
|
+
Retrieves the dashboard data from the ERAA study.
|
|
134
|
+
Args:
|
|
135
|
+
file_name:
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
|
|
139
|
+
"""
|
|
140
|
+
data_dir = RESULTS_DIR / "eraa_study"
|
|
141
|
+
data_dir.mkdir(parents=True, exist_ok=True)
|
|
142
|
+
file_path = data_dir / file_name
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if not file_path.is_file():
|
|
146
|
+
logging.info(f"'{file_path}' not found. Downloading from remote URL...")
|
|
147
|
+
fetch_eraa_data()
|
|
148
|
+
|
|
149
|
+
if file_path.suffix == ".csv":
|
|
150
|
+
return pl.read_csv(file_path)
|
|
151
|
+
elif file_path.suffix == ".xlsx":
|
|
152
|
+
return pl.read_excel(file_path)
|
|
153
|
+
else:
|
|
154
|
+
raise ValueError(f"Unsupported file type: {file_path.suffix}")
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def get_storage_energy_capacities(
|
|
158
|
+
country:str,
|
|
159
|
+
storage_type:str = "Hydro",
|
|
160
|
+
technology:str = "CL pumping",
|
|
161
|
+
eraa_year:int = 2026
|
|
162
|
+
):
|
|
163
|
+
"""
|
|
164
|
+
loads the ERAA study data on storage energy capacities and
|
|
165
|
+
extract the relevant data for the given country, storage type and technology.
|
|
166
|
+
Args:
|
|
167
|
+
country: 2-letter country code
|
|
168
|
+
storage_type: "CL pumping", "OL pumping", "Market", "Non-market", "Reservoir"
|
|
169
|
+
technology: "Batteries", "Hydro"
|
|
170
|
+
eraa_year:
|
|
171
|
+
Returns:
|
|
172
|
+
a float with the storage energy capacity in MWh
|
|
173
|
+
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
eraa_storage = _eraa_study_data("Storage.xlsx")
|
|
177
|
+
eraa_storage = (
|
|
178
|
+
eraa_storage
|
|
179
|
+
.filter(pl.col("MARKET_NODE").str.slice(0, 2) == country)
|
|
180
|
+
.filter(pl.col("TYPE_STORAGE") == storage_type)
|
|
181
|
+
.filter(pl.col("TECHNOLOGY") == technology)
|
|
182
|
+
.filter(pl.col("YEAR") == eraa_year)
|
|
183
|
+
.filter(pl.col('DATA_VERSION') == 'Final')
|
|
184
|
+
)
|
|
185
|
+
if eraa_storage.is_empty():
|
|
186
|
+
return 0.
|
|
187
|
+
unit = eraa_storage['UNIT'][0]
|
|
188
|
+
capacity = eraa_storage['VALUE'].sum()
|
|
189
|
+
if unit == "GWh":
|
|
190
|
+
capacity *= 1.e3
|
|
191
|
+
elif unit == "TWh":
|
|
192
|
+
capacity *= 1.e6
|
|
193
|
+
else:
|
|
194
|
+
raise ValueError(f"Unit {unit} not recognized.")
|
|
195
|
+
|
|
196
|
+
return capacity
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def add_dispatchable_tech(
|
|
201
|
+
area: Area,
|
|
202
|
+
tech_name: str,
|
|
203
|
+
plant_type: str,
|
|
204
|
+
installed_capacities: pl.DataFrame,
|
|
205
|
+
variable_cost: float,
|
|
206
|
+
reference_year: int,
|
|
207
|
+
ramp_rate: float = 1.0,
|
|
208
|
+
fixed_cost: float = 0.0,
|
|
209
|
+
investment_cost: float = 0.0,
|
|
210
|
+
lifetime: float = 25.0,
|
|
211
|
+
) -> None:
|
|
212
|
+
"""Adds a dispatchable technology to the area."""
|
|
213
|
+
if plant_type not in installed_capacities.columns:
|
|
214
|
+
logger.info(f"Skipping {tech_name}: no installed capacity found for plant type '{plant_type}'.")
|
|
215
|
+
return
|
|
216
|
+
availability = _get_input_data_file(area.name, reference_year, "availability")
|
|
217
|
+
|
|
218
|
+
capacity = installed_capacities[plant_type][0]
|
|
219
|
+
year_op = area.model.year_ops[0]
|
|
220
|
+
hours = area.model.hours
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
tech_availability = (
|
|
224
|
+
availability.filter(pl.col("plant_type") == plant_type)
|
|
225
|
+
.select("availability_share")
|
|
226
|
+
.rename({"availability_share": "availability"})
|
|
227
|
+
.with_columns(pl.col("availability").clip(0., 1.))
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
if tech_availability.is_empty():
|
|
232
|
+
logger.warning(f"No availability data for {tech_name}. Assuming 100% availability.")
|
|
233
|
+
tech_availability = 1.0
|
|
234
|
+
elif tech_availability.height < 8760:
|
|
235
|
+
tech_availability = pl.concat([tech_availability,
|
|
236
|
+
tech_availability[-(8760 - tech_availability.height):]],)
|
|
237
|
+
elif tech_availability.height > 8760:
|
|
238
|
+
tech_availability = tech_availability[:8760]
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
tech_availability = (
|
|
242
|
+
tech_availability
|
|
243
|
+
.with_columns(hour=pl.Series(hours), year_op=pl.lit(year_op).cast(pl.Int64))
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
logger.info(f"Adding {tech_name} with {capacity:.0f} MW capacity.")
|
|
247
|
+
with area.model.context():
|
|
248
|
+
tech = ConversionTechnology(
|
|
249
|
+
name=tech_name,
|
|
250
|
+
factor={"electricity": 1.0},
|
|
251
|
+
availability=tech_availability,
|
|
252
|
+
must_run=0.,
|
|
253
|
+
variable_cost=variable_cost,
|
|
254
|
+
fixed_cost=fixed_cost,
|
|
255
|
+
invest_cost=investment_cost,
|
|
256
|
+
life_span=lifetime,
|
|
257
|
+
power_capacity_max=capacity,
|
|
258
|
+
power_capacity_min=capacity,
|
|
259
|
+
ramp_down=ramp_rate,
|
|
260
|
+
ramp_up=ramp_rate,
|
|
261
|
+
early_decommissioning=True,
|
|
262
|
+
)
|
|
263
|
+
area.add_component(tech)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def add_intermittent_tech(
|
|
267
|
+
area: Area,
|
|
268
|
+
tech_name: str,
|
|
269
|
+
plant_type: str,
|
|
270
|
+
installed_capacities: pl.DataFrame,
|
|
271
|
+
reference_year: int,
|
|
272
|
+
fixed_cost: float = 0.0,
|
|
273
|
+
investment_cost: float = 0.0,
|
|
274
|
+
lifetime: float = 25.0,
|
|
275
|
+
) -> None:
|
|
276
|
+
"""Adds an intermittent (must-run) technology to the area."""
|
|
277
|
+
|
|
278
|
+
if plant_type not in installed_capacities.columns:
|
|
279
|
+
logger.info(f"Skipping {tech_name}: no installed capacity found for plant type '{plant_type}'.")
|
|
280
|
+
return
|
|
281
|
+
|
|
282
|
+
capacity = installed_capacities[plant_type][0]
|
|
283
|
+
|
|
284
|
+
year_op = area.model.year_ops[0]
|
|
285
|
+
hours = area.model.hours
|
|
286
|
+
|
|
287
|
+
capacity_factors = _get_input_data_file(area.name,
|
|
288
|
+
reference_year,
|
|
289
|
+
"capacity_factors")
|
|
290
|
+
capacity_factors = capacity_factors.filter(pl.col("plant_type") == plant_type)
|
|
291
|
+
|
|
292
|
+
if capacity_factors.is_empty():
|
|
293
|
+
logger.warning(f"No capacity factor data for {tech_name} in {area.name} in {reference_year}. Replacing with 0.")
|
|
294
|
+
capacity_factors = pl.DataFrame({"capacity_factor": [0.0] * 8760})
|
|
295
|
+
|
|
296
|
+
# Append last row to the end
|
|
297
|
+
if capacity_factors.height < 8760:
|
|
298
|
+
capacity_factors = pl.concat([capacity_factors, capacity_factors[-(8760 - capacity_factors.height):]],)
|
|
299
|
+
elif capacity_factors.height > 8760:
|
|
300
|
+
capacity_factors = capacity_factors[:8760]
|
|
301
|
+
|
|
302
|
+
tech_availability = (
|
|
303
|
+
capacity_factors
|
|
304
|
+
.select("capacity_factor")
|
|
305
|
+
.rename({"capacity_factor": "availability"})
|
|
306
|
+
.with_columns(hour=pl.Series(hours), year_op=pl.lit(year_op).cast(pl.Int64))
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
logger.info(f"Adding {tech_name} with {capacity:.0f} MW capacity.")
|
|
311
|
+
|
|
312
|
+
with area.model.context():
|
|
313
|
+
tech = ConversionTechnology(
|
|
314
|
+
name=tech_name,
|
|
315
|
+
factor={"electricity": 1.0},
|
|
316
|
+
availability=tech_availability,
|
|
317
|
+
must_run=0.,
|
|
318
|
+
variable_cost=0.0,
|
|
319
|
+
fixed_cost=fixed_cost,
|
|
320
|
+
invest_cost=investment_cost,
|
|
321
|
+
life_span=lifetime,
|
|
322
|
+
power_capacity_max=capacity,
|
|
323
|
+
power_capacity_min=capacity,
|
|
324
|
+
early_decommissioning=True,
|
|
325
|
+
)
|
|
326
|
+
area.add_component(tech)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def add_reservoir_hydro(
|
|
330
|
+
area: Area,
|
|
331
|
+
installed_capacities: pl.DataFrame,
|
|
332
|
+
inflows: pl.DataFrame,
|
|
333
|
+
fixed_cost: float,
|
|
334
|
+
investment_cost: float,
|
|
335
|
+
country: str,
|
|
336
|
+
eraa_year: int = 2026,
|
|
337
|
+
lifetime: float = 25.0,
|
|
338
|
+
) -> None:
|
|
339
|
+
"""Adds reservoir hydro components (storage, inflow, plant) to the area."""
|
|
340
|
+
year_op = area.model.year_ops[0]
|
|
341
|
+
|
|
342
|
+
plant_type = "Hydro Water Reservoir"
|
|
343
|
+
if plant_type not in installed_capacities.columns:
|
|
344
|
+
logger.info(f"Skipping {plant_type}: no installed capacity found for plant type '{plant_type}'.")
|
|
345
|
+
return
|
|
346
|
+
|
|
347
|
+
turbine_capacity = installed_capacities[plant_type][0]
|
|
348
|
+
storage_capacity = get_storage_energy_capacities(country,
|
|
349
|
+
storage_type="Reservoir",
|
|
350
|
+
technology="Hydro",
|
|
351
|
+
eraa_year=eraa_year)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
if inflows.is_empty():
|
|
355
|
+
logger.warning("No inflow data for Reservoir Hydro. Skipping.")
|
|
356
|
+
return
|
|
357
|
+
|
|
358
|
+
logger.info(f"Adding Reservoir Hydro with {turbine_capacity:.0f} MW turbine capacity and {storage_capacity*1.e-3:.0f} GWh storage.")
|
|
359
|
+
|
|
360
|
+
# 1. Storage component
|
|
361
|
+
|
|
362
|
+
with area.model.context():
|
|
363
|
+
stor = StorageTechnology(
|
|
364
|
+
name="lake_hydro_store",
|
|
365
|
+
factor_in={"reservoir_water": -1.0},
|
|
366
|
+
factor_out={"reservoir_water": 1.0},
|
|
367
|
+
factor_keep={"reservoir_water": 0.0},
|
|
368
|
+
life_span=lifetime,
|
|
369
|
+
energy_capacity_investment_max=storage_capacity,
|
|
370
|
+
energy_capacity_investment_min=storage_capacity,
|
|
371
|
+
early_decommissioning=True,
|
|
372
|
+
)
|
|
373
|
+
area.add_component(stor)
|
|
374
|
+
|
|
375
|
+
if inflows.height < 8760:
|
|
376
|
+
inflows = pl.concat([inflows,
|
|
377
|
+
inflows[-(8760 - inflows.height):]],)
|
|
378
|
+
elif inflows.height > 8760:
|
|
379
|
+
inflows = inflows[:8760]
|
|
380
|
+
|
|
381
|
+
# 2. Inflow component (must-run)
|
|
382
|
+
inflow_availability = inflows.with_columns(
|
|
383
|
+
pl.Series("hour", range(8760)),
|
|
384
|
+
pl.lit(year_op).cast(pl.Int64).alias("year_op"),
|
|
385
|
+
(pl.col("inflow_MW") / pl.col("inflow_MW").max()).alias("availability")
|
|
386
|
+
).select(["hour", "year_op", "availability"])
|
|
387
|
+
|
|
388
|
+
inflow_capacity = inflows["inflow_MW"].max()
|
|
389
|
+
|
|
390
|
+
with area.model.context():
|
|
391
|
+
|
|
392
|
+
tech = ConversionTechnology(
|
|
393
|
+
name="lake_hydro_inflow",
|
|
394
|
+
factor={"reservoir_water": 1.0},
|
|
395
|
+
availability=inflow_availability,
|
|
396
|
+
must_run=1.0,
|
|
397
|
+
life_span=lifetime,
|
|
398
|
+
power_capacity_max=inflow_capacity,
|
|
399
|
+
power_capacity_min=inflow_capacity,
|
|
400
|
+
early_decommissioning=True,
|
|
401
|
+
)
|
|
402
|
+
area.add_component(tech)
|
|
403
|
+
|
|
404
|
+
# 3. Power plant component (dispatchable)
|
|
405
|
+
tech = ConversionTechnology(
|
|
406
|
+
name="lake_hydro_plant",
|
|
407
|
+
factor={"reservoir_water": -1.0, "electricity": 1.0},
|
|
408
|
+
availability=1.0,
|
|
409
|
+
life_span=lifetime,
|
|
410
|
+
fixed_cost=fixed_cost,
|
|
411
|
+
invest_cost=investment_cost,
|
|
412
|
+
power_capacity_max=turbine_capacity,
|
|
413
|
+
power_capacity_min=turbine_capacity,
|
|
414
|
+
early_decommissioning=True,
|
|
415
|
+
)
|
|
416
|
+
area.add_component(tech)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def add_pumped_hydro(
|
|
420
|
+
area: Area,
|
|
421
|
+
installed_capacities: pl.DataFrame,
|
|
422
|
+
country: str,
|
|
423
|
+
fixed_cost: float,
|
|
424
|
+
investment_cost: float,
|
|
425
|
+
lifetime: float = 25.0,
|
|
426
|
+
eraa_year: int = 2026
|
|
427
|
+
):
|
|
428
|
+
|
|
429
|
+
phs_storage_capacity = (
|
|
430
|
+
get_storage_energy_capacities(country,
|
|
431
|
+
storage_type="CL pumping",
|
|
432
|
+
technology="Hydro",
|
|
433
|
+
eraa_year=eraa_year)
|
|
434
|
+
+ get_storage_energy_capacities(country,
|
|
435
|
+
storage_type="OL pumping",
|
|
436
|
+
technology="Hydro",
|
|
437
|
+
eraa_year=eraa_year)
|
|
438
|
+
)
|
|
439
|
+
# --- Storage ---
|
|
440
|
+
plant_type = "Hydro Pumped Storage"
|
|
441
|
+
if plant_type not in installed_capacities.columns:
|
|
442
|
+
logger.info(f"Skipping {plant_type}: no installed capacity found for plant type '{plant_type}'.")
|
|
443
|
+
else:
|
|
444
|
+
turbine_capacity = installed_capacities[plant_type][0]
|
|
445
|
+
storage_capacity = phs_storage_capacity
|
|
446
|
+
with area.model.context():
|
|
447
|
+
|
|
448
|
+
logger.info(
|
|
449
|
+
f"Adding Pumped Hydro Storage with {turbine_capacity:.0f} MW power and {storage_capacity*1.e-3:.0f} GWh storage.")
|
|
450
|
+
stor = StorageTechnology(
|
|
451
|
+
name="pumped_hydro_storage",
|
|
452
|
+
factor_in={"electricity": -1.0},
|
|
453
|
+
factor_out={"electricity": 0.8},
|
|
454
|
+
factor_keep={"electricity": 0.0},
|
|
455
|
+
fixed_cost_power=fixed_cost,
|
|
456
|
+
invest_cost_power=investment_cost,
|
|
457
|
+
energy_capacity_investment_max=storage_capacity,
|
|
458
|
+
energy_capacity_investment_min=storage_capacity,
|
|
459
|
+
power_capacity_investment_max=turbine_capacity,
|
|
460
|
+
power_capacity_investment_min=turbine_capacity,
|
|
461
|
+
life_span=lifetime,
|
|
462
|
+
early_decommissioning=True,
|
|
463
|
+
)
|
|
464
|
+
area.add_component(stor)
|
|
465
|
+
|
|
466
|
+
def add_imports(
|
|
467
|
+
area: Area,
|
|
468
|
+
country: str,
|
|
469
|
+
reference_year: int,
|
|
470
|
+
):
|
|
471
|
+
energy_model = area.model
|
|
472
|
+
year_op = energy_model.year_ops[0]
|
|
473
|
+
hours = energy_model.hours
|
|
474
|
+
|
|
475
|
+
net_transfer_capacities = _get_input_data_file(
|
|
476
|
+
country,
|
|
477
|
+
reference_year,
|
|
478
|
+
"net_transfer_capacities"
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
connected_countries = (
|
|
482
|
+
net_transfer_capacities
|
|
483
|
+
.max()
|
|
484
|
+
.to_dicts()[0]
|
|
485
|
+
)
|
|
486
|
+
for connected_country, grid_capacity in connected_countries.items():
|
|
487
|
+
|
|
488
|
+
bzn = connected_country
|
|
489
|
+
for c, bzns in COUNTRY_BIDDING_ZONE_MAPPING.items():
|
|
490
|
+
if connected_country in bzns:
|
|
491
|
+
connected_country = c
|
|
492
|
+
|
|
493
|
+
try:
|
|
494
|
+
day_ahead_import_prices = get_electricity_import_prices(
|
|
495
|
+
country,
|
|
496
|
+
reference_year,
|
|
497
|
+
year_op,
|
|
498
|
+
hours,
|
|
499
|
+
bzn
|
|
500
|
+
)
|
|
501
|
+
day_ahead_export_prices = (
|
|
502
|
+
day_ahead_import_prices
|
|
503
|
+
.rename({"import_price": "export_price"})
|
|
504
|
+
)
|
|
505
|
+
except:
|
|
506
|
+
logger.warning(f"No day-ahead prices found for {connected_country}. Using default 150€/MWh")
|
|
507
|
+
day_ahead_export_prices = pl.DataFrame(
|
|
508
|
+
{
|
|
509
|
+
"export_price": [0.] * 8760,
|
|
510
|
+
"hour": hours,
|
|
511
|
+
"year_op": [year_op] * 8760,
|
|
512
|
+
}
|
|
513
|
+
)
|
|
514
|
+
day_ahead_import_prices = pl.DataFrame(
|
|
515
|
+
{
|
|
516
|
+
"import_price": [200.0] * 8760,
|
|
517
|
+
"hour": hours,
|
|
518
|
+
"year_op": [year_op] * 8760,
|
|
519
|
+
}
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
with energy_model.context():
|
|
523
|
+
area_connected = Area(connected_country)
|
|
524
|
+
net_import = NetImport(
|
|
525
|
+
name=f"import_from_{connected_country}",
|
|
526
|
+
resource="electricity",
|
|
527
|
+
import_price=day_ahead_import_prices,
|
|
528
|
+
export_price=day_ahead_export_prices
|
|
529
|
+
)
|
|
530
|
+
area_connected.add_component(net_import)
|
|
531
|
+
|
|
532
|
+
transport_tech_dict = {
|
|
533
|
+
"name": "electric_line",
|
|
534
|
+
"resource": "electricity",
|
|
535
|
+
"life_span": 25.,
|
|
536
|
+
"invest_cost": 0.,
|
|
537
|
+
"fixed_cost": 0.,
|
|
538
|
+
"hurdle_costs": 20.,
|
|
539
|
+
"finance_rate": 0.,
|
|
540
|
+
"power_capacity_investment_max": grid_capacity,
|
|
541
|
+
"power_capacity_investment_min": grid_capacity,
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
transport_technology = TransportTechnology(
|
|
545
|
+
**transport_tech_dict
|
|
546
|
+
)
|
|
547
|
+
link = Link(
|
|
548
|
+
name=f"link_{area.name}_{connected_country}",
|
|
549
|
+
area_from=area,
|
|
550
|
+
area_to=area_connected,
|
|
551
|
+
)
|
|
552
|
+
link.add_transport_technology(transport_technology)
|
|
553
|
+
|
|
554
|
+
transport_technology = TransportTechnology(
|
|
555
|
+
**transport_tech_dict
|
|
556
|
+
)
|
|
557
|
+
link = Link(
|
|
558
|
+
name=f"link_{connected_country}_{area.name}",
|
|
559
|
+
area_from=area_connected,
|
|
560
|
+
area_to=area,
|
|
561
|
+
)
|
|
562
|
+
link.add_transport_technology(transport_technology)
|
|
563
|
+
ls = LoadShedding(name="electricity_load_shedding", resource="electricity", max_capacity=0.)
|
|
564
|
+
area_connected.add_component(ls)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
with energy_model.context():
|
|
568
|
+
net_import = NetImport(
|
|
569
|
+
name="water_import",
|
|
570
|
+
resource="reservoir_water",
|
|
571
|
+
max_yearly_energy_import=0.0)
|
|
572
|
+
area.add_component(net_import)
|
|
573
|
+
net_import = NetImport(
|
|
574
|
+
name="electricity_import",
|
|
575
|
+
resource="electricity",
|
|
576
|
+
max_yearly_energy_import=0.0)
|
|
577
|
+
area.add_component(net_import)
|
|
578
|
+
|
|
579
|
+
def create_model(
|
|
580
|
+
country_code: str,
|
|
581
|
+
reference_year: int,
|
|
582
|
+
model_year:int,
|
|
583
|
+
dispatchable_tech_costs: dict = None,
|
|
584
|
+
dispatchable_ramp_rates: dict = None,
|
|
585
|
+
fixed_costs: dict = None,
|
|
586
|
+
investment_costs: dict = None,
|
|
587
|
+
lifetimes: dict = None,
|
|
588
|
+
lifetime_step: int = 5,
|
|
589
|
+
) -> None:
|
|
590
|
+
"""
|
|
591
|
+
Creates and configures an energy model for a given country and reference year.
|
|
592
|
+
|
|
593
|
+
The function initializes a comprehensive energy model that includes
|
|
594
|
+
technologies, economic assumptions, area components, and reserve structures
|
|
595
|
+
based on the input parameters and specified configurations. It supports
|
|
596
|
+
customization for various costs, ramp rates, and other parameters through
|
|
597
|
+
additional inputs.
|
|
598
|
+
|
|
599
|
+
Args:
|
|
600
|
+
country_code (str): Two-character code representing the country for which
|
|
601
|
+
the model is being created.
|
|
602
|
+
reference_year (int): The reference year used for input data such as
|
|
603
|
+
installed capacities or hydrological inflows.
|
|
604
|
+
model_year (int): The operating year for which the model simulates energy
|
|
605
|
+
operations.
|
|
606
|
+
dispatchable_tech_costs (dict, optional): Costs related to dispatchable
|
|
607
|
+
technologies. If not provided, defaults to predefined values.
|
|
608
|
+
dispatchable_ramp_rates (dict, optional): Ramp rates associated with
|
|
609
|
+
dispatchable technologies. If not provided, defaults to predefined
|
|
610
|
+
values.
|
|
611
|
+
fixed_costs (dict, optional): Fixed costs for various technologies. If not
|
|
612
|
+
provided, defaults to predefined values.
|
|
613
|
+
investment_costs (dict, optional): Investment costs for various
|
|
614
|
+
technologies. If not provided, defaults to predefined values.
|
|
615
|
+
lifetimes (dict, optional): Lifetimes of technologies. If not provided, defaults to predefined values
|
|
616
|
+
|
|
617
|
+
Returns:
|
|
618
|
+
None
|
|
619
|
+
"""
|
|
620
|
+
logger.info(f"Creating pommes_craft model for {country_code} for the year {reference_year}...")
|
|
621
|
+
|
|
622
|
+
# --- Load pre-processed data ---
|
|
623
|
+
capacities = _get_input_data_file(country_code, reference_year, "installed_capacities")
|
|
624
|
+
hydro_inflows = _get_input_data_file(country_code, reference_year, "inflow")
|
|
625
|
+
|
|
626
|
+
if dispatchable_tech_costs is None:
|
|
627
|
+
dispatchable_tech_costs = DISPATCHABLE_DEFAULT_COSTS
|
|
628
|
+
else:
|
|
629
|
+
dispatchable_tech_costs = DISPATCHABLE_DEFAULT_COSTS | dispatchable_tech_costs
|
|
630
|
+
|
|
631
|
+
if dispatchable_ramp_rates is None:
|
|
632
|
+
dispatchable_ramp_rates = DISPATCHABLE_RAMP_RATES
|
|
633
|
+
else:
|
|
634
|
+
dispatchable_ramp_rates = DISPATCHABLE_RAMP_RATES | dispatchable_ramp_rates
|
|
635
|
+
|
|
636
|
+
if fixed_costs is None:
|
|
637
|
+
fixed_costs = FIXED_COSTS
|
|
638
|
+
else:
|
|
639
|
+
fixed_costs = FIXED_COSTS | fixed_costs
|
|
640
|
+
|
|
641
|
+
if investment_costs is None:
|
|
642
|
+
investment_costs = INVEST_COSTS
|
|
643
|
+
else:
|
|
644
|
+
investment_costs = INVEST_COSTS | investment_costs
|
|
645
|
+
|
|
646
|
+
if lifetimes is None:
|
|
647
|
+
lifetimes = LIFETIMES
|
|
648
|
+
else:
|
|
649
|
+
lifetimes = LIFETIMES | lifetimes
|
|
650
|
+
|
|
651
|
+
for name, lt in lifetimes.items():
|
|
652
|
+
if lt % lifetime_step != 0:
|
|
653
|
+
raise ValueError(f"Life time must be multiple of lifetime step {lifetime_step}: {lt} for technology {name}"
|
|
654
|
+
"You can either adjust the lifetimes by technology or change lifetime_step")
|
|
655
|
+
|
|
656
|
+
max_lifetime = max(lifetimes.values())
|
|
657
|
+
# --- Initialize EnergyModel ---
|
|
658
|
+
hours = list(range(8760))
|
|
659
|
+
energy_model = EnergyModel(
|
|
660
|
+
name=f"model_{country_code}_ref_{reference_year}",
|
|
661
|
+
hours=hours,
|
|
662
|
+
year_ops=[model_year],
|
|
663
|
+
year_invs=[model_year],
|
|
664
|
+
year_decs=list(range(model_year, model_year + max_lifetime + lifetime_step, lifetime_step)),
|
|
665
|
+
modes=["base"],
|
|
666
|
+
resources=["electricity", "reservoir_water"],
|
|
667
|
+
)
|
|
668
|
+
|
|
669
|
+
# --- Economic, time steps and area components ---
|
|
670
|
+
with energy_model.context():
|
|
671
|
+
EconomicHypothesis("eco", discount_rate=0.0, year_ref=model_year, planning_step=25)
|
|
672
|
+
TimeStepManager("ts", time_step_duration=1.0, operation_year_duration=8760)
|
|
673
|
+
area = Area(country_code)
|
|
674
|
+
|
|
675
|
+
# --- Generation Technologies ---
|
|
676
|
+
# Dispatchable
|
|
677
|
+
for tech_name, plant_type in DISPATCHABLE_TECH_DICT.items():
|
|
678
|
+
add_dispatchable_tech(
|
|
679
|
+
area=area,
|
|
680
|
+
tech_name=tech_name,
|
|
681
|
+
plant_type=plant_type,
|
|
682
|
+
installed_capacities=capacities,
|
|
683
|
+
reference_year=reference_year,
|
|
684
|
+
variable_cost=dispatchable_tech_costs[tech_name],
|
|
685
|
+
ramp_rate=dispatchable_ramp_rates[tech_name],
|
|
686
|
+
fixed_cost=fixed_costs[tech_name],
|
|
687
|
+
investment_cost=investment_costs[tech_name],
|
|
688
|
+
lifetime=lifetimes[tech_name]
|
|
689
|
+
)
|
|
690
|
+
|
|
691
|
+
# Intermittent
|
|
692
|
+
for tech_name, plant_type in INTERMITTENT_TECH_DICT.items():
|
|
693
|
+
add_intermittent_tech(
|
|
694
|
+
area=area,
|
|
695
|
+
tech_name=tech_name,
|
|
696
|
+
plant_type=plant_type,
|
|
697
|
+
installed_capacities=capacities,
|
|
698
|
+
reference_year=reference_year,
|
|
699
|
+
fixed_cost=fixed_costs[tech_name],
|
|
700
|
+
investment_cost=investment_costs[tech_name],
|
|
701
|
+
lifetime=lifetimes[tech_name]
|
|
702
|
+
)
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
# Reserver Hydro
|
|
706
|
+
add_reservoir_hydro(
|
|
707
|
+
area=area,
|
|
708
|
+
installed_capacities=capacities,
|
|
709
|
+
inflows=hydro_inflows,
|
|
710
|
+
fixed_cost=fixed_costs['Reservoir_Hydro'],
|
|
711
|
+
investment_cost=investment_costs['Reservoir_Hydro'],
|
|
712
|
+
lifetime=lifetimes['Reservoir_Hydro'],
|
|
713
|
+
country=country_code
|
|
714
|
+
)
|
|
715
|
+
|
|
716
|
+
# Pumped hydro storage
|
|
717
|
+
add_pumped_hydro(
|
|
718
|
+
area,
|
|
719
|
+
capacities,
|
|
720
|
+
country_code,
|
|
721
|
+
fixed_costs['Pumped_Hydro'],
|
|
722
|
+
investment_costs['Pumped_Hydro']
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
# Import from interconnected countries
|
|
726
|
+
add_imports(area, country_code, reference_year)
|
|
727
|
+
|
|
728
|
+
# --- Balancing and feasibility components ---
|
|
729
|
+
|
|
730
|
+
with energy_model.context():
|
|
731
|
+
spil = Spillage(name="electricity_spillage", resource="electricity", max_capacity=0.)
|
|
732
|
+
area.add_component(spil)
|
|
733
|
+
ls = LoadShedding(name="electricity_load_shedding", resource="electricity", cost=30_000.)
|
|
734
|
+
area.add_component(ls)
|
|
735
|
+
|
|
736
|
+
spil = Spillage(name="reservoir_water_spillage", resource="reservoir_water", max_capacity=50.0e3)
|
|
737
|
+
area.add_component(spil)
|
|
738
|
+
ls = LoadShedding(name="reservoir_water_load_shedding", resource="reservoir_water", max_capacity=0.0)
|
|
739
|
+
area.add_component(ls)
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
return energy_model
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
if __name__ == "__main__":
|
|
747
|
+
|
|
748
|
+
logger.error("This script is intended to be run via Snakemake.")
|
|
749
|
+
logger.info("Running in standalone mode for debugging with placeholder data.")
|
|
750
|
+
# Example for standalone execution (requires dummy files)
|
|
751
|
+
country, year = "FR", 2022
|
|
752
|
+
model_year = 2025
|
|
753
|
+
|
|
754
|
+
create_model(country, year, model_year)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
from pommes_craft.components import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
gen_palette = {
|
|
8
|
+
'Nuclear': '#A0A0A0',
|
|
9
|
+
'RoR_Pondage': '#1E90FF',
|
|
10
|
+
'Solar': '#FDB813',
|
|
11
|
+
'Wind_Onshore': '#66B2FF',
|
|
12
|
+
'Wind_Offshore': '#0077BE',
|
|
13
|
+
'lake_hydro_plant': '#0000CD',
|
|
14
|
+
'Pumped_Hydro_Discharging': '#9370DB',
|
|
15
|
+
'Battery_Discharging': '#9B59B6',
|
|
16
|
+
'Coal': '#4B4B4B',
|
|
17
|
+
'Gas': '#E97451',
|
|
18
|
+
'Oil': '#8B4513',
|
|
19
|
+
'Biomass': '#2E8B57',
|
|
20
|
+
'Waste': '#6B8E23',
|
|
21
|
+
'Other': '#CCCCCC',
|
|
22
|
+
'Imports': '#15616d',
|
|
23
|
+
"Load_Shedding": '#d90429'
|
|
24
|
+
}
|
|
25
|
+
dem_palette = {
|
|
26
|
+
'Demand': '#2a9d8f',
|
|
27
|
+
'Pumped_Hydro_Charging': '#CBA0F5',
|
|
28
|
+
'Battery_Charging': '#D7BDE2',
|
|
29
|
+
'Exports': '#F08080',
|
|
30
|
+
"Flexible_Demand": "#0f4c5c"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def extract_power_results(energy_model, country_code):
|
|
34
|
+
|
|
35
|
+
area_fr = energy_model.areas[country_code]
|
|
36
|
+
# retrieving power produced by generators
|
|
37
|
+
powers = (
|
|
38
|
+
energy_model.get_results("operation", "power", [ConversionTechnology])
|
|
39
|
+
.pivot(on='name', values='value')
|
|
40
|
+
.drop(['area', 'year_op', 'hour', "lake_hydro_inflow"])
|
|
41
|
+
.to_pandas()
|
|
42
|
+
.set_index('datetime')
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# retrieving power stored and released in pumped hydro storages
|
|
46
|
+
hydro_storage_power_in = area_fr.components['pumped_hydro_storage'].results['operation']['power_in']
|
|
47
|
+
hydro_storage_power_out = area_fr.components['pumped_hydro_storage'].results['operation']['power_out']
|
|
48
|
+
|
|
49
|
+
# retrieving imported and exported powers
|
|
50
|
+
interco_powers = energy_model.get_results("operation", "power", [TransportTechnology])
|
|
51
|
+
imports_to_fr = (
|
|
52
|
+
interco_powers.filter(pl.col('link').str.ends_with(country_code))
|
|
53
|
+
.group_by(pl.col('datetime'), maintain_order=True)
|
|
54
|
+
.agg(pl.col('value').sum())
|
|
55
|
+
)
|
|
56
|
+
exports_from_fr = (
|
|
57
|
+
interco_powers.filter(pl.col('link').str.ends_with(country_code) == False)
|
|
58
|
+
.group_by(pl.col('datetime'), maintain_order=True)
|
|
59
|
+
.agg(pl.col('value').sum())
|
|
60
|
+
)
|
|
61
|
+
demand = area_fr.components['electricity_demand'].demand['demand'].to_numpy()
|
|
62
|
+
load_shedding = (
|
|
63
|
+
area_fr
|
|
64
|
+
.components['electricity_load_shedding']
|
|
65
|
+
.results['operation']['power']['value'].to_numpy()
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
powers['Pumped_Hydro_Discharging'] = hydro_storage_power_out['value'].to_numpy()
|
|
69
|
+
powers['Pumped_Hydro_Charging'] = hydro_storage_power_in['value'].to_numpy()
|
|
70
|
+
powers['Imports'] = imports_to_fr['value'].to_numpy()
|
|
71
|
+
powers['Exports'] = exports_from_fr['value'].to_numpy()
|
|
72
|
+
powers['Demand'] = demand
|
|
73
|
+
powers['Load_Shedding'] = load_shedding
|
|
74
|
+
|
|
75
|
+
if "Battery_Storage" in area_fr.components.keys():
|
|
76
|
+
# retrieving power stored and released in batteries
|
|
77
|
+
battery_power_in = area_fr.components['Battery_Storage'].results['operation']['power_in']
|
|
78
|
+
battery_power_out = area_fr.components['Battery_Storage'].results['operation']['power_out']
|
|
79
|
+
powers['Battery_Charging'] = battery_power_in['value'].to_numpy()
|
|
80
|
+
powers['Battery_Discharging'] = battery_power_out['value'].to_numpy()
|
|
81
|
+
else:
|
|
82
|
+
powers['Battery_Charging'] = 0.
|
|
83
|
+
powers['Battery_Discharging'] = 0.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
flex = energy_model.get_results('operation', 'demand', [FlexibleDemand])
|
|
88
|
+
|
|
89
|
+
if flex.is_empty():
|
|
90
|
+
powers['Flexible_Demand'] = 0.
|
|
91
|
+
else:
|
|
92
|
+
powers['Flexible_Demand'] = flex['value'].to_numpy()
|
|
93
|
+
|
|
94
|
+
return powers
|
|
95
|
+
|
|
96
|
+
def plot_power_balance(power_df, resample_step="1h", week=None, day=None, max_y=None):
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
fig, ax = plt.subplots(1, 2,figsize=(15, 6))
|
|
100
|
+
|
|
101
|
+
if week is not None:
|
|
102
|
+
plot_mask = power_df.index.isocalendar().week == week
|
|
103
|
+
elif day is not None:
|
|
104
|
+
plot_mask = power_df.index.day_of_year == day
|
|
105
|
+
else:
|
|
106
|
+
plot_mask = power_df.index
|
|
107
|
+
|
|
108
|
+
powers_to_p = power_df.loc[plot_mask].resample(resample_step).mean()
|
|
109
|
+
|
|
110
|
+
gen_cols = list(gen_palette.keys())
|
|
111
|
+
powers_to_p[gen_cols].plot.area(ax=ax[0], color=gen_palette, linewidth=0)
|
|
112
|
+
|
|
113
|
+
dem_cols = list(dem_palette.keys())
|
|
114
|
+
powers_to_p[dem_cols].plot.area(ax=ax[1], color=dem_palette, linewidth=0)
|
|
115
|
+
ax[0].legend(
|
|
116
|
+
loc='upper center',
|
|
117
|
+
bbox_to_anchor=(0.5, -0.15),
|
|
118
|
+
ncol=3,
|
|
119
|
+
frameon=False,
|
|
120
|
+
fontsize=9
|
|
121
|
+
)
|
|
122
|
+
ax[1].legend(
|
|
123
|
+
loc='upper center',
|
|
124
|
+
bbox_to_anchor=(0.5, -0.15),
|
|
125
|
+
ncol=3,
|
|
126
|
+
frameon=False,
|
|
127
|
+
fontsize=9
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
ax[0].set_ylabel('Power in MW')
|
|
131
|
+
ax[0].set_xlabel('')
|
|
132
|
+
ax[1].set_xlabel('')
|
|
133
|
+
if max_y is not None:
|
|
134
|
+
ax[0].set_ylim(0, max_y)
|
|
135
|
+
ax[1].set_ylim(0, max_y)
|
|
136
|
+
plt.show()
|
|
137
|
+
|
|
138
|
+
def get_summary_df(model_dict, country_code, cmap='Greys'):
|
|
139
|
+
|
|
140
|
+
cols = list(gen_palette.keys()) + list(dem_palette.keys())
|
|
141
|
+
index_colors = (
|
|
142
|
+
{f'{k} in TWh': f"{v}80" for k,v in gen_palette.items()}
|
|
143
|
+
| {f'{k} in TWh': f"{v}80" for k,v in dem_palette.items()}
|
|
144
|
+
| {
|
|
145
|
+
"Costs in B€": "#fca31180",
|
|
146
|
+
'Peak Demand in GW': "#2a9d8f80",
|
|
147
|
+
'Peak Load Shedding in GW': "#FF000080"
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
dfs = []
|
|
151
|
+
for name, energy_model in model_dict.items():
|
|
152
|
+
powers_df = extract_power_results(energy_model, country_code)
|
|
153
|
+
comp_df = powers_df[cols].sum().to_frame() * 1.e-6
|
|
154
|
+
comp_df.columns = [name]
|
|
155
|
+
comp_df.index = [f"{c} in TWh" for c in comp_df.index]
|
|
156
|
+
peak_demand = powers_df[['Demand', "Flexible_Demand"]].sum(axis=1).max() * 1.e-3
|
|
157
|
+
comp_df.loc['Peak Demand in GW', name] = peak_demand
|
|
158
|
+
peak_load_shedding = powers_df["Load_Shedding"].max() * 1.e-3
|
|
159
|
+
comp_df.loc['Peak Load Shedding in GW', name] = peak_load_shedding
|
|
160
|
+
costs = energy_model.get_results('operation', "costs")['value'].sum() * 1.e-9
|
|
161
|
+
comp_df.loc['Costs in B€', name] = costs
|
|
162
|
+
dfs.append(comp_df)
|
|
163
|
+
|
|
164
|
+
df = pd.concat(dfs, axis=1).round(2)
|
|
165
|
+
|
|
166
|
+
separators = [f"{list(gen_palette)[-1]} in TWh",
|
|
167
|
+
f"{list(dem_palette)[-1]} in TWh",
|
|
168
|
+
'Peak Load Shedding in GW',
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
def bold_row_bottom_border(styler, indices_to_style):
|
|
172
|
+
index_map = {label: i + 1 for i, label in enumerate(styler.data.index)}
|
|
173
|
+
styles = []
|
|
174
|
+
|
|
175
|
+
# Corrected Property Format: (property_name, property_value)
|
|
176
|
+
property_tuple = ('border-bottom', '3px solid #14213d !important;')
|
|
177
|
+
|
|
178
|
+
for index_label in indices_to_style:
|
|
179
|
+
if index_label in index_map:
|
|
180
|
+
row_number = index_map[index_label]
|
|
181
|
+
|
|
182
|
+
# Selector targets ALL cells (*, i.e., both <th> and <td>)
|
|
183
|
+
# within the Nth table row (tr:nth-child(N)).
|
|
184
|
+
selector = f'tr:nth-child({row_number}) *'
|
|
185
|
+
|
|
186
|
+
styles.append({
|
|
187
|
+
'selector': selector,
|
|
188
|
+
# Pass the property tuple inside a list
|
|
189
|
+
'props': [property_tuple]
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
return styles
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
df_styled = (
|
|
196
|
+
df.style.apply_index(
|
|
197
|
+
lambda idx: [f"background-color: {index_colors.get(i, '')}" for i in idx],
|
|
198
|
+
axis=0
|
|
199
|
+
).format(precision=2)
|
|
200
|
+
.set_table_styles(
|
|
201
|
+
bold_row_bottom_border(df.style, separators)
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if len(dfs) > 1:
|
|
206
|
+
df_styled = df_styled.background_gradient(cmap=cmap, axis=1)
|
|
207
|
+
|
|
208
|
+
return df, df_styled
|
supplyforge/utils.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
import logging
|
|
3
|
+
import urllib
|
|
4
|
+
from supplyforge import RESULTS_DIR
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _get_input_data_file(country: str, year: int, input_file: str) -> pl.DataFrame:
|
|
8
|
+
"""Retrieves the input for a given country and year.
|
|
9
|
+
|
|
10
|
+
Downloads the data from a remote URL if it's not available locally.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
country (str): The country code (e.g., 'DE').
|
|
14
|
+
year (int): The reference year.
|
|
15
|
+
input_file (str) : The name of the input file.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
pl.DataFrame: A polars DataFrame with the combined load data.
|
|
19
|
+
"""
|
|
20
|
+
file_name = f"{input_file}_{country}_{year}.parquet"
|
|
21
|
+
data_dir = RESULTS_DIR / input_file
|
|
22
|
+
data_dir.mkdir(parents=True, exist_ok=True)
|
|
23
|
+
file_path = data_dir / file_name
|
|
24
|
+
|
|
25
|
+
if not file_path.is_file():
|
|
26
|
+
logging.info(f"'{file_path}' not found. Downloading from remote URL...")
|
|
27
|
+
url = f"https://storage.googleapis.com/supplyforge/{file_name}"
|
|
28
|
+
try:
|
|
29
|
+
urllib.request.urlretrieve(url, file_path)
|
|
30
|
+
logging.info(f"Successfully downloaded '{file_path}'.")
|
|
31
|
+
except urllib.error.URLError as e:
|
|
32
|
+
logging.error(f"Failed to download {url}. Error: {e}")
|
|
33
|
+
raise
|
|
34
|
+
|
|
35
|
+
return pl.read_parquet(file_path)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_electricity_import_prices(country, reference_year, year_op, hours, bzn):
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
_get_input_data_file(
|
|
42
|
+
country,
|
|
43
|
+
reference_year,
|
|
44
|
+
"day_ahead_prices"
|
|
45
|
+
)
|
|
46
|
+
.rename({"price_eur_per_mwh": "import_price"})
|
|
47
|
+
.filter(pl.col("bidding_zone") == bzn)
|
|
48
|
+
.drop(["timestamp", "bidding_zone"], strict=False)[:len(hours)]
|
|
49
|
+
.with_columns(hour=pl.Series(hours),
|
|
50
|
+
year_op=pl.lit(year_op).cast(pl.Int64),
|
|
51
|
+
import_price=pl.col("import_price").clip(0.))
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_electricity_emission_factors(country, reference_year, year_op, hours, emission_factors=None):
|
|
56
|
+
|
|
57
|
+
if emission_factors is None:
|
|
58
|
+
emission_factors = {
|
|
59
|
+
'Biomass': 230.0,
|
|
60
|
+
'Fossil Gas': 500.0,
|
|
61
|
+
'Fossil Hard coal': 1000.0,
|
|
62
|
+
'Fossil Brown coal/Lignite': 1050.,
|
|
63
|
+
'Fossil Coal-derived gas': 1000.0,
|
|
64
|
+
'Geothermal': 40.0,
|
|
65
|
+
'Fossil Oil': 700.0,
|
|
66
|
+
'Hydro Pumped Storage': 0.0,
|
|
67
|
+
'Hydro Run-of-river and poundage': 24.0,
|
|
68
|
+
'Hydro Water Reservoir': 24.0,
|
|
69
|
+
'Nuclear': 5.0,
|
|
70
|
+
'Solar': 48.0,
|
|
71
|
+
'Waste': 230.0,
|
|
72
|
+
'Wind Onshore': 12.0,
|
|
73
|
+
'Wind Offshore': 15.0,
|
|
74
|
+
'Other': 700.0,
|
|
75
|
+
'Other renewable': 40.0,
|
|
76
|
+
} # in TCO2/MWh
|
|
77
|
+
|
|
78
|
+
generation = _get_input_data_file(country=country, year=reference_year, input_file="generation")
|
|
79
|
+
cols_to_keep = [c for c in generation.columns if 'Actual Aggregated' in c]
|
|
80
|
+
generation = generation.select(cols_to_keep)
|
|
81
|
+
generation = generation.rename({c: c.split("'")[1] for c in generation.columns})
|
|
82
|
+
|
|
83
|
+
emission_totals = (
|
|
84
|
+
generation.with_columns(**{c: pl.col(c) * emission_factors[c] for c in generation.columns})
|
|
85
|
+
).sum_horizontal()
|
|
86
|
+
|
|
87
|
+
emission_factors = emission_totals / generation.sum_horizontal()
|
|
88
|
+
|
|
89
|
+
if len(emission_factors) < 8760:
|
|
90
|
+
emission_factors = pl.concat([emission_factors, emission_factors[-(8760 - len(emission_factors)):]],)
|
|
91
|
+
if len(emission_factors) > 8760:
|
|
92
|
+
emission_factors = emission_factors[:8760]
|
|
93
|
+
|
|
94
|
+
return pl.DataFrame(
|
|
95
|
+
{
|
|
96
|
+
"emission_factor": emission_factors / 1000.,
|
|
97
|
+
"hour": pl.Series(hours),
|
|
98
|
+
"year_op": [year_op] * 8760,
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: supplyforge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Snakemake workflow to generate country-level electricity supply datasets.
|
|
5
|
+
Author-email: Yassine Abdelouadoud <yassine.abdelouadoud@minesparis.psl.eu>
|
|
6
|
+
Project-URL: Homepage, https://git.persee.minesparis.psl.eu/energy-alternatives/supplyforge
|
|
7
|
+
Project-URL: Bug Tracker, https://git.persee.minesparis.psl.eu/energy-alternatives/supplyforge/-/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.md
|
|
13
|
+
Requires-Dist: pandas
|
|
14
|
+
Requires-Dist: polars
|
|
15
|
+
Requires-Dist: pyarrow
|
|
16
|
+
Requires-Dist: entsoe-py
|
|
17
|
+
Requires-Dist: pommes_craft
|
|
18
|
+
Requires-Dist: fastexcel
|
|
19
|
+
Requires-Dist: python-dotenv
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# ⚡️ supplyforge
|
|
23
|
+
|
|
24
|
+
**supplyforge** is a Python package that implements a reproducible **Snakemake workflow** to generate country-level
|
|
25
|
+
datasets describing the **electricity supply side** for power system analysis and planning.
|
|
26
|
+
It is the companion package to [**demandforge**](https://git.persee.minesparis.psl.eu/energy-alternatives/demandforge), which focuses on demand projection.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 🌍 Overview
|
|
31
|
+
|
|
32
|
+
The goal of **supplyforge** is to build a consistent and transparent data foundation describing the **generation
|
|
33
|
+
infrastructure and resources** of European electricity systems.
|
|
34
|
+
|
|
35
|
+
The workflow integrates data obtained primarily from **ENTSO-E** (the European Network of Transmission System Operators
|
|
36
|
+
for Electricity), including:
|
|
37
|
+
|
|
38
|
+
- 🏭 **Installed capacity** by technology (nuclear, gas, hydro, wind, solar, etc.)
|
|
39
|
+
- ⚙️ **Availability profiles** by technology and country
|
|
40
|
+
- 💧 **Hydro inflows** and reservoir information
|
|
41
|
+
- 🌦️ **Renewable resource time series** (when available)
|
|
42
|
+
- 📊 **Aggregated country-level summaries** ready for power system modeling tools
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 🧩 Features
|
|
47
|
+
|
|
48
|
+
- Automated **data retrieval** from ENTSO-E public APIs and datasets
|
|
49
|
+
- Harmonized **technology classification** across countries
|
|
50
|
+
- Computation of **availability and inflow time series** for each technology
|
|
51
|
+
- Generation of **validated, ready-to-use datasets** for scenario analysis and planning models
|
|
52
|
+
- Full **traceability and reproducibility** via Snakemake
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🔗 Relation to *demandforge*
|
|
57
|
+
|
|
58
|
+
| Package | Focus | Description |
|
|
59
|
+
|----------|--------|-------------|
|
|
60
|
+
| [**demandforge**](https://github.com/yourusername/demandforge) | **Demand** | Creates projected electricity load curves for future scenarios |
|
|
61
|
+
| **supplyforge** | **Supply** | Builds datasets describing generation capacity, availability, and inflows |
|
|
62
|
+
|
|
63
|
+
Together, these tools provide a **complete data pipeline** for future electricity system modeling at the national scale.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## ⚙️ Workflow
|
|
68
|
+
|
|
69
|
+
`supplyforge` uses a modular Snakemake workflow with well-defined stages:
|
|
70
|
+
|
|
71
|
+
1. **Download** — fetch data from ENTSO-E and other sources
|
|
72
|
+
2. **Preprocess** — clean and align generation technology data
|
|
73
|
+
3. **Compute** — derive availability, inflow, and capacity time series
|
|
74
|
+
4. **Aggregate** — generate standardized outputs for modeling tools
|
|
75
|
+
|
|
76
|
+
Each rule is designed for transparency, reproducibility, and easy extension to new datasets.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🧱 Outputs
|
|
81
|
+
|
|
82
|
+
Typical outputs include:
|
|
83
|
+
|
|
84
|
+
| Output file | Description |
|
|
85
|
+
|--------------|-------------|
|
|
86
|
+
| `installed_capacity.csv` | Installed capacity by country and technology |
|
|
87
|
+
| `availability_profiles.parquet` | Hourly availability by technology |
|
|
88
|
+
| `hydro_inflows.parquet` | Hourly inflow series for hydro reservoirs |
|
|
89
|
+
| `metadata.yaml` | Documentation of data sources and processing steps |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 📦 Installation
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install supplyforge
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
or from source:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
git clone https://git.persee.minesparis.psl.eu/energy-alternatives/supplyforge.git
|
|
103
|
+
cd supplyforge
|
|
104
|
+
pip install -e .
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 🚀 Usage
|
|
110
|
+
|
|
111
|
+
You can run the Snakemake workflow with:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
snakemake --cores all
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This will download raw data, process it, and generate the final datasets under the `output/` directory.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 📚 Data Sources
|
|
122
|
+
|
|
123
|
+
- **ENTSO-E Transparency Platform** — generation, availability, and inflows
|
|
124
|
+
- **ENTSO-E Statistical Factsheets** — installed capacities
|
|
125
|
+
- Optional integration with **renewable resource datasets** for solar/wind availability
|
|
126
|
+
|
|
127
|
+
All datasets are open or publicly accessible, and sources are documented in the workflow metadata.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🧑💻 Contributing
|
|
132
|
+
|
|
133
|
+
Contributions are welcome!
|
|
134
|
+
You can:
|
|
135
|
+
- Add support for additional data sources or countries
|
|
136
|
+
- Improve technology mappings or validation checks
|
|
137
|
+
- Extend workflow outputs for specific modeling frameworks
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 📄 License
|
|
142
|
+
|
|
143
|
+
Licensed under the **MIT License**.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## ✉️ Contact
|
|
148
|
+
|
|
149
|
+
For questions, suggestions, or collaboration opportunities, please contact:
|
|
150
|
+
**[Your Name]** – [your.email@domain]
|
|
151
|
+
or open an issue on the [Gitlab repository](https://git.persee.minesparis.psl.eu/energy-alternatives/supplyforge).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
supplyforge/__init__.py,sha256=PdRzBefXoUZCPTz8GkrwM5BxigNjYJlsvzB8HYrsTck,836
|
|
2
|
+
supplyforge/create_pommes_craft_model.py,sha256=Hd-t_x4fCCG8b_ezu-sotQg1fbT3Cc9rBn48aXRzK6g,25928
|
|
3
|
+
supplyforge/result_process.py,sha256=ZEb2BI2V4Rx5j6ki4fnafosRArlDs0Co-VlEir-s5_k,7237
|
|
4
|
+
supplyforge/utils.py,sha256=cWzr68F2GBnxIwFSVxCNm16AbU3fRd8oGAVM5ANzuq8,3562
|
|
5
|
+
supplyforge-0.1.0.dist-info/licenses/LICENSE.md,sha256=kRXv9ZraZ_Wp4Od-9m9kZshoycY9vO2e6DtDekMPRao,1068
|
|
6
|
+
supplyforge-0.1.0.dist-info/METADATA,sha256=WbSM30skbfYcPejw6a2egzUItuEJmE7jSAj2H4CLFmg,4968
|
|
7
|
+
supplyforge-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
supplyforge-0.1.0.dist-info/top_level.txt,sha256=BNzgL42I9idcDp52KhuX3121QqFOLRgDJFj7LiTye2o,12
|
|
9
|
+
supplyforge-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 [Your Name]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
supplyforge
|