Skip to content

Commit

Permalink
Fix examples, postprocessing, facades in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
simnh committed Feb 28, 2019
1 parent 5ead696 commit 1c5aa34
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 57 deletions.
90 changes: 51 additions & 39 deletions src/oemof/tabular/examples/scripting/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,61 @@
es = EnergySystem(timeindex=timeseries.index)

bus = Bus(label='DE')

wind = fc.Volatile(
label='wind',
carrier="wind",
tech="onshore",
capacity=150,
bus=bus,
profile=timeseries['onshore'])

ccgt = fc.Dispatchable(
label='ccgt',
bus=bus,
carrier="gas",
tech="ccgt",
capacity=100,
marginal_cost=25)

sto = fc.Storage(
label='storage',
bus=bus,
carrier="lithium",
tech="battery",
capacity=20,
storage_capacity=100,
capacity_ratio=1/6
)

load = fc.Load(
label='load',
bus=bus,
amount=500e3,
profile=timeseries['load'])

curtailment = fc.Excess(
label="excess",
bus=bus)

# add the components to the energy system object
es.add(wind, load, sto, ccgt, bus, curtailment)
es.add(bus)

es.add(
fc.Volatile(
label='wind',
carrier="wind",
tech="onshore",
capacity=150,
bus=bus,
profile=timeseries['onshore'])
)

es.add(
fc.Dispatchable(
label='ccgt',
bus=bus,
carrier="gas",
tech="ccgt",
capacity=100,
marginal_cost=25)
)

es.add(
fc.Storage(
label='storage',
bus=bus,
carrier="lithium",
tech="battery",
capacity=20,
balanced=False,
initial_storage_capacity=1,
storage_capacity=100)
)

es.add(
fc.Load(
label='load',
bus=bus,
amount=500e3,
profile=timeseries['load'])
)

es.add(
fc.Excess(
label="excess",
bus=bus)
)

# create model based on energy system and its components
m = Model(es)

# write lp file
m.write(os.path.join(results_path, 'dispatch.lp'),
io_options={'symbolic_solver_labels': True})

# solve the model using cbc solver
m.solve('cbc')

Expand Down
16 changes: 8 additions & 8 deletions src/oemof/tabular/examples/scripting/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@


# plot results with plotly
offline.plot(
stacked_plot(
name,
os.path.join(
os.path.expanduser('~'),
"oemof-results")
),
filename=os.path.join(results_path, 'stacked-plot.html'))
# offline.plot(
# stacked_plot(
# name,
# os.path.join(
# os.path.expanduser('~'),
# "oemof-results")
# ),
# filename=os.path.join(results_path, 'stacked-plot.html'))
8 changes: 4 additions & 4 deletions src/oemof/tabular/facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class Storage(GenericStorage, Facade):
Investment costs for the storage unit e.g in €/MW-capacity
loss: numeric
Standing loss per timestep in % of capacity. Default: 0
storage_capacity_initial: numeric
initial_storage_capacity: numeric
The state of the storage capacity in the first (and last) time step of
optimization. Default: 0.5
input_parameters: dict (optional)
Expand Down Expand Up @@ -604,8 +604,8 @@ def __init__(self, *args, **kwargs):

self.loss = sequence(kwargs.get('loss', 0))

self.storage_capacity_initial = kwargs.get(
'storage_capacity_initial', 0.5)
self.initial_storage_capacity = kwargs.get(
'initial_storage_capacity', 0.5)

self.input_parameters = kwargs.get('input_parameters', {})

Expand All @@ -620,7 +620,7 @@ def build_solph_components(self):
"""
self.nominal_storage_capacity = self.storage_capacity

self.initial_storage_level = self.storage_capacity_initial
self.initial_storage_level = self.initial_storage_capacity

self.loss_rate = self.loss

Expand Down
14 changes: 8 additions & 6 deletions src/oemof/tabular/tools/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ def save(df, name, path=output_path):
duals.columns = duals.columns.droplevel(1)
duals = (duals.T / m.objective_weighting).T
save(duals, "shadow_prices")

filling_levels = views.node_weight_by_type(
m.results, GenericStorage
)
filling_levels.columns = filling_levels.columns.droplevel(1)
save(filling_levels, "filling_levels")

# check if storages exist in energy system nodes
if [n for n in m.es.nodes if isinstance(n, GenericStorage)]:
filling_levels = views.node_weight_by_type(
m.results, GenericStorage
)
filling_levels.columns = filling_levels.columns.droplevel(1)
save(filling_levels, "filling_levels")

0 comments on commit 1c5aa34

Please sign in to comment.