Skip to content

Commit

Permalink
Merge pull request #820 from rl-institut/hotfix/circular-imports
Browse files Browse the repository at this point in the history
Fix circular imports
Local pytest running though (Win+Ubuntu)
  • Loading branch information
smartie2076 authored Mar 4, 2021
2 parents a8517d1 + 2a0cf56 commit f81f96b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 122 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Here is a template for new release sections
- Fix: `ENERGY_PROVIDER` assets are missing parameter `DISPATCHABILITY` when parsed from EPA to MVS (#810)
- Fix: No `DISPATCHABILITY` parameter for `ENERGY_PRODUCTION` assets in EPA (#810)
- Fix: Default value of `MAXIMUM_EMISSIONS` when parsing from EPA (#810)
- Move `process_fixcost` from `E1` to `E0` to avoid circular imports (#820)

## [0.5.4] - 2020-12-18

Expand Down
1 change: 0 additions & 1 deletion src/multi_vector_simulator/C0_data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import multi_vector_simulator.B0_data_input_json as B0
import multi_vector_simulator.C1_verification as C1
import multi_vector_simulator.C2_economic_functions as C2
import multi_vector_simulator.F0_output as F0


def all(dict_values):
Expand Down
47 changes: 46 additions & 1 deletion src/multi_vector_simulator/E0_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def evaluate_dict(dict_values, results_main, results_meta):
store_result_matrix(dict_values[KPI], dict_values[group][asset])

# Add fix project costs
E1.process_fixcost(dict_values)
process_fixcost(dict_values)

logging.info("Evaluating key performance indicators of the system")
E3.all_totals(dict_values)
Expand Down Expand Up @@ -293,3 +293,48 @@ def initalize_kpi(dict_values):
}
}
)


def process_fixcost(dict_values):
r"""
Adds fix costs of the project to the economic evaluation of the energy system.
Parameters
----------
dict_values: dict
All simulation data with inputs and results of the assets
Returns
-------
Updated dict_values with costs attributed in dict values also appended to the dict_values[KPI] (scalar results)
Notes
-----
Function is tested with:
- test_E0_evaluation.test_process_fixcost()
"""
for asset in dict_values[FIX_COST]:
# Add parameters that are needed for E2.get_costs()
dict_values[FIX_COST][asset].update(
{
OPTIMIZED_ADD_CAP: {VALUE: 1},
INSTALLED_CAP: {VALUE: 0},
LIFETIME_PRICE_DISPATCH: {VALUE: 0},
FLOW: pd.Series([0, 0]),
}
)

E2.get_costs(dict_values[FIX_COST][asset], dict_values[ECONOMIC_DATA])
# Remove all parameters that were added before and the KPI that do not apply
for key in [
OPTIMIZED_ADD_CAP,
LIFETIME_PRICE_DISPATCH,
INSTALLED_CAP,
FLOW,
COST_DISPATCH,
]:
dict_values[FIX_COST][asset].pop(key)
store_result_matrix(
dict_values[KPI], dict_values[FIX_COST][asset], fix_cost=True
)
47 changes: 0 additions & 47 deletions src/multi_vector_simulator/E1_process_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
LIFETIME_PRICE_DISPATCH,
)

from multi_vector_simulator.E0_evaluation import store_result_matrix
import multi_vector_simulator.E2_economics as E2

# Determines which assets are defined by...
# a influx from a bus
Expand Down Expand Up @@ -1095,48 +1093,3 @@ def get_units_of_cost_matrix_entries(dict_economic, kpi_list):
else:
unit_list.append(kpi_cost_unit_dict[key])
return unit_list


def process_fixcost(dict_values):
r"""
Adds fix costs of the project to the economic evaluation of the energy system.
Parameters
----------
dict_values: dict
All simulation data with inputs and results of the assets
Returns
-------
Updated dict_values with costs attributed in dict values also appended to the dict_values[KPI] (scalar results)
Notes
-----
Function is tested with:
- test_E1_process_results.test_process_fixcost()
"""
for asset in dict_values[FIX_COST]:
# Add parameters that are needed for E2.get_costs()
dict_values[FIX_COST][asset].update(
{
OPTIMIZED_ADD_CAP: {VALUE: 1},
INSTALLED_CAP: {VALUE: 0},
LIFETIME_PRICE_DISPATCH: {VALUE: 0},
FLOW: pd.Series([0, 0]),
}
)

