Skip to content
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

Enabling Examples To Pass on Installation #1155

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,38 @@ to help new users to understand the framework's structure.
You are welcome to contribute your own examples via a `pull request <https://github.com/oemof/oemof-solph/pulls>`_
or by e-mailing us (see `here <https://oemof.org/contact/>`_ for contact information).

To get the example applications set up do the following:

Requirements:
`Poetry <https://python-poetry.org/docs/#installation>`_
Python 3.10

1. Clone the repo, then open the file location in your terminal

2. Install core dependencies using poetry

.. code:: console

(venv) poetry install --no-root

3. Install extra dependencies required for development

.. code:: console

(venv) poetry install --extras "dev" --no-root

Note:
if --no-root is not used, the following error may be thrown "Error: The current project could not be installed: No file/folder found for package oemof-solph
"

4. Install Oemof.solph

.. code:: console

(venv) pip install oemof.solph

5. Run the "check_examples.py" file

License
=======

Expand Down
Empty file modified ci/bootstrap.py
100755 → 100644
Empty file.
Empty file modified docs/_files/GenericCHP.svg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Giving *'my_demand_series'* as parameter *'fix'* means that the demand cannot be
.. code-block:: python

solph.components.Sink(label='electricity_demand', inputs={electricity_bus: solph.flows.Flow(
fix=my_demand_series, nominal_capacity=nominal_demand)})
fix=my_demand_series, nominal_value=nominal_demand)})

In contrast to the demand sink the excess sink has normally less restrictions but is open to take the whole excess.

Expand Down Expand Up @@ -303,10 +303,10 @@ The *nominal_capacity* sets the installed capacity.
solph.components.Source(
label='import_natural_gas',
outputs={my_energysystem.groups['natural_gas']: solph.flows.Flow(
nominal_capacity=1000, full_load_time_max=1000000, variable_costs=50)})
nominal_value=1000, full_load_time_max=1000000, variable_costs=50)})

solph.components.Source(label='wind', outputs={electricity_bus: solph.flows.Flow(
fix=wind_power_feedin_series, nominal_capacity=1000000)})
fix=wind_power_feedin_series, nominal_value=1000000)})

.. note:: The Source class is only a plug and provides no additional constraints or variables.

Expand All @@ -329,7 +329,7 @@ A condensing power plant can be defined by a converter with one input (fuel) and
solph.components.Converter(
label="pp_gas",
inputs={bgas: solph.flows.Flow()},
outputs={b_el: solph.flows.Flow(nominal_capacity=10e10)},
outputs={b_el: solph.flows.Flow(nominal_value=10e10)},
conversion_factors={electricity_bus: 0.58})

A CHP power plant would be defined in the same manner but with two outputs:
Expand All @@ -343,8 +343,8 @@ A CHP power plant would be defined in the same manner but with two outputs:
solph.components.Converter(
label='pp_chp',
inputs={b_gas: Flow()},
outputs={b_el: Flow(nominal_capacity=30),
b_th: Flow(nominal_capacity=40)},
outputs={b_el: Flow(nominal_value=30),
b_th: Flow(nominal_value=40)},
conversion_factors={b_el: 0.3, b_th: 0.4})

A CHP power plant with 70% coal and 30% natural gas can be defined with two inputs and two outputs:
Expand All @@ -359,8 +359,8 @@ A CHP power plant with 70% coal and 30% natural gas can be defined with two inpu
solph.components.Converter(
label='pp_chp',
inputs={b_gas: Flow(), b_coal: Flow()},
outputs={b_el: Flow(nominal_capacity=30),
b_th: Flow(nominal_capacity=40)},
outputs={b_el: Flow(nominal_value=30),
b_th: Flow(nominal_value=40)},
conversion_factors={b_el: 0.3, b_th: 0.4,
b_coal: 0.7, b_gas: 0.3})

Expand Down
8 changes: 4 additions & 4 deletions examples/activity_costs/activity_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ def main():
activity_costs = np.full(periods, 5)
activity_costs[18:] = 0

es = solph.EnergySystem(timeindex=time)
es = solph.EnergySystem(infer_last_interval=False,timeindex=time)

b_heat = solph.Bus(label="b_heat")

es.add(b_heat)

sink_heat = solph.components.Sink(
label="demand",
inputs={b_heat: solph.Flow(fix=demand_heat, nominal_capacity=1)},
inputs={b_heat: solph.Flow(fix=demand_heat, nominal_value=1)},
)

