Skip to content

Commit

Permalink
Implement new KPI: GENSET_HOURS_OF_OPERATION
Browse files Browse the repository at this point in the history
- Add `GENSET_HOURS_OF_OPERATION` to `constants.py` and in `C1.overall_results_title`
- Add function `G3.get_hours_of_operation()` for generator evaluation, including pytests
  • Loading branch information
smartie2076 committed May 4, 2021
1 parent 6b5689b commit 3c44ddf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 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 @@ -1308,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
30 changes: 30 additions & 0 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 @@ -496,9 +497,38 @@ def get_genset(case_dict, oemof_results, electricity_bus_ac, e_flows_df):
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
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
28 changes: 28 additions & 0 deletions tests/test_G3_oemof_evaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pandas as pd
import numpy as np
from pandas.util.testing import assert_series_equal

import src.G3_oemof_evaluate as G3
from src.constants import EVALUATED_DAYS, GENSET_HOURS_OF_OPERATION


def test_get_hours_of_operation():
genset_generation = pd.Series([0, 0, 0, 0.5, 2])
oemof_results = {}
case_dict = {EVALUATED_DAYS: 5}
operation_boolean = G3.get_hours_of_operation(
oemof_results, case_dict, genset_generation
)
exp = pd.Series([0, 0, 0, 1, 1])
assert (
operation_boolean.sum() == 2
), f"It was expected that the number of operation hours in the evaluated timeframe was 2, but it is {operation_boolean.sum()}."
assert_series_equal(
genset_generation.astype(np.float64), exp(np.float64), check_names=False,
), f"The operational hours pd.Series should be the same when calculated with the function to the expected series."
assert (
GENSET_HOURS_OF_OPERATION in oemof_results
), f"Parameter {GENSET_HOURS_OF_OPERATION} is not in the oemof_results, but was expected."
assert oemof_results[GENSET_HOURS_OF_OPERATION] == 2 * (
365 / 5
), f"Parameter {GENSET_HOURS_OF_OPERATION} is not of expected annual value {2*365/5}, but {oemof_results[GENSET_HOURS_OF_OPERATION]}."

0 comments on commit 3c44ddf

Please sign in to comment.