E2.get_costs(dict_values[FIX_COST][asset], dict_values[ECONOMIC_DATA])
# Remove all parameters that were added before and the KPI that do not apply
for key in [
OPTIMIZED_ADD_CAP,
LIFETIME_PRICE_DISPATCH,
INSTALLED_CAP,
FLOW,
COST_DISPATCH,
]:
dict_values[FIX_COST][asset].pop(key)
store_result_matrix(
dict_values[KPI], dict_values[FIX_COST][asset], fix_cost=True
)
73 changes: 64 additions & 9 deletions tests/test_E0_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import mock
import pandas as pd
import numpy as np

import multi_vector_simulator.A0_initialization as A0
import multi_vector_simulator.B0_data_input_json as B0
Expand All @@ -14,15 +15,8 @@

from multi_vector_simulator.utils.constants import OUTPUT_FOLDER

from multi_vector_simulator.utils.constants_json_strings import (
VALUE,
KPI,
KPI_SCALARS,
KPI_COST_MATRIX,
KPI_SCALAR_MATRIX,
KPI_SCALARS_DICT,
OPTIMIZED_FLOWS,
)
from multi_vector_simulator.utils.constants_json_strings import *

from _constants import (
TEST_REPO_PATH,
INPUT_FOLDER,
Expand Down Expand Up @@ -142,6 +136,67 @@ def test_evaluate_check_dict_fields_in_output_dict_under_kpi_scalar_fields():
# assert k in KPI_SCALARS


def test_process_fixcost():
economic_data = {
PROJECT_DURATION: {VALUE: 20},
ANNUITY_FACTOR: {VALUE: 1},
CRF: {VALUE: 1},
DISCOUNTFACTOR: {VALUE: 0},
TAX: {VALUE: 0},
CURR: CURR,
}
fix_cost_entry = "one entry"
dict_test = {
ECONOMIC_DATA: economic_data,
SIMULATION_SETTINGS: {EVALUATED_PERIOD: {VALUE: 365, UNIT: "Days"}},
FIX_COST: {
fix_cost_entry: {
LABEL: fix_cost_entry,
SPECIFIC_COSTS_OM: {VALUE: 1, UNIT: CURR},
SPECIFIC_COSTS: {VALUE: 1, UNIT: CURR},
DEVELOPMENT_COSTS: {VALUE: 1, UNIT: CURR},
LIFETIME: {VALUE: 20},
AGE_INSTALLED: {VALUE: 0},
LIFETIME_SPECIFIC_COST: {VALUE: 1, UNIT: CURR},
LIFETIME_SPECIFIC_COST_OM: {VALUE: 1, UNIT: CURR},
ANNUITY_SPECIFIC_INVESTMENT_AND_OM: {VALUE: 1, UNIT: CURR},
SIMULATION_ANNUITY: {VALUE: 1, UNIT: CURR},
SPECIFIC_REPLACEMENT_COSTS_INSTALLED: {VALUE: 1, UNIT: CURR},
SPECIFIC_REPLACEMENT_COSTS_OPTIMIZED: {VALUE: 1, UNIT: CURR},
}
},
}
E0.initalize_kpi(dict_test)
E0.process_fixcost(dict_test)
assert (
fix_cost_entry in dict_test[KPI][KPI_COST_MATRIX][LABEL].values
), f"The fix cost entry `{fix_cost_entry}` is not added to the cost matrix ({KPI_COST_MATRIX})."
for k in [
COST_TOTAL,
COST_OPERATIONAL_TOTAL,
COST_INVESTMENT,
COST_UPFRONT,
COST_REPLACEMENT,
COST_OM,
ANNUITY_TOTAL,
ANNUITY_OM,
]:
assert isinstance(dict_test[KPI][KPI_COST_MATRIX][k][0], float) or isinstance(
dict_test[KPI][KPI_COST_MATRIX][k][0], int
), f"A float or int should be added for fix cost entry `{fix_cost_entry}` and its KPI `{k}`."
for k in [
COST_DISPATCH,
LCOE_ASSET,
]:
assert np.isnan(
dict_test[KPI][KPI_COST_MATRIX][k][0]
), f"No value should be added for fix cost entry `{fix_cost_entry}` and KPI `{k}`, but value {dict_test[KPI][KPI_COST_MATRIX][k][fix_cost_entry]} is attributed."

assert (
fix_cost_entry not in dict_test[KPI][KPI_SCALAR_MATRIX][LABEL].values
), f"No line should be added for the fix cost entry `{fix_cost_entry}` to the scalar matrix ({KPI_SCALAR_MATRIX})."


def teardown_module():
# Remove the output folder
if os.path.exists(TEST_OUTPUT_PATH):
Expand Down
64 changes: 0 additions & 64 deletions tests/test_E1_process_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import multi_vector_simulator.D0_modelling_and_optimization as D0
import multi_vector_simulator.E1_process_results as E1

from multi_vector_simulator.E0_evaluation import initalize_kpi

from multi_vector_simulator.utils.constants import OUTPUT_FOLDER, CSV_EXT

from multi_vector_simulator.utils.constants_json_strings import *
Expand All @@ -27,7 +25,6 @@
PATH_INPUT_FOLDER,
PATH_OUTPUT_FOLDER,
TEST_INPUT_DIRECTORY,
# JSON_PATH,
CSV_ELEMENTS,
)