fireplace = solph.components.Source(
label="fireplace",
outputs={
b_heat: solph.Flow(
nominal_capacity=3,
nominal_value=3,
variable_costs=0,
nonconvex=solph.NonConvex(activity_costs=activity_costs),
)
Expand All @@ -85,7 +85,7 @@ def main():

boiler = solph.components.Source(
label="boiler",
outputs={b_heat: solph.Flow(nominal_capacity=10, variable_costs=1)},
outputs={b_heat: solph.Flow(nominal_value=10, variable_costs=1)},
)

es.add(sink_heat, fireplace, boiler)
Expand Down
22 changes: 11 additions & 11 deletions examples/basic_example/basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def main(dump_and_restore=False):
label="wind",
outputs={
bus_electricity: flows.Flow(
fix=data["wind"], nominal_capacity=1000000
fix=data["wind"], nominal_value=1000000
)
},
)
Expand All @@ -188,20 +188,20 @@ def main(dump_and_restore=False):
label="pv",
outputs={
bus_electricity: flows.Flow(
fix=data["pv"], nominal_capacity=582000
fix=data["pv"], nominal_value=582000
)
},
)
)

# create simple sink object representing the electrical demand
# nominal_capacity is set to 1 because demand_el is not a normalised series
# nominal_value is set to 1 because demand_el is not a normalised series
energysystem.add(
components.Sink(
label="demand",
inputs={
bus_electricity: flows.Flow(
fix=data["demand_el"], nominal_capacity=1
fix=data["demand_el"], nominal_value=1
)
},
)
Expand All @@ -214,26 +214,26 @@ def main(dump_and_restore=False):
inputs={bus_gas: flows.Flow()},
outputs={
bus_electricity: flows.Flow(
nominal_capacity=10e10, variable_costs=50
nominal_value=10e10, variable_costs=50
)
},
conversion_factors={bus_electricity: 0.58},
)
)

# create storage object representing a battery
nominal_capacity = 10077997
nominal_capacity = nominal_capacity / 6
nominal_storage_capacity = 10077997
nominal_storage_capacity = nominal_storage_capacity / 6

battery_storage = components.GenericStorage(
nominal_capacity=nominal_capacity,
nominal_storage_capacity=nominal_storage_capacity,
label=STORAGE_LABEL,
inputs={
bus_electricity: flows.Flow(nominal_capacity=nominal_capacity)
bus_electricity: flows.Flow(nominal_value=nominal_storage_capacity)
},
outputs={
bus_electricity: flows.Flow(
nominal_capacity=nominal_capacity, variable_costs=0.001
nominal_value=nominal_storage_capacity, variable_costs=0.001
)
},
loss_rate=0.00,
Expand Down Expand Up @@ -300,7 +300,7 @@ def main(dump_and_restore=False):
logging.info("**** The script can be divided into two parts here.")
logging.info("Restore the energy system and the results.")

energysystem = EnergySystem()
energysystem = EnergySystem(infer_last_interval=False)
energysystem.restore(dpath=None, filename=None)

# define an alias for shorter calls below (optional)
Expand Down
12 changes: 6 additions & 6 deletions examples/dual_variable_example/dual_variable_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ def main():
energysystem.add(
cmp.Source(
label="pv",
outputs={bus_elec: flows.Flow(fix=pv, nominal_capacity=700)},
outputs={bus_elec: flows.Flow(fix=pv, nominal_value=700)},
)
)

# create simple sink object representing the electrical demand
energysystem.add(
cmp.Sink(
label="demand",
inputs={bus_elec: flows.Flow(fix=demand, nominal_capacity=1)},
inputs={bus_elec: flows.Flow(fix=demand, nominal_value=1)},
)
)

Expand All @@ -215,20 +215,20 @@ def main():
cmp.Converter(
label="pp_gas",
inputs={bus_gas: flows.Flow()},
outputs={bus_elec: flows.Flow(nominal_capacity=400)},
outputs={bus_elec: flows.Flow(nominal_value=400)},
conversion_factors={bus_elec: 0.5},
)
)

# create storage object representing a battery
cap = 400
storage = cmp.GenericStorage(
nominal_capacity=cap,
nominal_storage_capacity=cap,
label="storage",
inputs={bus_elec: flows.Flow(nominal_capacity=cap / 6)},
inputs={bus_elec: flows.Flow(nominal_value=cap / 6)},
outputs={
bus_elec: flows.Flow(
nominal_capacity=cap / 6, variable_costs=0.001
nominal_value=cap / 6, variable_costs=0.001
)
},
loss_rate=0.00,
Expand Down
12 changes: 6 additions & 6 deletions examples/electrical/transshipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def main():
label="line_0",
inputs={b_0: Flow(), b_1: Flow()},
outputs={
b_1: Flow(nominal_capacity=Investment()),
b_0: Flow(nominal_capacity=Investment()),
b_1: Flow(nominal_value=Investment()),
b_0: Flow(nominal_value=Investment()),
},
conversion_factors={(b_0, b_1): 0.95, (b_1, b_0): 0.9},
)
Expand All @@ -154,28 +154,28 @@ def main():
es.add(
cmp.Source(
label="gen_0",
outputs={b_0: Flow(nominal_capacity=100, variable_costs=50)},
outputs={b_0: Flow(nominal_value=100, variable_costs=50)},
)
)

