Output of DSM parameters (DSM-Method "DLR")

Hello community,

I want to check, if all parameters are on the right place in oemof. Therefore, I am using the function:


The function works fine, if I use the DSM-Method “oemof”. However, changing the DSM-Method to “DLR” following error occurs: ValueError: arrays must all be same length.
I found out that the error disappears when changing the parameter “demand” in SinkDSM to a fix number. However, I need a time series for modelling my energy system. I appreciate any help! Thanks!

Br, Alex

from oemof import solph
import pandas as pd

# Create profiles
pv_timeseries = [0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0] * 365
demand_timeseries = [1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1] * 365

# Create Energy System
datetimeindex = pd.date_range(start='1/1/2013', periods=8760, freq='H')
es = solph.EnergySystem(timeindex=datetimeindex)

# Create bus for electricity
b_elec = solph.Bus(label='electricity_bus')

# Create a back supply
grid = solph.Source(label='grid_source',
                    b_elec: solph.Flow(

# Create a wind supply
wind = solph.Source(label='wind_source',
                      b_elec: solph.Flow(
                      fix = pv_timeseries,
                      nominal_value = 50)}

# Create DSM Sink - DLR
                            inputs={b_elec: solph.Flow()},
                            demand = 5 * demand_timeseries,
                            #demand = 5,
                            capacity_down = 3,
                            capacity_up = 3,
                            delay_time = 24,
                            shift_time = 8760, 
                            max_capacity_down = 1,
                            max_demand = 1,
                            max_capacity_up = 1,
                            shed_eligibility = False,

# Create Sink for excess electricity
excess = solph.Sink(label="excess",
                    inputs={b_elec: solph.Flow()}

# Add buses, sources and sinks to the model
es.add(b_elec, grid, wind, excess)

# Initialise the model
model = solph.Model(es)

# Solve the model
model.solve(solver="gurobi", solve_kwargs={"tee": True})

# Results
Ergebnisse = solph.processing.convert_keys_to_strings(solph.processing.results(model)) 
Parameter = solph.processing.convert_keys_to_strings(solph.processing.parameter_as_dict(model))

I just informed the original author of that method about your problem. Maybe, he can help. (Please note that the DSM components are still experimental.)

Hum, thanks for this interesting post and sorry for the late reply. I’m the one who implemented the component alongside with some other demand response extensions for oemof.solph.

To be honest, I’ve simply never used the results extraction functions convert_keys_to_strings and
parameter_as_dict you are referring to.

While being experimental, I’ve carefully tested the implementation of all approaches. You can find some example for usage here: https://github.com/jokochems/DR_modeling_tutorial
I assume that it has to do with the variable / data structure being more complicated and simply not tailored to these “standard” extraction methods.

I’d suggest that you simply go with

results = solph.processing.results(model)
dsm_results = views.node(results, electricity_bus)

to inspect the resulting demand flow after demand response and use the results extraction routine I provide in the tutorial for now.
Also you can prettyprint the pyomo components to make sure they are working as intended:
Only do this for real small models (like a couple of timesteps) to be able to make sense of the output.

Besides, when you use the DLR approach, you have to set the shift_time smaller than the delay_time. If demand response is not your main focus, sticking to the oemof approach will be all fine and not so hard to parameterize.

I’ll definitely have a closer look on the processing methods you are referring to and come back to you if you’d still need help.

Best regards,

Text and images licensed under CC BY 4.0Data licensed under CC0 1.0Code licensed under MITSite terms of serviceOpenmod mailing listOpenmod wiki.