Implement a variable electricity import price
Hi. I have a variable electricity price for my project site. Is there a method to switch from fixed to variable price?
Hi @oum96-mah! Sadly, it is not possible to define an electricity provide with an electricity price based on the hour of the year. If you have coding experience, you could introduce this feature. Otherwise, I would recommend to check out the not-as-user-friendly Multi Vector Simulator (https://github.com/rl-institut/multi-vector-simulator/). There, you can define your energy system via csv files, and also define specific parameters (like efficiencies, dispatch prices and energy prices) as a timeseries.
Related to #169
Here is a list of what would need to be done to implement a variable electricity (import) price. Variable or function names are suggestions and might be improved on, looking at existing naming conventions.
There are two options:
a) Push offgridders to accept both string and float for maingrid_electricity_price
b) Properly define a new parameter in case_definitions, eg. maingrid_electricity_price_is_fix== FALSE / TRUE, and depending on that require a title_maingrid_electricity_price in project_sites or not.
I explain the option a) here now, as it works well if you have a pilot site that has a variable price, or does not. The scenarios are not based on the electricity price timeseries (ie. focussing on sizing implications). If the focus was more on creating multiple cases applied to one test stite, where either the electricity price was variable or it was not (ie. impact assessment of that) then b) would be better.
- [ ] Create a simple benchmark test that assesses the functionality of the maingrid electricity price (see comment below), before you change anything. The electricity price must be a scalar here.
- [ ] Add a column in
./inputs/timeseriesandtest_site.csvfor your electricty price timeseries - [ ] Change description of parameter
maingrid_electricity_priceon tabinput_constantsfrom/kWhtofloat in /kWh or title of timeseries in input file with each value in /kWh - [ ] Try to define
maingrid_electricity_priceas a string, and see where it gives you an error message (that is where you need to change code) - [ ] Allow
maingrid_electricity_priceto both be a string or a float: If it is a value, then use that, if it is a string, parse as string - [ ] If string, then use functions that also parse
title_pvetc. to parse the new column. For this, the approach b) would be a bit easier, as then you could simple add atitle_maingrid_electricy_pricein https://github.com/rl-institut/offgridders/blob/90d22741d7b4c977966ec9a2a0aacc0f909efcf0/src/B_read_from_files.py#L532 in this list https://github.com/rl-institut/offgridders/blob/90d22741d7b4c977966ec9a2a0aacc0f909efcf0/src/B_read_from_files.py#L551-L558. Maybe it is easiest to create one or multiple new functions from the lines https://github.com/rl-institut/offgridders/blob/90d22741d7b4c977966ec9a2a0aacc0f909efcf0/src/B_read_from_files.py#L567 until the end of the function, this would also make writingpytestseasier and you could re-use existing functions. - [ ] The values should be in a
pandas.seriesformat at the end. - [ ] Make sure the maingrid source is defined with the new
pandas.seriesasvariable_costin https://github.com/rl-institut/offgridders/blob/9095014d054b26e1c0a02b51d237840e1b8e9ea6/src/G2a_oemof_busses_and_componets.py#L523 andpointofcoupling_consumption_oem. https://github.com/rl-institut/offgridders/blob/9095014d054b26e1c0a02b51d237840e1b8e9ea6/src/G2a_oemof_busses_and_componets.py#L536-L537 and https://github.com/rl-institut/offgridders/blob/9095014d054b26e1c0a02b51d237840e1b8e9ea6/src/G2a_oemof_busses_and_componets.py#L562-L563 must result in apandas.seriesagain. - [ ] You can check if the price series is integrated correctly by assessing the
lpfile that can be exported - [ ] Make sure that in https://github.com/rl-institut/offgridders/blob/9095014d054b26e1c0a02b51d237840e1b8e9ea6/src/G3a_economic_evaluation.py#L420 the cost are is calculated correctly, ie. that https://github.com/rl-institut/offgridders/blob/9095014d054b26e1c0a02b51d237840e1b8e9ea6/src/G3a_economic_evaluation.py#L425-L432 can deal with an
pandas.series - [ ] Create a benchmark test for your function, ie. a variable
maingrid_electricity_price. This one and the one from the beginning must run though with Offgridders. If this becomes an issue, you could also generate an imaginativepandas.seriesfrom the scalar value in the pre-processing steps.
I highly recommend creating pytest unit-tests along the way to test if what you want to change is working or not, ie. for the different functions that you are changing.
As two simple benchmark tests, I would suggest the following:
- Case with only demand and connection to the main grid for consumption (no PV, no battery, no feedin)
- No costs connected to any assets (also the PCC), only to the
maingrid_electricity_price - Simple, first benchmark test with
maingrid_electricity_priceas a scalar, that makes sure thatsum(demand)*maingrid_electricity_price==costs calculated by Offgridders. This should already pass right now, but by creating the test you make sure that it still passes after you have introduced your changes. - Second benchmark test, in which
maingrid_electricity_priceis a timeseries, where you assess thatsum(demand(t)*maingrid_electricity_price(t)) == costs calculated by Offgridders. This will proove that your introduced algorithm works properly.
The actual values of the demand or electricity price timeseries (as long as they are not 0 all the time) does not matter. You can limit the evaluated timeframe to a day or a week, as we are not dealing with a plausibility test of renewables here.
You would probably create two duplicates of \tests\inputs and its contents for this in the test folder, and those contain the inputs to the benchmark test. You can add a new file test_benchmark_maingrid_electricity_price.py to the test folder to write the benchmark tests.