Skip to content

Commit

Permalink
Merge pull request #153 from rl-institut/patch/fuel_price_and_generat…
Browse files Browse the repository at this point in the history
…or_operation

Patch/fuel price and generator operation
  • Loading branch information
smartie2076 authored May 4, 2021
2 parents 3c3349c + 2650237 commit 90d2274
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 91 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ Here is a template for new release sections

### Added
- Version number with `src/version.py` (#150)
- Constant variables in `constants.py`: `INPUT_TEMPLATE_EXCEL_XLSX`(#150)
- Constant variables in `constants.py`: `INPUT_TEMPLATE_EXCEL_XLSX`(#150), `GENSET_HOURS_OF_OPERATION` (#153)
- Added pytests for `D1.crf` and `D1.present_value_of_changing_fuel_price` (#153)
- Implement new KPI: `GENSET_HOURS_OF_OPERATION` with new function `G3.get_hours_of_operation()` for generator evaluation, including pytests (#153)

### Changed
- Execute all pytests in Travis `.travis.yml` (#150)
- Added version number to `setup.py` (#150)
- Moved `main()` from `Offgridders.py` to new file `src/cli.py` (#150)
- Enable benchmark tests for Offgridders: Add optional argument `input_file` to `main()` (#150)
- Added `GENSET_HOURS_OF_OPERATION` in `C1.overall_results_title` (#153)

### Removed
-

### Fixed
- Basic pytest to ensure no termination with test input file (`tests/inputs/pytest_test.xlsx`) (#150)
- `present_value_of_changing_fuel_price` now correctly calculated, fixed function call of `D1.present_value_of_changing_fuel_price` in `D0` (#153)

## [Offgridders V4.6.1] - 2020-11-07

Expand Down
7 changes: 3 additions & 4 deletions src/B_read_from_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,9 @@ def process_excel_file(input_excel_file):
# -------- Check for, create or empty results directory -----------------------#
check_output_directory(settings, input_excel_file)

(
parameters_constant_units,
parameters_constant_values,
) = get_parameters_constant(input_excel_file, sheet_input_constant)
(parameters_constant_units, parameters_constant_values,) = get_parameters_constant(
input_excel_file, sheet_input_constant
)
parameters_sensitivity = get_parameters_sensitivity(
input_excel_file, sheet_input_sensitivity
)
Expand Down
19 changes: 7 additions & 12 deletions src/C_sensitivity_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
TOTAL_WIND_GENERATION_KWH,
TOTAL_GENSET_GENERATION_KWH,
CONSUMPTION_FUEL_ANNUAL_L,
GENSET_HOURS_OF_OPERATION,
CONSUMPTION_MAIN_GRID_MG_SIDE_ANNUAL_KWH,
FEEDIN_MAIN_GRID_MG_SIDE_ANNUAL_KWH,
RESULTS_ANNUITIES,
Expand Down Expand Up @@ -270,10 +271,7 @@ def get(settings, parameters_constant_values, parameters_sensitivity, project_si
sensitivity_array_dict,
total_number_of_experiments,
) = all_possible(
settings,
parameters_constant_values,
parameters_sensitivity,
project_sites,
settings, parameters_constant_values, parameters_sensitivity, project_sites,
)

elif settings[SENSITIVITY_ALL_COMBINATIONS] is False:
Expand All @@ -283,10 +281,7 @@ def get(settings, parameters_constant_values, parameters_sensitivity, project_si
sensitivity_array_dict,
total_number_of_experiments,
) = with_base_case(
settings,
parameters_constant_values,
parameters_sensitivity,
project_sites,
settings, parameters_constant_values, parameters_sensitivity, project_sites,
)

else:
Expand Down Expand Up @@ -339,10 +334,9 @@ def get(settings, parameters_constant_values, parameters_sensitivity, project_si
# Get blackout_experiment_s for sensitvitiy #
#######################################################
# Creating dict of possible blackout scenarios (combinations of durations frequencies
(
blackout_experiment_s,
blackout_experiments_count,
) = blackout(sensitivity_array_dict, parameters_constant_values, settings)
(blackout_experiment_s, blackout_experiments_count,) = blackout(
sensitivity_array_dict, parameters_constant_values, settings
)

# save all Experiments with all used input data to csv
csv_dict = deepcopy(sensitivitiy_experiment_s)
Expand Down Expand Up @@ -1315,6 +1309,7 @@ def overall_results_title(settings, number_of_project_sites, sensitivity_array_d
TOTAL_GENSET_GENERATION_KWH,
CONSUMPTION_FUEL_ANNUAL_KWH,
CONSUMPTION_FUEL_ANNUAL_L,
GENSET_HOURS_OF_OPERATION,
CONSUMPTION_MAIN_GRID_MG_SIDE_ANNUAL_KWH,
FEEDIN_MAIN_GRID_MG_SIDE_ANNUAL_KWH,
]
Expand Down
14 changes: 6 additions & 8 deletions src/D0_process_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,12 @@ def economic_values(experiment):
)

if PRICE_FUEL not in experiment:
present_value_changing_fuel_price = (
economics.present_value_of_changing_fuel_price(
experiment[FUEL_PRICE],
experiment[PROJECT_LIFETIME],
experiment[WACC],
experiment[FUEL_PRICE_CHANGE_ANNUAL],
experiment[CRF],
)
present_value_changing_fuel_price = economics.present_value_of_changing_fuel_price(
fuel_price=experiment[FUEL_PRICE],
project_lifetime=experiment[PROJECT_LIFETIME],
wacc=experiment[WACC],
crf=experiment[CRF],
fuel_price_change_annual=experiment[FUEL_PRICE_CHANGE_ANNUAL],
)
experiment.update({PRICE_FUEL: present_value_changing_fuel_price})
else:
Expand Down
8 changes: 5 additions & 3 deletions src/E_blackouts_central_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ def get_blackouts(settings, blackout_experiment_s):
in grid_availability_df.columns
):
count_of_red_data = count_of_red_data + 1
name_of_experiment_requested_from_file_dataset = (
blackout_experiment_s[experiment][EXPERIMENT_NAME]
)
name_of_experiment_requested_from_file_dataset = blackout_experiment_s[
experiment
][
EXPERIMENT_NAME
]
blackout_result = oemof_extension_for_blackouts(
grid_availability_df[
name_of_experiment_requested_from_file_dataset
Expand Down
12 changes: 2 additions & 10 deletions src/G2a_oemof_busses_and_componets.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,7 @@ def genset_fix_minload(


def genset_oem(
micro_grid_system,
bus_fuel,
bus_electricity_ac,
experiment,
number_of_generators,
micro_grid_system, bus_fuel, bus_electricity_ac, experiment, number_of_generators,
):
"""
Generates fossi-fueled genset "transformer_fuel_generator" for OEM with generator efficiency,
Expand Down Expand Up @@ -580,11 +576,7 @@ def pointofcoupling_consumption_oem(


def storage_fix(
micro_grid_system,
bus_electricity_dc,
experiment,
capacity_storage,
power_storage,
micro_grid_system, bus_electricity_dc, experiment, capacity_storage, power_storage,
):
"""
Create storage unit "generic_storage" with fixed capacity,
Expand Down
12 changes: 6 additions & 6 deletions src/G2b_constraints_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ def linear_charge(model, t):
expr = 0
if case_dict[STORAGE_FIXED_CAPACITY] != None:
if case_dict[STORAGE_FIXED_CAPACITY] is False: # Storage subject to OEM
stored_electricity += (
model.GenericInvestmentStorageBlock.storage_content[storage, t]
)
stored_electricity += model.GenericInvestmentStorageBlock.storage_content[
storage, t
]
elif isinstance(
case_dict[STORAGE_FIXED_CAPACITY], float
): # Fixed storage subject to dispatch
Expand Down Expand Up @@ -814,9 +814,9 @@ def discharge_rule_upper(model, t):
expr += model.flow[storage, el_bus, t]
# Get stored electricity at t
if case_dict[STORAGE_FIXED_CAPACITY] is False: # Storage subject to OEM
stored_electricity += (
model.GenericInvestmentStorageBlock.storage_content[storage, t]
)
stored_electricity += model.GenericInvestmentStorageBlock.storage_content[
storage, t
]
elif isinstance(
case_dict[STORAGE_FIXED_CAPACITY], float
): # Fixed storage subject to dispatch
Expand Down
60 changes: 36 additions & 24 deletions src/G3_oemof_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
FEED_INTO_MAIN_GRID_MG_SIDE,
DEMAND_AC,
DEMAND_DC,
GENSET_HOURS_OF_OPERATION,
)


Expand Down Expand Up @@ -222,10 +223,7 @@ def get_shortage(

demand_supplied = e_flows_df[DEMAND] - shortage
annual_value(
TOTAL_DEMAND_SUPPLIED_ANNUAL_KWH,
demand_supplied,
oemof_results,
case_dict,
TOTAL_DEMAND_SUPPLIED_ANNUAL_KWH, demand_supplied, oemof_results, case_dict,
)
annual_value(
TOTAL_DEMAND_SHORTAGE_ANNUAL_KWH, shortage, oemof_results, case_dict
Expand Down Expand Up @@ -397,10 +395,7 @@ def get_inverter(
e_flows_df = join_e_flows_df(inverter_in, INVERTER_INPUT, e_flows_df)

annual_value(
TOTAL_INVERTER_DC_AC_THROUGHPUT_KWH,
inverter_in,
oemof_results,
case_dict,
TOTAL_INVERTER_DC_AC_THROUGHPUT_KWH, inverter_in, oemof_results, case_dict,
)
else:
oemof_results.update({TOTAL_INVERTER_DC_AC_THROUGHPUT_KWH: 0})
Expand Down Expand Up @@ -476,10 +471,7 @@ def get_genset(case_dict, oemof_results, electricity_bus_ac, e_flows_df):
total_genset = genset
for number in range(2, case_dict[NUMBER_OF_EQUAL_GENERATORS] + 1):
genset = electricity_bus_ac[SEQUENCES][
(
(TRANSFORMER_GENSET_ + str(number), BUS_ELECTRICITY_AC),
FLOW,
)
((TRANSFORMER_GENSET_ + str(number), BUS_ELECTRICITY_AC), FLOW,)
]
e_flows_df = join_e_flows_df(
genset, "Genset " + str(number) + " generation", e_flows_df
Expand All @@ -498,19 +490,45 @@ def get_genset(case_dict, oemof_results, electricity_bus_ac, e_flows_df):
genset_capacity = 0
for number in range(1, case_dict[NUMBER_OF_EQUAL_GENERATORS] + 1):
genset_capacity += electricity_bus_ac[SCALARS][
(
(TRANSFORMER_GENSET_ + str(number), BUS_ELECTRICITY_AC),
INVEST,
)
((TRANSFORMER_GENSET_ + str(number), BUS_ELECTRICITY_AC), INVEST,)
]
oemof_results.update({CAPACITY_GENSET_KW: genset_capacity})
elif isinstance(case_dict[GENSET_FIXED_CAPACITY], float):
oemof_results.update({CAPACITY_GENSET_KW: case_dict[GENSET_FIXED_CAPACITY]})
elif case_dict[GENSET_FIXED_CAPACITY] == None:
oemof_results.update({CAPACITY_GENSET_KW: 0})

# Get hours of operation:
if case_dict[GENSET_FIXED_CAPACITY] != None:
get_hours_of_operation(oemof_results, case_dict, e_flows_df[GENSET_GENERATION])
else:
oemof_results.update({GENSET_HOURS_OF_OPERATION: 0})
return e_flows_df


def get_hours_of_operation(oemof_results, case_dict, genset_generation_total):
"""
Calculates the total hours of genset generation (aggregated generation) of the evaluated timeframe.
Parameters
----------
oemof_results: dict
Dict of all results of the simulation
genset_generation_total: pd.Series
Dispatch of the gensets, aggregated
Returns
-------
Updates oemof_results with annual value of the GENSET_HOURS_OF_OPERATION.
"""
operation_boolean = genset_generation_total.where(
genset_generation_total == 0, other=1
)
annual_value(GENSET_HOURS_OF_OPERATION, operation_boolean, oemof_results, case_dict)
return operation_boolean


def get_fuel(case_dict, oemof_results, results):
logging.debug("Evaluate flow: fuel")
if case_dict[GENSET_FIXED_CAPACITY] != None:
Expand Down Expand Up @@ -586,10 +604,7 @@ def get_storage(case_dict, oemof_results, experiment, results, e_flows_df):
]

oemof_results.update(
{
CAPACITY_STORAGE_KWH: storage_capacity,
POWER_STORAGE_KW: storage_power,
}
{CAPACITY_STORAGE_KWH: storage_capacity, POWER_STORAGE_KW: storage_power,}
)

elif isinstance(case_dict[STORAGE_FIXED_CAPACITY], float):
Expand Down Expand Up @@ -654,10 +669,7 @@ def get_national_grid(case_dict, oemof_results, results, e_flows_df, grid_availa
results, BUS_ELECTRICITY_NG_CONSUMPTION
)
consumption_utility_side = bus_electricity_ng_consumption[SEQUENCES][
(
(BUS_ELECTRICITY_NG_CONSUMPTION, TRANSFORMER_PCC_CONSUMPTION),
FLOW,
)
((BUS_ELECTRICITY_NG_CONSUMPTION, TRANSFORMER_PCC_CONSUMPTION), FLOW,)
]
e_flows_df = join_e_flows_df(
consumption_utility_side,
Expand Down
4 changes: 1 addition & 3 deletions src/G4_output_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ def save_mg_flows(experiment, case_dict, e_flows_df, filename):
]

mg_flows = pd.DataFrame(
e_flows_df[DEMAND].values,
columns=[DEMAND],
index=e_flows_df[DEMAND].index,
e_flows_df[DEMAND].values, columns=[DEMAND], index=e_flows_df[DEMAND].index,
)
for entry in flows_connected_to_electricity_mg_bus:
if entry in e_flows_df.columns:
Expand Down
21 changes: 7 additions & 14 deletions src/H0_multicriteria_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ def main_analysis(overallresults, multicriteria_data, settings):
) = format_punctuations(multicriteria_data)

# the cases chosen to analyse in the multicriteria analysis are selected
(
all_results,
cases,
projects_name,
sensibility,
) = presentation(overallresults, parameters)
(all_results, cases, projects_name, sensibility,) = presentation(
overallresults, parameters
)

# the multicriteria analysis with sensibility parameters can only be realised if all combinations have been calculated
if settings[SENSITIVITY_ALL_COMBINATIONS] or not sensibility:
Expand All @@ -84,10 +81,8 @@ def main_analysis(overallresults, multicriteria_data, settings):

# first, a global ranking, for all solutions, is calculated
# evaluations are normalized
global_normalized_evaluations = (
multicriteria_functions.normalize_evaluations(
global_evaluations, weights_criteria, GLOBAL
)
global_normalized_evaluations = multicriteria_functions.normalize_evaluations(
global_evaluations, weights_criteria, GLOBAL
)
all_projects_MCA_data[NORMALIZED_EVALUATIONS][
project
Expand All @@ -109,10 +104,8 @@ def main_analysis(overallresults, multicriteria_data, settings):
# second, each local_evaluations are normalized and a ranking is calculated
local_Ls = []
for evaluation in local_evaluations:
local_normalized_evaluation = (
multicriteria_functions.normalize_evaluations(
evaluation, weights_criteria, LOCAL
)
local_normalized_evaluation = multicriteria_functions.normalize_evaluations(
evaluation, weights_criteria, LOCAL
)
local_Ls_each = multicriteria_functions.rank(
local_normalized_evaluation,
Expand Down
6 changes: 2 additions & 4 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,8 @@ def main(input_file=None):
logging.debug(
"Using grid availability timeseries that was randomly generated."
)
blackout_experiment_name = (
generate_sensitvitiy_experiments.get_blackout_experiment_name(
sensitivity_experiment_s[experiment]
)
blackout_experiment_name = generate_sensitvitiy_experiments.get_blackout_experiment_name(
sensitivity_experiment_s[experiment]
)
sensitivity_experiment_s[experiment].update(
{
Expand Down
1 change: 1 addition & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
TOTAL_GENSET_GENERATION_KWH = "total_genset_generation_kWh"
CONSUMPTION_FUEL_ANNUAL_L = "consumption_fuel_annual_l"
CONSUMPTION_MAIN_GRID_MG_SIDE_ANNUAL_KWH = "consumption_main_grid_mg_side_annual_kWh"
GENSET_HOURS_OF_OPERATION = "generator_operation_hours"
FEEDIN_MAIN_GRID_MG_SIDE_ANNUAL_KWH = "feedin_main_grid_mg_side_annual_kWh"
RESULTS_ANNUITIES = "results_annuities"
ANNUITY_PV = "annuity_pv"
Expand Down
Loading

0 comments on commit 90d2274

Please sign in to comment.