Expand Down Expand Up @@ -309,67 +306,6 @@ def test_cut_below_micro_pd_Series_larger_0_smaller_threshold(caplog):
).all(), f"One value in pd.Series is below 0 but smaller then the threshold, its value should be changed to zero (but it is {result})."


def test_process_fixcost():
economic_data = {
PROJECT_DURATION: {VALUE: 20},
ANNUITY_FACTOR: {VALUE: 1},
CRF: {VALUE: 1},
DISCOUNTFACTOR: {VALUE: 0},
TAX: {VALUE: 0},
CURR: CURR,
}
fix_cost_entry = "one entry"
dict_test = {
ECONOMIC_DATA: economic_data,
SIMULATION_SETTINGS: {EVALUATED_PERIOD: {VALUE: 365, UNIT: "Days"}},
FIX_COST: {
fix_cost_entry: {
LABEL: fix_cost_entry,
SPECIFIC_COSTS_OM: {VALUE: 1, UNIT: CURR},
SPECIFIC_COSTS: {VALUE: 1, UNIT: CURR},
DEVELOPMENT_COSTS: {VALUE: 1, UNIT: CURR},
LIFETIME: {VALUE: 20},
AGE_INSTALLED: {VALUE: 0},
LIFETIME_SPECIFIC_COST: {VALUE: 1, UNIT: CURR},
LIFETIME_SPECIFIC_COST_OM: {VALUE: 1, UNIT: CURR},
ANNUITY_SPECIFIC_INVESTMENT_AND_OM: {VALUE: 1, UNIT: CURR},
SIMULATION_ANNUITY: {VALUE: 1, UNIT: CURR},
SPECIFIC_REPLACEMENT_COSTS_INSTALLED: {VALUE: 1, UNIT: CURR},
SPECIFIC_REPLACEMENT_COSTS_OPTIMIZED: {VALUE: 1, UNIT: CURR},
}
},
}
initalize_kpi(dict_test)
E1.process_fixcost(dict_test)
assert (
fix_cost_entry in dict_test[KPI][KPI_COST_MATRIX][LABEL].values
), f"The fix cost entry `{fix_cost_entry}` is not added to the cost matrix ({KPI_COST_MATRIX})."
for k in [
COST_TOTAL,
COST_OPERATIONAL_TOTAL,
COST_INVESTMENT,
COST_UPFRONT,
COST_REPLACEMENT,
COST_OM,
ANNUITY_TOTAL,
ANNUITY_OM,
]:
assert isinstance(dict_test[KPI][KPI_COST_MATRIX][k][0], float) or isinstance(
dict_test[KPI][KPI_COST_MATRIX][k][0], int
), f"A float or int should be added for fix cost entry `{fix_cost_entry}` and its KPI `{k}`."
for k in [
COST_DISPATCH,
LCOE_ASSET,
]:
assert np.isnan(
dict_test[KPI][KPI_COST_MATRIX][k][0]
), f"No value should be added for fix cost entry `{fix_cost_entry}` and KPI `{k}`, but value {dict_test[KPI][KPI_COST_MATRIX][k][fix_cost_entry]} is attributed."

assert (
fix_cost_entry not in dict_test[KPI][KPI_SCALAR_MATRIX][LABEL].values
), f"No line should be added for the fix cost entry `{fix_cost_entry}` to the scalar matrix ({KPI_SCALAR_MATRIX})."


"""
def test_get_optimal_cap_optimize_input_flow_timeseries_peak_provided():
pass
Expand Down

0 comments on commit f81f96b

Please sign in to comment.