-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add storage_costs to GenericStorage #962
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e021ce9
Add storage_costs to GenericStorage
p-snft ff7c87b
Adhere to Black
p-snft f4e7b20
Adhere to Black
p-snft d8c0cb0
Fix typo in docstring of GenericStorageBlock
p-snft 91636ef
Add test for storage costs
p-snft 8a6d25a
Make storage_costs docstring more specific
p-snft 012c8b1
Make storage cost example more practical
p-snft db8e499
Adhere to Black
p-snft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
General description | ||
------------------- | ||
Example that shows the parameter `storage_costs` of `GenericStorage`. | ||
A battery is used to make profit from fluctuating electricity prices. | ||
For a battery without storage costs, it is beneficial to be empty | ||
the end of the time horizon of the optimisation. For a battery that | ||
assumes the average revenue, energy is kept at the end. | ||
|
||
|
||
Installation requirements | ||
------------------------- | ||
This example requires oemof.solph (v0.5.x), install by: | ||
|
||
pip install oemof.solph[examples] | ||
|
||
|
||
License | ||
------- | ||
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_ | ||
""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from matplotlib import pyplot as plt | ||
|
||
from oemof import solph | ||
|
||
|
||
def storage_costs_example(): | ||
# create an energy system | ||
idx = pd.date_range("1/1/2023", periods=13, freq="H") | ||
es = solph.EnergySystem(timeindex=idx, infer_last_interval=False) | ||
|
||
# power bus | ||
bel = solph.Bus(label="bel") | ||
es.add(bel) | ||
|
||
es.add( | ||
solph.components.Source( | ||
label="source_el", | ||
outputs={bel: solph.Flow()}, | ||
) | ||
) | ||
|
||
es.add( | ||
solph.components.Sink( | ||
label="sink_el", | ||
inputs={bel: solph.Flow()}, | ||
) | ||
) | ||
|
||
electricity_price = np.array( | ||
[ | ||
0.38, | ||
0.31, | ||
0.32, | ||
0.33, | ||
0.37, | ||
0.32, | ||
0.33, | ||
0.34, | ||
0.39, | ||
0.38, | ||
0.37, | ||
0.35, | ||
0.35, | ||
] | ||
) | ||
|
||
# Electric Storage 1 | ||
# Costs are designed in a way that storing energy is benificial until the | ||
# last four time steps but emptying it is not a good option. | ||
battery1 = solph.components.GenericStorage( | ||
label="battery 1", | ||
nominal_storage_capacity=10, | ||
inputs={ | ||
bel: solph.Flow( | ||
nominal_value=1, | ||
variable_costs=electricity_price, | ||
) | ||
}, | ||
outputs={ | ||
bel: solph.Flow( | ||
nominal_value=1, | ||
variable_costs=-electricity_price, | ||
) | ||
}, | ||
initial_storage_level=0.5, | ||
balanced=False, | ||
) | ||
es.add(battery1) | ||
|
||
# storages that balance our fluctuating costs | ||
# Electric Storage 2 | ||
battery2 = solph.components.GenericStorage( | ||
label="battery 2", | ||
nominal_storage_capacity=10, | ||
inputs={ | ||
bel: solph.Flow( | ||
nominal_value=1, | ||
variable_costs=electricity_price, | ||
) | ||
}, | ||
outputs={ | ||
bel: solph.Flow( | ||
nominal_value=1, | ||
variable_costs=-electricity_price, | ||
) | ||
}, | ||
storage_costs=12 * [0] + [-np.mean(electricity_price)], | ||
initial_storage_level=0.5, | ||
balanced=False, | ||
) | ||
es.add(battery2) | ||
|
||
# create an optimization problem and solve it | ||
model = solph.Model(es) | ||
|
||
# solve model | ||
model.solve(solver="cbc") | ||
|
||
# create result object | ||
results = solph.processing.results(model) | ||
|
||
plt.plot( | ||
results[(battery1, None)]["sequences"], | ||
label="content w/o storage costs", | ||
) | ||
plt.plot( | ||
results[(battery2, None)]["sequences"], | ||
label="content w/ storage revenue", | ||
) | ||
plt.legend() | ||
plt.grid() | ||
|
||
plt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
storage_costs_example() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently there is no
period
index for the storage block. Maybe this should be fixed for the sake of consistency? Not sure if this needs to be addressed in a separate issue though?!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the storage content is given in absolute values, only the limit (which might change from period to period) needs to have the index. I will leave it as it is.