Skip to content

Commit 2007956

Browse files
Direct transformation ok - errors in fo
1 parent f738d87 commit 2007956

5 files changed

Lines changed: 65 additions & 13 deletions

File tree

pypsa2smspp/transformation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ def _preprocess_network_for_iteration(self, n):
501501
if self.capacity_expansion_ucblock:
502502
apply_expansion_overrides(
503503
self.config.IntermittentUnitBlock_parameters,
504+
self.config.BatteryUnitBlock_parameters,
504505
self.config.BatteryUnitBlock_store_parameters,
505506
self.config.IntermittentUnitBlock_inverse,
506507
self.config.BatteryUnitBlock_inverse,

pypsa2smspp/transformation_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ def reset(self):
6666
"MinPower": lambda p_nom, p_min_pu, p_nom_extendable: (p_nom * p_min_pu).where(~p_nom_extendable, p_min_pu),
6767
# "DeltaRampUp": np.nan,
6868
# "DeltaRampDown": np.nan,
69-
"ExtractingBatteryRho": lambda efficiency_dispatch, snapshot_weighting: snapshot_weighting / efficiency_dispatch,
70-
"StoringBatteryRho": lambda efficiency_store, snapshot_weighting: efficiency_store / snapshot_weighting,
69+
"ExtractingBatteryRho": lambda efficiency_dispatch, snapshots_weighting: snapshots_weighting.iloc[0] / efficiency_dispatch.iloc[0],
70+
"StoringBatteryRho": lambda efficiency_store, snapshots_weighting: snapshots_weighting.iloc[0] * efficiency_store.iloc[0],
7171
"Demand": 0.0,
7272
"MinStorage": 0.0,
73-
"MaxStorage": lambda p_nom, p_max_pu, max_hours: p_nom * p_max_pu * max_hours,
73+
"MaxStorage": lambda p_nom, p_max_pu, p_nom_extendable, max_hours: (p_nom * p_max_pu * max_hours).where(~p_nom_extendable, p_max_pu),
7474
"MaxPrimaryPower": 0.0,
7575
"MaxSecondaryPower": 0.0,
7676
# "InitialPower": lambda p: p[0][0],
77-
"InitialStorage": lambda cyclic_state_of_charge: -1 if cyclic_state_of_charge.values else 0,
77+
"InitialStorage": lambda cyclic_state_of_charge, state_of_charge_initial, p_nom: -1 if cyclic_state_of_charge.values else state_of_charge_initial * p_nom,
7878
"Cost": lambda marginal_cost: abs(marginal_cost),
7979
# "BatteryInvestmentCost": lambda capital_cost: capital_cost,
8080
# "ConverterInvestmentCost": 0.0,

pypsa2smspp/utils.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ def add_sectorcoupled_parameters(
13161316

13171317

13181318
# Sempre nella classe Transformation
1319-
def apply_expansion_overrides(IntermittentUnitBlock_parameters=None, BatteryUnitBlock_store_parameters=None, IntermittentUnitBlock_inverse=None, BatteryUnitBlock_inverse=None, InvestmentBlock=None):
1319+
def apply_expansion_overrides(IntermittentUnitBlock_parameters=None, BatteryUnitBlock_parameters=None, BatteryUnitBlock_store_parameters=None, IntermittentUnitBlock_inverse=None, BatteryUnitBlock_inverse=None, InvestmentBlock=None):
13201320
"""
13211321
Inject missing keys for UC expansion to be solved inside UCBlock instead of a separate InvestmentBlock.
13221322
Keys are only added if missing, so it remains idempotent.
@@ -1348,6 +1348,57 @@ def _min_cap_design(p_nom, p_nom_extendable, p_nom_min):
13481348
if bool(first_scalar(p_nom_extendable))
13491349
else first_scalar(p_nom))
13501350
d["MinCapacityDesign"] = _min_cap_design
1351+
1352+
# --- BatteryUnitBlock ---
1353+
b = BatteryUnitBlock_parameters
1354+
1355+
# "BatteryInvestmentCost"
1356+
if "BatteryInvestmentCost" not in b:
1357+
b["BatteryInvestmentCost"] = lambda capital_cost, p_nom_extendable: capital_cost if bool(first_scalar(p_nom_extendable)) else 0.0
1358+
1359+
# "ConverterInvestmentCost"
1360+
if "ConverterInvestmentCost" not in b:
1361+
b["ConverterInvestmentCost"] = lambda p_nom_extendable: 1e-12 if bool(first_scalar(p_nom_extendable)) else 0.0
1362+
1363+
# "BatteryMaxCapacityDesign"
1364+
if "BatteryMaxCapacityDesign" not in b:
1365+
def _battery_max_cap_design(p_nom, p_nom_extendable, p_nom_max):
1366+
p_nom_max_safe = p_nom_max.replace(np.inf, 1e9)
1367+
return (first_scalar(p_nom_max_safe)
1368+
if bool(first_scalar(p_nom_extendable))
1369+
else first_scalar(p_nom))
1370+
b["BatteryMaxCapacityDesign"] = _battery_max_cap_design
1371+
1372+
# "BatteryMinCapacityDesign"
1373+
if "BatteryMinCapacityDesign" not in b:
1374+
def _battery_min_cap_design(p_nom, p_nom_extendable, p_nom_min):
1375+
p_nom_min_safe = p_nom_min
1376+
return (first_scalar(p_nom_min_safe)
1377+
if bool(first_scalar(p_nom_extendable))
1378+
else first_scalar(p_nom))
1379+
b["BatteryMinCapacityDesign"] = _battery_min_cap_design
1380+
1381+
# "ConverterMaxCapacityDesign"
1382+
if "ConverterMaxCapacityDesign" not in b:
1383+
def _conv_max_cap_design(p_nom, p_nom_extendable, p_nom_max):
1384+
p_nom_max_safe = p_nom_max.replace(np.inf, 1e9)
1385+
# Your rule of thumb: 10x battery energy cap when extendable, else p_nom
1386+
return (10.0 * first_scalar(p_nom_max_safe)
1387+
if bool(first_scalar(p_nom_extendable))
1388+
else first_scalar(p_nom))
1389+
b["ConverterMaxCapacityDesign"] = _conv_max_cap_design
1390+
1391+
1392+
# "ConverterMinCapacityDesign"
1393+
if "ConverterMinCapacityDesign" not in b:
1394+
def _conv_min_cap_design(p_nom, p_nom_extendable, p_nom_min):
1395+
p_nom_min_safe = p_nom_min.replace(np.inf, 1e9)
1396+
# Your rule of thumb: 10x battery energy cap when extendable, else p_nom
1397+
return (10.0 * first_scalar(p_nom_min_safe)
1398+
if bool(first_scalar(p_nom_extendable))
1399+
else first_scalar(p_nom))
1400+
b["ConverterMinCapacityDesign"] = _conv_min_cap_design
1401+
13511402

13521403
# --- BatteryUnitBlock_store ---
13531404
b = BatteryUnitBlock_store_parameters

test/configs/application.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ input_data_path = data
77
input_name_PV = ninja_pv_1.7250_33.6208_uncorrected.csv
88
input_name_wind = ninja_wind_1.7250_33.6208_uncorrected.csv
99
input_name_demand = demand_data.csv
10-
input_name_components = test/2n_1c_1gext_1bext_2lext.xlsx
10+
input_name_components = test/1n_1c_1g_1h.xlsx
1111
input_name_costs = costs.xlsx
1212
input_name_parameters = parameters_smspp.xlsx
1313

@@ -17,7 +17,7 @@ input_path_smspp = ./pypsa2smspp.nc4
1717

1818

1919
[OPTIMIZATION]
20-
weight = 1
20+
weight = 365
2121
n_snapshots = 24
2222

2323

test/main_pypsaeur_stochastic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
# User settings
5353
# =============================================================================
5454

55-
NETWORK_PATH = "/home/pampado/stochastic/pypsa-eur/results/eth_results/stochastic_network/networks/base_s_stoch_adm___2050.nc"
56-
# NETWORK_PATH = r"C:\Users\aless\sms\transformation_pypsa_smspp\test\networks\base_s_stoch_adm___2050.nc"
55+
# NETWORK_PATH = "/home/pampado/stochastic/pypsa-eur/results/eth_results/stochastic_network/networks/base_s_stoch_adm___2050.nc"
56+
NETWORK_PATH = r"C:\Users\aless\sms\transformation_pypsa_smspp\test\networks\pypsa_network_stochUC.nc"
5757

58-
NAME = "stochastic_reduced"
58+
NAME = "stochastic_edf"
5959
FOLDER = "develop/tssb_loaded"
6060

6161
WORKDIR = OUT / FOLDER
@@ -64,20 +64,20 @@
6464
CONFIG_FP = "application_stochastic.ini"
6565
SMSPP_CONFIGFILE = "TSSBlock/TSSBSCfg_grb.txt"
6666

67-
RUN_PYPSA_REFERENCE = False
67+
RUN_PYPSA_REFERENCE = True
6868
EXPORT_PYPSA_LP = True
6969
EXPORT_NETCDF = True
7070

7171
ADD_SLACK = True
7272

73-
DO_REDUCE_SNAPSHOTS = True
73+
DO_REDUCE_SNAPSHOTS = False
7474
REDUCE_SNAPSHOTS_TO = 1000
7575

7676
# If None, the script infers stochastic parameters from the network.
7777
# Otherwise use, for example:
7878
# STOCHASTIC_PARAMETERS_OVERRIDE = ["demand"]
7979
# STOCHASTIC_PARAMETERS_OVERRIDE = ["demand", "renewables"]
80-
STOCHASTIC_PARAMETERS_OVERRIDE = ["demand"]
80+
STOCHASTIC_PARAMETERS_OVERRIDE = ["demand", "renewable_maxpower"]
8181

8282
SOLVER_NAME = "gurobi"
8383
SOLVER_OPTIONS = {

0 commit comments

Comments
 (0)