Skip to content
Snippets Groups Projects
Commit 1c4e1a09 authored by Christoph von Oy's avatar Christoph von Oy
Browse files

Removed unused files

parent 921ada79
No related branches found
No related tags found
No related merge requests found
Showing
with 1 addition and 922 deletions
Subproject commit 6bb636ea23fdfe960ea5f69b93e097233cc54e4b
Subproject commit 9c293d53569edeb54f362cf1f4204fde5c0b6a74
"""
MIT License
Copyright (c) 2023 RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
"""
This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !13 Input Profile Processor.
This script assumes that the file containing the paths to the files containing the input profiles is called "data_path.csv".
"""
import os.path
changed_files = []
for dirpath, dirnames, filenames in os.walk(".\\input_files"):
for filename in filenames:
if filename == "data_path.csv":
print(f"Inspecting file {os.path.join(dirpath, filename)}")
changed_files.append(os.path.join(dirpath, filename))
os.remove(os.path.join(dirpath, filename))
for file in changed_files:
print(f"Modified file {file}!")
"""
MIT License
Copyright (c) 2023 RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
"""
This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !24 New input format.
"""
import os.path
import pandas as pd
import numpy as np
import json
def parse_component_config(component_name, component_type, config, component_json):
possible_keys = dict()
if component_type == 'CoolGrid':
possible_keys['price'] = component_name + '_price'
possible_keys['injection_price'] = component_name + '_injection_price'
elif component_type == "ElectricalGrid":
possible_keys['price'] = component_name + '_price'
possible_keys['injection_price'] = component_name + '_injection_price'
possible_keys['emission'] = component_name + '_emission'
possible_keys['peak_power_cost'] = component_name + '_peak_power_costs'
elif component_type == "GasGrid":
possible_keys['price'] = component_name + '_price'
possible_keys['injection_price'] = component_name + '_injection_price'
possible_keys['peak_power_cost'] = component_name + '_emission'
elif component_type == 'HeatGrid':
possible_keys['price'] = component_name + '_price'
possible_keys['injection_price'] = component_name + '_injection_price'
for key, prefixed_key in possible_keys.items():
if prefixed_key in config:
component_json[key] = config[prefixed_key]
del config[prefixed_key]
def np_encoder(object):
if isinstance(object, np.generic):
return object.item()
changed_topologies = []
invalid_topologies = []
for dirpath, dirnames, filenames in os.walk(".\\input_files"):
components_here = False
config_here = False
connections_here = False
for filename in filenames:
if filename == "components.csv":
components_file = filename
components_here = True
elif filename == "config.csv":
config_file = filename
config_here = True
elif filename == "connections.csv":
connections_file = filename
connections_here = True
if components_here and config_here and connections_here:
try:
print(f"Inspecting topology {dirpath}")
components_df = pd.read_csv(os.path.join(dirpath, components_file))
components = {}
for i in components_df.index:
components[components_df["name"][i]] = components_df.loc[i]
config_df = pd.read_csv(os.path.join(dirpath, config_file))
config_dict = config_df.to_dict(orient='list')
for i in config_dict:
config_dict[i] = config_dict[i][0]
connections = pd.read_csv(os.path.join(dirpath, connections_file))
prosumer_json = dict()
components_json = dict()
for component in components.values():
component_json = dict()
for i in component.index:
if i == 'name' or i == 'current_size' or isinstance(component[i], np.float) and np.isnan(component[i]):
continue
component_json[i] = component[i]
parse_component_config(component['name'], component['type'], config_dict, component_json)
components_json[component['name']] = component_json
prosumer_json['components'] = components_json
connections_json = []
for i in connections.index:
connection_json = dict()
connection_json['from'] = connections['from'][i]
connection_json['output'] = connections['output'][i]
connection_json['to'] = connections['to'][i]
connection_json['input'] = connections['input'][i]
connections_json.append(connection_json)
prosumer_json['connections'] = connections_json
for key, value in config_dict.items():
prosumer_json[key] = value
changed_topologies.append(dirpath)
os.remove(os.path.join(dirpath, "components.csv"))
os.remove(os.path.join(dirpath, "config.csv"))
os.remove(os.path.join(dirpath, "connections.csv"))
with open(os.path.join(dirpath, "prosumer.json"), "w", encoding ="utf-8") as f:
json.dump(prosumer_json, f, indent = 4, default = np_encoder)
except:
invalid_topologies.append(dirpath)
for directory in changed_topologies:
print(f"Modified topology {directory}!")
for file in invalid_topologies:
print(f"Topology {file} breaks some part of the input file specification!")
changed_models = []
invalid_models = []
for dirpath, dirnames, filenames in os.walk(".\\Model_Library\\Component\\data"):
for filename in filenames:
if filename.endswith(".csv"):
try:
print(f"Inspecting model {os.path.join(dirpath, filename)}")
model = pd.read_csv(os.path.join(dirpath, filename))
model_json = dict()
for i in model.columns:
no_space_name = "_".join(i.split(" "))
model_json[no_space_name] = model[i][0]
changed_models.append(os.path.join(dirpath, filename))
os.remove(os.path.join(dirpath, filename))
with open(os.path.join(dirpath, "".join(filename.split(".")[:-1]) + ".json"), "w", encoding ="utf-8") as f:
json.dump(model_json, f, indent = 4, default = np_encoder)
except:
invalid_models.append(os.path.join(dirpath, filename))
for directory in changed_models:
print(f"Modified model {directory}!")
for file in invalid_models:
print(f"Model {file} breaks some part of the input file specification!")
"""
MIT License
Copyright (c) 2023 RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
"""
This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !TODO New input format.
"""
import os.path
import json
changed_prosumers = []
invalid_prosumers = []
for dirpath, dirnames, filenames in os.walk(".\\input_files"):
prosumer_here = False
for filename in filenames:
if filename == "prosumer.json":
prosumer_file = filename
prosumer_here = True
if prosumer_here:
try:
print(f"Inspecting prosumer {dirpath}")
with open(os.path.join(dirpath, filename)) as f:
prosumer_json = json.load(f)
for component in prosumer_json["components"].values():
if "model" in component:
type = component["type"]
model = component["model"]
component["model"] = os.path.join("input_files", "data", "components", type, model + ".json")
changed_prosumers.append(dirpath)
with open(os.path.join(dirpath, filename), "w", encoding ="utf-8") as f:
json.dump(prosumer_json, f, indent = 4)
except:
invalid_prosumers.append(dirpath)
for prosumer in changed_prosumers:
print(f"Modified prosumer {prosumer}!")
for prosumer in invalid_prosumers:
print(f"Prosumer {prosumer} breaks some part of the input file specification!")
"""
MIT License
Copyright (c) 2023 RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
"""
This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !12 Refactoring Part 1.
"""
import os.path
import pandas as pd
def read_matrix(df):
matrix = []
for i in df.index:
matrix_row = []
for j in df.index:
matrix_row.append(df[df["comp_name"][j]][i])
matrix.append(matrix_row)
return matrix
def read_components(df):
components = {}
for i in df.index:
components[df["comp_name"][i]] = i
return components
def get_connection(matrix, components, comp_from, comp_to):
return matrix[components[comp_from]][components[comp_to]]
def set_connection(matrix, components, comp_from, comp_to, value):
matrix[components[comp_from]][components[comp_to]] = value
def write_matrix(df, matrix):
for i in df.index:
for j in df.index:
df.loc[i, df["comp_name"][j]] = matrix[i][j]
changed_files = []
invalid_files = []
for dirpath, dirnames, filenames in os.walk(".\\input_files"):
for filename in filenames:
matrix_names = ["elec_matrix.csv", "gas_matrix.csv", "hydro_matrix.csv", "therm_matrix.csv"]
consumption_component_names = ["ChargingInfrastructure", "StandardElectricalConsumption", "HeadConsumption", "Radiator", "HotWaterConsumption"]
if filename.find('matrix') and filename.endswith('.csv') and (filename.find('elec') is not -1 or filename.find('gas') is not -1 or filename.find('hydro') is not -1 or filename.find('therm') is not -1):
try:
print(f"Inspecting file {os.path.join(dirpath, filename)}")
df = pd.read_csv(os.path.join(dirpath, filename))
file_changed = False
matrix = read_matrix(df)
components = read_components(df)
for component in components.keys():
if df["comp_type"][components[component]] in consumption_component_names:
receives_from = []
gives_to = []
for other_component in components.keys():
if get_connection(matrix, components, other_component, component) == 1:
receives_from.append(other_component)
if get_connection(matrix, components, component, other_component) == 1:
gives_to.append(other_component)
if len(gives_to) != 0:
file_changed = True
for recieving_component in gives_to:
set_connection(matrix, components, component, recieving_component, 0)
for giving_component in receives_from:
set_connection(matrix, components, giving_component, recieving_component, 1)
if file_changed:
changed_files.append(os.path.join(dirpath, filename))
write_matrix(df, matrix)
df.to_csv(os.path.join(dirpath, "temp.csv"), index = False)
df_str = pd.read_csv(os.path.join(dirpath, "temp.csv"), dtype = str, keep_default_na = False)
for i in df.columns:
if issubclass(type(df[i][0]), float):
for j in df.index:
if len(df_str[i][j]) != 0 and df_str[i][j].endswith(".0"):
df_str[i][j] = f"{df[i][j]:.0f}"
df_str.to_csv(os.path.join(dirpath, filename), index = False)
os.remove(os.path.join(dirpath, "temp.csv"))
except KeyError:
invalid_files.append(os.path.join(dirpath, filename))
for file in changed_files:
print(f"Modified file {file}!")
for file in invalid_files:
print(f"File {file} breaks some part of the input file specification that during the refactoring!")
"""
MIT License
Copyright (c) 2023 RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
"""
This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !16 Refactoring Part 2.
"""
import os.path
import pandas as pd
import math
def read_matrix(df):
matrix = []
for i in df.index:
matrix_row = []
for j in df.index:
matrix_row.append(df[df["name"][j]][i])
matrix.append(matrix_row)
return matrix
def read_components(df):
components = {}
for i in df.index:
components[df["name"][i]] = i
return components
def compare_components(comp_1, comp_2):
different = False
for column in ['name', 'type', 'model', 'min_size', 'max_size', 'current_size']:
if comp_1[column] != comp_2[column]:
if not math.isnan(comp_1[column]) and not math.isnan(comp_2[column]):
different = True
break
return different
def get_connected_components(matrix, components, comp):
connected_components = []
for component in components:
if get_connection(matrix, components, comp, component) == 1:
connected_components.append(component)
return connected_components
def get_connection(matrix, components, comp_from, comp_to):
return matrix[components[comp_from]][components[comp_to]]
def get_bypasses(component_name, connections):
inputs = []
outputs = []
sector = ''
for i in connections.index:
if connections['to'][i] == component_name and connections['from'][i] not in inputs:
inputs.append(connections['from'][i])
if sector == '':
sector = connections['sector'][i]
else:
if sector != connections['sector'][i]:
raise KeyError
if connections['from'][i] == component_name and connections['to'][i] not in outputs:
outputs.append(connections['to'][i])
if sector == '':
sector = connections['sector'][i]
else:
if sector != connections['sector'][i]:
raise KeyError
bypasses = []
for input in inputs:
for output in outputs:
if input != output:
if not ((connections['sector'] == sector) & (connections['from'] == input) & (connections['to'] == output)).any():
bypasses.append((sector, input, output))
return bypasses
def read_config(config_path):
config_df = pd.read_csv(config_path)
config_dict = config_df.to_dict(orient='list')
for k in config_dict:
config_dict[k] = config_dict[k][0]
return config_dict
changed_topologies = []
invalid_topologies = []
renamed_components = {'StandardElectricalConsumption': 'ElectricalConsumption',
'StandardACGrid': 'ElectricalGrid',
'StandardPVGenerator': 'PVGenerator',
'StandardGasGrid': 'GasGrid',
'StandardPEMElectrolyzer': 'PEMElectrolyzer',
'StandardPEMFuelCell': 'PEMFuelCell',
'BasicInverter': 'StaticInverter',
'Inverter': 'DynamicInverter'}
consumption_components = ['CoolConsumption', 'ChargingInfrastructure', 'ElectricalConsumption', 'HeatConsumption', 'Radiator', 'HotWaterConsumption']
storage_components = ['LiionBattery', 'HotWaterStorage', 'PressureStorage']
for dirpath, dirnames, filenames in os.walk(".\\input_files"):
topology_here = False
matrix_files = []
for filename in filenames:
if filename.find('matrix') and filename.endswith('.csv') and (filename.find('elec') is not -1):
topology_here = True
matrix_files.append((filename, 'electricity'))
if filename.find('matrix') and filename.endswith('.csv') and (filename.find('gas') is not -1):
topology_here = True
matrix_files.append((filename, 'gas'))
if filename.find('matrix') and filename.endswith('.csv') and (filename.find('hydro') is not -1):
topology_here = True
matrix_files.append((filename, 'hydrogen'))
if filename.find('matrix') and filename.endswith('.csv') and (filename.find('therm') is not -1):
topology_here = True
matrix_files.append((filename, 'heat'))
if topology_here:
try:
print(f"Inspecting topology {dirpath}")
file_contents = []
for matrix_file, sector in matrix_files:
df = pd.read_csv(os.path.join(dirpath, matrix_file))
df.rename(columns = {'comp_name': 'name', 'comp_type': 'type'}, inplace = True)
for i in df.index:
if df['type'][i] in renamed_components:
df.loc[i, 'type'] = renamed_components[df['type'][i]]
if df['type'][i] in consumption_components:
df.loc[i, 'model'] = ''
df.loc[i, 'min_size'] = ''
df.loc[i, 'max_size'] = ''
df.loc[i, 'current_size'] = ''
file_contents.append((df, read_matrix(df), read_components(df), sector))
all_components = pd.DataFrame(columns = ['name', 'type', 'model', 'min_size', 'max_size', 'current_size'])
all_connections = pd.DataFrame(columns = ['sector', 'from', 'to'])
for df, matrix, components, sector in file_contents:
for component in components:
if component not in all_components.loc[:]['name']:
all_components.loc[component] = df.loc[components[component]][['name', 'type', 'model', 'min_size', 'max_size', 'current_size']]
else:
if compare_components(all_components.loc[component], df.loc[components[component]][['name', 'type', 'model', 'min_size', 'max_size', 'current_size']]):
raise KeyError
for connected_component in get_connected_components(matrix, components, component):
all_connections = pd.concat([all_connections, pd.Series({'sector': sector, 'from': component, 'to': connected_component}).to_frame().T], ignore_index = True)
while True:
number_of_connections_before = len(all_connections)
for i in all_components.index:
if all_components['type'][i] in storage_components:
for sector, from_component, to_component in get_bypasses(all_components['name'][i], all_connections):
all_connections = pd.concat([all_connections, pd.Series({'sector': sector, 'from': from_component, 'to': to_component}).to_frame().T], ignore_index = True)
number_of_connections_after = len(all_connections)
if number_of_connections_before == number_of_connections_after:
break
config = read_config(os.path.join(dirpath, "config.csv"))
changed_topologies.append(dirpath)
new_config = dict()
for name, value in config.items():
# configs to delete
if name in ['injection/pvpeak', 'elec_price_cap_low', 'elec_price_cap_high']:
pass
# configs to keep
elif name in ['yearly_interest', 'planning_horizon']:
new_config[name] = value
# configs that are handled by other configs
elif name in ['elec_price_variable', 'injection_price_variable', 'gas_price_variable', 'injection_price_gas_variable', 'heat_price_variable', 'injection_price_heat_variable', 'cooling_price_variable', 'injection_price_cooling_variable']:
pass
elif name == 'elec_price':
if config['elec_price_variable'] == 1:
print(f"Config of topology {dirpath} has a variable electricity price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'ElectricalGrid':
new_config[all_components['name'][i] + '_price'] = value
elif name == 'injection_price':
if config['injection_price_variable'] == 1:
print(f"Config of topology {dirpath} has a variable electricity injection price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'ElectricalGrid':
new_config[all_components['name'][i] + '_injection_price'] = value
elif name == 'gas_price':
if config['gas_price_variable'] == 1:
print(f"Config of topology {dirpath} has a variable gas price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'GasGrid':
new_config[all_components['name'][i] + '_price'] = value
elif name == 'injection_price_gas':
if config['injection_price_gas_variable'] == 1:
print(f"Config of topology {dirpath} has a variable gas injection price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'GasGrid':
new_config[all_components['name'][i] + '_injection_price'] = value
elif name == 'heat_price':
if config['heat_price_variable'] == 1:
print(f"Config of topology {dirpath} has a variable heat price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'HeatGrid':
new_config[all_components['name'][i] + '_price'] = value
elif name == 'injection_price_heat':
if config['injection_price_heat_variable'] == 1:
print(f"Config of topology {dirpath} has a variable heat injection price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'HeatGrid':
new_config[all_components['name'][i] + '_injection_price'] = value
elif name == 'cooling_price':
if config['cooling_price_variable'] == 1:
print(f"Config of topology {dirpath} has a variable cooling price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'CoolingGrid':
new_config[all_components['name'][i] + '_price'] = value
elif name == 'injection_price_cooling':
if config['injection_price_cooling_variable'] == 1:
print(f"Config of topology {dirpath} has a variable cooling injection price, so be sure to add a price profile!")
else:
for i in all_components.index:
if all_components['type'][i] == 'CoolingGrid':
new_config[all_components['name'][i] + '_injection_price'] = value
elif name == 'elec_emission':
for i in all_components.index:
if all_components['type'][i] == 'ElectricalGrid':
new_config[all_components['name'][i] + '_emission'] = value
elif name == 'gas_emission':
for i in all_components.index:
if all_components['type'][i] == 'GasGrid':
new_config[all_components['name'][i] + '_emission'] = value
else:
new_config[name] = value
all_components.to_csv(os.path.join(dirpath, "temp.csv"), index = False)
df_str = pd.read_csv(os.path.join(dirpath, "temp.csv"), dtype = str, keep_default_na = False)
for i in all_components.columns:
counter = 0
for j in all_components.index:
if issubclass(type(all_components[i][j]), float):
if len(df_str[i][counter]) != 0 and df_str[i][counter].endswith(".0"):
df_str[i][counter] = f"{all_components[i][j]:.0f}"
counter += 1
df_str.to_csv(os.path.join(dirpath, "components.csv"), index = False)
os.remove(os.path.join(dirpath, "temp.csv"))
all_connections.to_csv(os.path.join(dirpath, "connections.csv"), index = False)
for matrix_file, sector in matrix_files:
os.remove(os.path.join(dirpath, matrix_file))
os.remove(os.path.join(dirpath, "config.csv"))
new_config_df = pd.DataFrame(columns = list(new_config.keys()), index = [0])
for key, value in new_config.items():
string = str(value)
if issubclass(type(value), float):
if len(string) != 0 and string.endswith(".0"):
string = f"{value:.0f}"
new_config_df.loc[0, key] = string
new_config_df.to_csv(os.path.join(dirpath, "config.csv"), index = False)
except:
invalid_topologies.append(dirpath)
for directory in changed_topologies:
print(f"Modified topology {directory}!")
for file in invalid_topologies:
print(f"Topology {file} breaks some part of the input file specification!")
"""
MIT License
Copyright (c) 2023 RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
"""
This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !13 Release focused refactoring.
"""
import os.path
import pandas as pd
def component_to_commodities(type):
if type == "AbsorptionChiller":
return "heat", None, "cold", None
if type == "CompressorChiller":
return "electricity", None, "cold", None
if type == "CoolConsumption":
return "cold", None, None, None
if type == "CoolGrid":
return "cold", None, "cold", None
if type == "ChargingInfrastructure":
return "electricity", None, None, None
if type == "ElectricalBusBar":
return "electricity", None, "electricity", None
if type == "ElectricalConsumption":
return "electricity", None, None, None
if type == "ElectricalGrid":
return "electricity", None, "electricity", None
if type == "PVGenerator":
return None, None, "electricity", None
if type == "DynamicInverter":
return "electricity", None, "electricity", None
if type == "StaticInverter":
return "electricity", None, "electricity", None
if type == "LiionBattery":
return "electricity", None, "electricity", None
if type == "BHKW":
return "gas", None, "heat", "electricity"
if type == "CHP":
return "gas", None, "heat", "electricity"
if type == "GasGrid":
return "gas", None, "gas", None
if type == "ElectricBoiler":
return "electricity", None, "heat", None
if type == "GasBoiler":
return "gas", None, "heat", None
if type == "HeatGrid":
return "heat", None, "heat", None
if type == "ElectricRadiator":
return "electricity", None, "heat", None
if type == "HeatConsumption":
return "heat", None, None, None
if type == "Radiator":
return "heat", None, None, None
if type == "UnderfloorHeat":
return "heat", None, "heat", None
if type == "HeatExchanger":
return "heat", None, "heat", None
if type == "GasHeatPump":
return "gas", None, "heat", None
if type == "HeatPump":
return "electricity", None, "heat", None
if type == "HotWaterConsumption":
return "heat", None, None, None
if type == "SolarThermalCollector":
return None, None, "heat", None
if type == "HotWaterStorage":
return "heat", None, "heat", None
if type == "PEMElectrolyzer":
return "electricity", None, "hydrogen", None
if type == "PEMFuelCell":
return "hydrogen", None, "electricity", "heat"
if type == "PEMElectrolyzer":
return "electricity", None, "hydrogen", None
if type == "PressureStorage":
return "hydrogen", None, "hydrogen", None
raise KeyError
changed_topologies = []
invalid_topologies = []
for dirpath, dirnames, filenames in os.walk(".\\input_files"):
components_here = False
connections_here = False
for filename in filenames:
if filename == "components.csv":
components_file = filename
components_here = True
elif filename == "connections.csv":
connections_file = filename
connections_here = True
if components_here and connections_here:
try:
print(f"Inspecting topology {dirpath}")
components_df = pd.read_csv(os.path.join(dirpath, components_file))
components = {}
for i in components_df.index:
components[components_df["name"][i]] = components_df.loc[i]
connections = pd.read_csv(os.path.join(dirpath, connections_file))
connections['output'] = pd.Series("", index = connections.index)
connections['input'] = pd.Series("", index = connections.index)
for i in connections.index:
commodity = connections['sector'][i]
connection_from = connections['from'][i]
connection_to = connections['to'][i]
from_type = components[connection_from]['type']
input_commodity_1, input_commodity_2, output_commodity_1, output_commodity_2 = component_to_commodities(from_type)
if commodity == output_commodity_1:
connections['output'][i] = "1"
elif commodity == output_commodity_2:
connections['output'][i] = "2"
else:
raise KeyError
to_type = components[connection_to]['type']
input_commodity_1, input_commodity_2, output_commodity_1, output_commodity_2 = component_to_commodities(to_type)
if commodity == input_commodity_1:
connections['input'][i] = "1"
elif commodity == input_commodity_2:
connections['input'][i] = "2"
else:
raise KeyError
connections.drop("sector", axis = 1)
connections = connections[["from", "output", "to", "input"]]
changed_topologies.append(dirpath)
connections.to_csv(os.path.join(dirpath, "connections.csv"), index = False)
except:
invalid_topologies.append(dirpath)
for directory in changed_topologies:
print(f"Modified topology {directory}!")
for file in invalid_topologies:
print(f"Topology {file} breaks some part of the input file specification!")
{
"efficiency_heat": 0.49,
"efficiency_elec": 0.344,
"elec_heat_ratio": 0.7020000000000001,
"cost": 3400,
"fix_cost_factor": 0.03,
"service_life": 20,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.05,
"servicing_effort_hours": 20
}
\ No newline at end of file
{
"efficiency_heat_under50": 0.5805,
"efficiency_elec_under50": 0.3065,
"efficiency_heat_over50": 0.5575,
"efficiency_elec_over50": 0.359,
"cost": 3400,
"fix_cost_factor": 0.03,
"service_life": 20,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.05,
"servicing_effort_hours": 20
}
\ No newline at end of file
{
"efficiency_heat": 0.598,
"efficiency_elec": 0.316,
"ratio": 0.528,
"cost": 3400,
"fix_cost_factor": 0.03,
"service_life": 20,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.05,
"servicing_effort_hours": 20
}
\ No newline at end of file
{
"efficiency_heat": 0.52,
"efficiency_elec": 0.38,
"cost": 1100,
"fix_cost_factor": 0.02,
"service_life": 15,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.05,
"servicing_effort_hours": 20
}
\ No newline at end of file
{
"efficiency": 0.97,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.015,
"servicing_effort_hours": 20,
"service_life": 20,
"cost": 250
}
\ No newline at end of file
{
"p1": 0.05,
"p2": 0.55,
"p3": 0.95,
"eta1": 0.1441,
"eta2": 0.8959,
"eta3": 0.8911,
"nominal_efficiency": 0.89,
"curve_type": 1,
"cost": 250,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.015,
"servicing_effort_hours": 20,
"service_life": 20
}
\ No newline at end of file
{
"p1": 0.05,
"p2": 0.1,
"p3": 0.75,
"eta1": 0.88,
"eta2": 0.9279999999999999,
"eta3": 0.973,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.015,
"servicing_effort_hours": 20,
"service_life": 20,
"cost": 250,
"nominal_efficiency": 0.973,
"curve_type": 1
}
\ No newline at end of file
{
"p1": 0.05,
"p2": 0.1,
"p3": 0.75,
"eta1": 0.88,
"eta2": 0.9279999999999999,
"eta3": 0.973,
"nominal_efficiency": 0.973,
"curve_type": 1,
"fit": 0.6
}
\ No newline at end of file
{
"p1": 0.05,
"p2": 0.55,
"p3": 0.95,
"eta1": 0.1441,
"eta2": 0.8959,
"eta3": 0.8911,
"nominal_efficiency": 0.89,
"curve_type": 1,
"cost": 250,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.015,
"servicing_effort_hours": 20,
"service_life": 20
}
\ No newline at end of file
{
"p1": 0.05,
"p2": 0.1,
"p3": 0.75,
"eta1": 0.88,
"eta2": 0.9279999999999999,
"eta3": 0.973,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.015,
"servicing_effort_hours": 20,
"service_life": 20,
"cost": 250,
"nominal_efficiency": 0.973,
"curve_type": 1
}
\ No newline at end of file
{
"p1": 0.05,
"p2": 0.1,
"p3": 0.75,
"eta1": 0.88,
"eta2": 0.9279999999999999,
"eta3": 0.973,
"nominal_efficiency": 0.973,
"curve_type": 1,
"fit": 0.6
}
\ No newline at end of file
{
"input_efficiency": 0.99,
"output_efficiency": 0.99,
"cost": 1000,
"fix_cost_factor": 0.008,
"service_life": 20,
"e2p_in": 1,
"e2p_out": 1,
"factor_repair_effort": 0.01,
"factor_servicing_effort": 0.015,
"servicing_effort_hours": 20,
"max_soe": 1,
"min_soe": 0,
"init_soe": 0.5
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment