Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion peakshaving_analyzer/PSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def add_storage(self):
commodity="stored_energy",
locationalEligibility=pd.Series([1, 0], index=["consumption_site", "grid"]),
hasCapacityVariable=True,
cyclicLifetime=10000,
cyclicLifetime=self.config.storage_cyclic_lifetime,
chargeEfficiency=self.storage_charge_efficiency,
dischargeEfficiency=self.storage_discharge_efficiency,
capacityMax=self.max_storage_size_kwh,
Expand Down
1 change: 1 addition & 0 deletions peakshaving_analyzer/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Config(IOHandler):
storage_charge_efficiency: float = 0.95
storage_discharge_efficiency: float = 0.95
storage_charge_rate: float = 5
storage_cyclic_lifetime: float = 10000
storage_discharge_rate: float = 5
inverter_efficiency: float = 0.95
max_pv_system_size_kwp: float | None = None
Expand Down
30 changes: 30 additions & 0 deletions tests/test_psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,33 @@ def test_add_solar():
+ results.inverter_annuity_eur
+ results.storage_annuity_eur
)


def test_storage_only():
# 4 cheap hours, one expensive hour
# adding a storage of 1 kwh reduces cost here
config = Config(
"test_config",
consumption_timeseries=[1] * 6,
hours_per_timestep=1,
n_timesteps=6,
price_timeseries=pd.DataFrame({"grid": [0.3] * 4 + [1] + [0.3], "consumption_site": [0] * 6}),
storage_charge_rate=10,
storage_discharge_rate=10,
# cyclic lifetime must be increased, otherwise we are building much more storage
storage_cyclic_lifetime=1e5,
interest_rate=2,
storage_charge_efficiency=1,
storage_discharge_efficiency=1,
)
psa = PeakShavingAnalyzer(config=config)
results = psa.optimize()
ts = results.timeseries_to_df()
# we need to charge in the first few hours
assert (ts["grid_usage_kw"][0:4] >= 1).all()
# but do not charge in the last hour
assert (ts["grid_usage_kw"][4] == 0).all()

assert results.inverter_capacity_kw == 1
results.storage_capacity_kwh
assert results.storage_capacity_kwh == 1