Skip to content

Commit

Permalink
Merge pull request #971 from rl-institut/fix/black-vulnerability
Browse files Browse the repository at this point in the history
Fix/black vulnerability
  • Loading branch information
Bachibouzouk authored Apr 28, 2024
2 parents 72950de + 2d81322 commit 3f6c631
Show file tree
Hide file tree
Showing 38 changed files with 529 additions and 195 deletions.
56 changes: 46 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,24 @@ def generate_parameter_description(input_csv_file, output_rst_file):
see_also = []
lines = (
lines
+ [f".. _{props.ref}:", "", props.label, "^" * len(props.label), "",]
+ [
f".. _{props.ref}:",
"",
props.label,
"^" * len(props.label),
"",
]
+ [f"{p} {props[p]}" for p in parameter_properties]
+ [""]
+ [
"This parameter is used within the following categories: "
+ ", ".join([f":ref:`{cat}`" for cat in props.category.split(";")])
]
+ see_also
+ ["", "",]
+ [
"",
"",
]
)

with open(output_rst_file, "w") as ofs:
Expand Down Expand Up @@ -139,11 +148,22 @@ def generate_parameter_categories(

lines = (
lines
+ [f".. _{props.ref}:", "", cat_label, "^" * len(cat_label), "",]
+ [
f".. _{props.ref}:",
"",
cat_label,
"^" * len(cat_label),
"",
]
+ props.description.split("\\n")
+ ["",]
+ [
"",
]
+ [f"* :ref:`{p}`" for p in parameter_per_cat]
+ ["", "",]
+ [
"",
"",
]
)

with open(output_rst_file, "w") as ofs:
Expand Down Expand Up @@ -194,10 +214,17 @@ def generate_kpi_categories(input_param_csv_file, input_cat_csv_file, output_rst

lines = (
lines
+ [f"{props.description} These are the calculated {props.category} KPI:",]
+ ["",]
+ [
f"{props.description} These are the calculated {props.category} KPI:",
]
+ [
"",
]
+ [f"* :ref:`{parameters[p]} <{p}>`" for p in parameter_per_cat]
+ ["", "",]
+ [
"",
"",
]
)

with open(output_rst_file, "w") as ofs:
Expand Down Expand Up @@ -290,10 +317,19 @@ def generate_kpi_description(input_csv_file, output_path):

# Write lines based on definitions to an *.inc file
lines = (
[f".. _{props.ref}:", "", title, "^" * len(title), "",]
[
f".. _{props.ref}:",
"",
title,
"^" * len(title),
"",
]
+ [f"{p} {props[p]}" for p in parameter_properties]
+ [f":Related indicators: {see_also}"]
+ ["", "",]
+ [
"",
"",
]
)

with open(os.path.join(output_path, props.ref + ".inc"), "w") as ofs:
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pytest>=5.3.1
black==19.10b0
black==24.3.0
coverage>=4.5
coveralls>=3.0.1
mock>=3.0.5
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def parse_requirements_file(filename):
# called `my_module.py` to exist:
#
# py_modules=["my_module"],
packages=["multi_vector_simulator", "multi_vector_simulator.utils",], # Required
packages=[
"multi_vector_simulator",
"multi_vector_simulator.utils",
], # Required
# Specify which Python versions you support. In contrast to the
# 'Programming Language' classifiers above, 'pip install' will check this
# and refuse to install the project if the version does not match. If you
Expand Down
3 changes: 2 additions & 1 deletion src/multi_vector_simulator/A0_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ def report_arg_parser():
:return: parser
"""
parser = argparse.ArgumentParser(
prog="mvs_report", description="Display the report of a MVS simulation",
prog="mvs_report",
description="Display the report of a MVS simulation",
)
parser.add_argument(
"-pdf",
Expand Down
7 changes: 5 additions & 2 deletions src/multi_vector_simulator/A1_csv_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@


def create_input_json(
input_directory, pass_back=True,
input_directory,
pass_back=True,
):
"""Convert csv files to json file as input for the simulation.
Expand Down Expand Up @@ -515,7 +516,9 @@ def create_json_from_csv(
df.loc[STORAGE_FILENAME][column]
)
storage_dict = add_storage_components(
storage_file_name, input_directory, single_dict[column][LABEL],
storage_file_name,
input_directory,
single_dict[column][LABEL],
)
single_dict[column].update(storage_dict)

Expand Down
4 changes: 3 additions & 1 deletion src/multi_vector_simulator/B0_data_input_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module B0 - Data input json
===========================
"""

import logging
import copy
import json
Expand Down Expand Up @@ -321,7 +322,8 @@ def load_json(
os.replace(
path_input_file,
os.path.join(
dict_values[SIMULATION_SETTINGS][PATH_OUTPUT_FOLDER_INPUTS], CSV_FNAME,
dict_values[SIMULATION_SETTINGS][PATH_OUTPUT_FOLDER_INPUTS],
CSV_FNAME,
),
)

Expand Down
69 changes: 53 additions & 16 deletions src/multi_vector_simulator/C0_data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ def energyConversion(dict_values, group):
and HEADER in dict_values[group][asset][EFFICIENCY]
):
receive_timeseries_from_csv(
dict_values[SIMULATION_SETTINGS], dict_values[group][asset], EFFICIENCY,
dict_values[SIMULATION_SETTINGS],
dict_values[group][asset],
EFFICIENCY,
)
# in case there is more than one parameter provided (either (A) n input busses and 1 output bus or (B) 1 input bus and n output busses)
# dictionaries with filenames and headers will be replaced by timeseries, scalars will be mantained
Expand Down Expand Up @@ -398,7 +400,8 @@ def energyStorage(dict_values, group):
for asset in dict_values[group]:
for subasset in [STORAGE_CAPACITY, INPUT_POWER, OUTPUT_POWER]:
define_missing_cost_data(
dict_values, dict_values[group][asset][subasset],
dict_values,
dict_values[group][asset][subasset],
)
evaluate_lifetime_costs(
dict_values[SIMULATION_SETTINGS],
Expand Down Expand Up @@ -504,7 +507,9 @@ def define_missing_cost_data(dict_values, dict_asset):
if DISPATCH_PRICE in dict_asset:
if isinstance(dict_asset[DISPATCH_PRICE][VALUE], dict):
receive_timeseries_from_csv(
dict_values[SIMULATION_SETTINGS], dict_asset, DISPATCH_PRICE,
dict_values[SIMULATION_SETTINGS],
dict_asset,
DISPATCH_PRICE,
)
elif isinstance(dict_asset[DISPATCH_PRICE][VALUE], list):
treat_multiple_flows(dict_asset, dict_values, DISPATCH_PRICE)
Expand All @@ -519,8 +524,14 @@ def define_missing_cost_data(dict_values, dict_asset):
SPECIFIC_COSTS: {VALUE: 0, UNIT: CURR + "/" + UNIT},
SPECIFIC_COSTS_OM: {VALUE: 0, UNIT: CURR + "/" + UNIT_YEAR},
DISPATCH_PRICE: {VALUE: 0, UNIT: CURR + "/" + UNIT + "/" + UNIT_YEAR},
LIFETIME: {VALUE: economic_data[PROJECT_DURATION][VALUE], UNIT: UNIT_YEAR,},
AGE_INSTALLED: {VALUE: 0, UNIT: UNIT_YEAR,},
LIFETIME: {
VALUE: economic_data[PROJECT_DURATION][VALUE],
UNIT: UNIT_YEAR,
},
AGE_INSTALLED: {
VALUE: 0,
UNIT: UNIT_YEAR,
},
}

# checks that an asset has all cost parameters needed for evaluation.
Expand Down Expand Up @@ -722,11 +733,17 @@ def define_auxiliary_assets_of_energy_providers(dict_values, dso_name):
)

dict_availability_timeseries = define_availability_of_peak_demand_pricing_assets(
dict_values, number_of_pricing_periods, months_in_a_period,
dict_values,
number_of_pricing_periods,
months_in_a_period,
)

list_of_dso_energyConversion_assets = add_a_transformer_for_each_peak_demand_pricing_period(
dict_values, dso_dict, dict_availability_timeseries,
list_of_dso_energyConversion_assets = (
add_a_transformer_for_each_peak_demand_pricing_period(
dict_values,
dso_dict,
dict_availability_timeseries,
)
)

define_source(
Expand Down Expand Up @@ -1025,7 +1042,10 @@ def define_transformer_for_peak_demand_pricing(
AVAILABILITY_DISPATCH: timeseries_availability,
EFFICIENCY: {VALUE: 1, UNIT: "factor"},
DEVELOPMENT_COSTS: {VALUE: 0, UNIT: CURR},
SPECIFIC_COSTS: {VALUE: 0, UNIT: CURR + "/" + dict_dso[UNIT],},
SPECIFIC_COSTS: {
VALUE: 0,
UNIT: CURR + "/" + dict_dso[UNIT],
},
# the demand pricing is only applied to consumption
SPECIFIC_COSTS_OM: {
VALUE: dict_dso[PEAK_DEMAND_PRICING][VALUE],
Expand Down Expand Up @@ -1058,7 +1078,10 @@ def define_transformer_for_peak_demand_pricing(
AVAILABILITY_DISPATCH: timeseries_availability,
EFFICIENCY: {VALUE: 1, UNIT: "factor"},
DEVELOPMENT_COSTS: {VALUE: 0, UNIT: CURR},
SPECIFIC_COSTS: {VALUE: 0, UNIT: CURR + "/" + dict_dso[UNIT],},
SPECIFIC_COSTS: {
VALUE: 0,
UNIT: CURR + "/" + dict_dso[UNIT],
},
# the demand pricing is only applied to consumption
SPECIFIC_COSTS_OM: {
VALUE: 0,
Expand All @@ -1068,7 +1091,7 @@ def define_transformer_for_peak_demand_pricing(
OEMOF_ASSET_TYPE: OEMOF_TRANSFORMER,
ENERGY_VECTOR: dict_dso[ENERGY_VECTOR],
AGE_INSTALLED: {VALUE: 0, UNIT: UNIT_YEAR},
TYPE_ASSET: dict_dso.get(TYPE_ASSET)
TYPE_ASSET: dict_dso.get(TYPE_ASSET),
# LIFETIME: {VALUE: 100, UNIT: UNIT_YEAR},
}
if dict_dso.get(DSO_FEEDIN_CAP, None) is not None:
Expand Down Expand Up @@ -1150,7 +1173,10 @@ def define_source(
},
OPTIMIZE_CAP: {VALUE: True, UNIT: TYPE_BOOL},
MAXIMUM_CAP: {VALUE: None, UNIT: "?"},
AGE_INSTALLED: {VALUE: 0, UNIT: UNIT_YEAR,},
AGE_INSTALLED: {
VALUE: 0,
UNIT: UNIT_YEAR,
},
ENERGY_VECTOR: energy_vector,
EMISSION_FACTOR: emission_factor,
TYPE_ASSET: asset_type,
Expand Down Expand Up @@ -1334,7 +1360,10 @@ def define_sink(
VALUE: dict_values[ECONOMIC_DATA][PROJECT_DURATION][VALUE],
UNIT: UNIT_YEAR,
},
AGE_INSTALLED: {VALUE: 0, UNIT: UNIT_YEAR,},
AGE_INSTALLED: {
VALUE: 0,
UNIT: UNIT_YEAR,
},
ENERGY_VECTOR: energy_vector,
OPTIMIZE_CAP: {VALUE: True, UNIT: TYPE_BOOL},
DISPATCHABILITY: {VALUE: True, UNIT: TYPE_BOOL},
Expand Down Expand Up @@ -1408,7 +1437,9 @@ def define_sink(
for item in [SPECIFIC_COSTS, SPECIFIC_COSTS_OM]:
if item in kwargs:
sink.update(
{item: kwargs[item],}
{
item: kwargs[item],
}
)

# update dictionary
Expand Down Expand Up @@ -1751,8 +1782,14 @@ def compute_timeseries_properties(dict_asset):

dict_asset.update(
{
TIMESERIES_PEAK: {VALUE: max(timeseries), UNIT: unit,},
TIMESERIES_TOTAL: {VALUE: sum(timeseries), UNIT: unit,},
TIMESERIES_PEAK: {
VALUE: max(timeseries),
UNIT: unit,
},
TIMESERIES_TOTAL: {
VALUE: sum(timeseries),
UNIT: unit,
},
TIMESERIES_AVERAGE: {
VALUE: sum(timeseries) / len(timeseries),
UNIT: unit,
Expand Down
8 changes: 5 additions & 3 deletions src/multi_vector_simulator/C2_economic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- calculate present costs based on annuity
- calculate effective fuel price cost, in case there is a annual fuel price change (this functionality still has to be checked in this module)
"""

import logging
import pandas as pd

Expand All @@ -26,6 +27,7 @@
LIFETIME_PRICE_DISPATCH,
)


# annuity factor to calculate present value of cash flows
def annuity_factor(project_life, discount_factor):
r"""
Expand Down Expand Up @@ -258,9 +260,9 @@ def get_replacement_costs(
# Subtraction of component value at end of life with last replacement (= number_of_investments - 1)
replacement_costs -= value_at_project_end
# Update cash flow projection (specific)
present_value_of_capital_expenditures.loc[
project_lifetime
] = -value_at_project_end
present_value_of_capital_expenditures.loc[project_lifetime] = (
-value_at_project_end
)

return replacement_costs

Expand Down
3 changes: 2 additions & 1 deletion src/multi_vector_simulator/D0_modelling_and_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def store_lp_file(dict_values, local_energy_system):
)
logging.debug("Saving to lp-file.")
local_energy_system.write(
path_lp_file, io_options={"symbolic_solver_labels": True},
path_lp_file,
io_options={"symbolic_solver_labels": True},
)

def simulating(dict_values, model, local_energy_system):
Expand Down
Loading

0 comments on commit 3f6c631

Please sign in to comment.