es.add(
cmp.Source(
label="gen_1",
outputs={b_1: Flow(nominal_capacity=100, variable_costs=50)},
outputs={b_1: Flow(nominal_value=100, variable_costs=50)},
)
)

es.add(
cmp.Sink(
label="load_0",
inputs={b_0: Flow(nominal_capacity=150, fix=[0, 1])},
inputs={b_0: Flow(nominal_value=150, fix=[0, 1])},
)
)

es.add(
cmp.Sink(
label="load_1",
inputs={b_1: Flow(nominal_capacity=150, fix=[1, 0])},
inputs={b_1: Flow(nominal_value=150, fix=[1, 0])},
)
)

Expand Down
8 changes: 4 additions & 4 deletions examples/emission_constraint/emission_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

def main():
# create energy system
energysystem = solph.EnergySystem(
energysystem = solph.EnergySystem(infer_last_interval=False,
timeindex=pd.date_range("1/1/2012", periods=3, freq="h")
)

Expand All @@ -57,7 +57,7 @@ def main():
label="biomass",
outputs={
bel: solph.Flow(
nominal_capacity=100,
nominal_value=100,
variable_costs=10,
fix=[0.1, 0.2, 0.3],
custom_attributes={"emission_factor": 0.01},
Expand All @@ -84,7 +84,7 @@ def main():
label="demand",
inputs={
bel: solph.Flow(
nominal_capacity=200,
nominal_value=200,
variable_costs=10,
fix=[0.1, 0.2, 0.3],
)
Expand All @@ -97,7 +97,7 @@ def main():
solph.components.Converter(
label="pp_gas",
inputs={bgas: solph.Flow()},
outputs={bel: solph.Flow(nominal_capacity=200)},
outputs={bel: solph.Flow(nominal_value=200)},
conversion_factors={bel: 0.58},
)
)
Expand Down
12 changes: 6 additions & 6 deletions examples/excel_reader/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def create_nodes(nd=None):
for i, re in nd["renewables"].iterrows():
if re["active"]:
# set static outflow values
outflow_args = {"nominal_capacity": re["capacity"]}
outflow_args = {"nominal_value": re["capacity"]}
# get time series for node and parameter
for col in nd["timeseries"].columns.values:
if col.split(".")[0] == re["label"]:
Expand All @@ -196,7 +196,7 @@ def create_nodes(nd=None):
for i, de in nd["demand"].iterrows():
if de["active"]:
# set static inflow values
inflow_args = {"nominal_capacity": de["nominal value"]}
inflow_args = {"nominal_value": de["nominal value"]}
# get time series for node and parameter
for col in nd["timeseries"].columns.values:
if col.split(".")[0] == de["label"]:
Expand Down Expand Up @@ -226,7 +226,7 @@ def create_nodes(nd=None):
inputs={busd[t["from"]]: solph.Flow(**inflow_args)},
outputs={
busd[t["to"]]: solph.Flow(
nominal_capacity=t["capacity"]
nominal_value=t["capacity"]
)
},
conversion_factors={busd[t["to"]]: t["efficiency"]},
Expand All @@ -240,17 +240,17 @@ def create_nodes(nd=None):
label=s["label"],
inputs={
busd[s["bus"]]: solph.Flow(
nominal_capacity=s["capacity inflow"],
nominal_value=s["capacity inflow"],
variable_costs=s["variable input costs"],
)
},
outputs={
busd[s["bus"]]: solph.Flow(
nominal_capacity=s["capacity outflow"],
nominal_value=s["capacity outflow"],
variable_costs=s["variable output costs"],
)
},
nominal_capacity=s["nominal capacity"],
nominal_storage_capacity=s["nominal capacity"],
loss_rate=s["capacity loss"],
initial_storage_level=s["initial capacity"],
max_storage_level=s["capacity max"],
Expand Down
Empty file modified examples/excel_reader/scenario.xlsx
100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions examples/flexible_modelling/add_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ def run_add_constraints_example(solver="cbc", nologg=False):

sink = cmp.Sink(
label="Sink",
inputs={b_el: Flow(nominal_capacity=40, fix=[0.5, 0.4, 0.3, 1])},
inputs={b_el: Flow(nominal_value=40, fix=[0.5, 0.4, 0.3, 1])},
)
pp_oil = cmp.Converter(
label="pp_oil",
inputs={boil: Flow()},
outputs={b_el: Flow(nominal_capacity=50, variable_costs=25)},
outputs={b_el: Flow(nominal_value=50, variable_costs=25)},
conversion_factors={b_el: 0.39},
)
pp_lig = cmp.Converter(
label="pp_lig",
inputs={blig: Flow()},
outputs={b_el: Flow(nominal_capacity=50, variable_costs=10)},
outputs={b_el: Flow(nominal_value=50, variable_costs=10)},
conversion_factors={b_el: 0.41},
)

Expand Down
Loading