Variable costs in multiperiod model

Dear all,

I am very close to setting up a multiperiod model, but keep getting an indexing error relating to the variable costs
index 2 is out of bounds for axis 0 with size 2

However, I can’t really figure out what this error is trying to tell me. With the exception of an electricity import component - which takes a timeseries as its variable costs - all variable costs are either just a scalar or an array of length 2.
Therefore I can only assume I can’t pass a timeseries for variable costs for the electricity import because that has 17520 timesteps or am I overlooking something?

Thx in advance and all the best,


Hello Moritz,

from your posting, I assume you are running a two year model with 8,760 hours for each year, right? Also, I assume you use the years as periods, so you consider two periods with 17,520 time steps in total.

Now you have to pay attention to use the right indexing. Variable costs, as most parameters, are indexed in TIMESTEPS. So you have to either provide a scalar value that is under the hood transferred to a sequence or you have to provide an iterable with 17,520 values.

You could go for something like this.

my_sample_flow = solph.Flow(
    variable_costs = [3] * 8760 + [2] * 8760

Hi Johannes,

thanks again for your quick response!

Just to clarify: “under the hood” would be done automatically in oemof if I only provided a scalar value? But once I provide a list with a scalar for each period, I would have to make sure to turn that into an iterable with 17520 values?


Yes, this is what the sequence function of oemof.solph_plumbing does for you.

Note that currently, oemof.solph will also do the discounting for you in a multi-period model (if the discount_rate attribute of your Model is other than 0). If you want to work with real cost values (which is more common and also more handy, just set it to 0).

thanks for the quick reply from my side as well, I wanted to deepen on this question:
I also have two periods, 8760 timesteps each. I read my data using and the result is a pandas.core.series.Series object called costs_gas_consumption with the length of 17520 containing numpy.float64 values.

I than pass this to the variable costs like this:

# sources
        outputs={bgas: Flow(variable_costs= costs_gas_consumption)

Is this then the correct approach?

Best regards!

Hi @Siebenfurcht,

well actually, you don’t need to adjust that, provided your periods definition is correct. Then the 8760th (zero-based indexing) value and all that follow should be attributed to period 2.

I would recommend using a list or a numpy array for passing the variable costs. If you are facing trouble, feel free to share more of your code and processing so it gets easier to trace a potential error.

Best regards and good luck!

Hello @dlr_jk,

thanks for your reply. Since the feature is new I have been looking for discussions on this.

Currently I am loading the data with panda:
data = pd.read_csv(filename)

Then I am passing the data like this as variable costs:
costs_gas_consumption = ((data["Gas_price"] + data["CO2_price"] * 0.202)

As far as I see it is working like this. I was just replying to this thread since I did not find an example for Multiperiod, which was similar to this.

Best Regards!