Skip to content
Snippets Groups Projects
Commit 1165006a authored by Jonas Brucksch's avatar Jonas Brucksch
Browse files

Merge commit 'e33a4ce1' into dev_jou_fsa_build_quarter_model

# Conflicts:
#	Model_Library
#	Tooling
#	runme.py
#	runme_community.py
parents a08bba29 e33a4ce1
Branches
No related tags found
No related merge requests found
Showing
with 17955 additions and 27 deletions
Subproject commit 2562cac5ba7b6280539585cb0496dcd7b0ffdda0 Subproject commit 464d488d4660999a14542f1c636825c3b28fc2ab
...@@ -161,7 +161,7 @@ The ineed-dc-framework repository is the framework's main repository. It contain ...@@ -161,7 +161,7 @@ The ineed-dc-framework repository is the framework's main repository. It contain
The sub-repository Model_Libary contains the mathematical models of component, prosumer, quarter, and city levels. The sub-repository Model_Libary contains the mathematical models of component, prosumer, quarter, and city levels.
- `Components/` : Contains all component models and initialized pre-configured components - `Components/` : Contains all component models and initialized pre-configured components
- `Prosumer/` : Includes BaseProsumer model whhich allows to flexibily model any Prosumer application - `Prosumer/` : Includes Prosumer model whhich allows to flexibily model any Prosumer application
- `District/` : Will contain district level model (implementation in progress). - `District/` : Will contain district level model (implementation in progress).
- `City/` : Will contain city level model (implementation in progress). - `City/` : Will contain city level model (implementation in progress).
......
"""
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!")
"""
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!")
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
name,type,model,min_size,max_size,current_size
inv_pv_bat,DynamicInverter,STP-7000TL-20,0,20,0
battery,LiionBattery,BAT1,0,6,6
grd,ElectricalGrid,GRD1,1000,1000,1000
elec_cns,ElectricalConsumption,,,,
injection_price,injection_price_variable,injection/pvpeak,gas_price,gas_price_variable,elec_price,elec_price_variable,heat_price,heat_price_variable,cooling_price,cooling_price_variable,injection_price_gas,injection_price_gas_variable,injection_price_heat,injection_price_heat_variable,injection_price_cooling,injection_price_cooling_variable,elec_emission,gas_emission,yearly_interest,planning_horizon grd_injection_price,grd_price,grd_emission,yearly_interest,planning_horizon
0.0793,0,0.7,0.0606,0,0.3046,0,0,0,0,0,0,0,0,0,0,0,0.401,0.21,0.03,20 0.0793,0.3046,0.401,0.03,20
from,output,to,input
inv_pv_bat,1,battery,1
inv_pv_bat,1,grd,1
inv_pv_bat,1,elec_cns,1
battery,1,inv_pv_bat,1
grd,1,inv_pv_bat,1
grd,1,elec_cns,1
comp_name,comp_type,model,min_size,max_size,current_size,inv_pv_bat,battery,grd,elec_cns
inv_pv_bat,Inverter,STP-7000TL-20,0,20,0,0,1,1,1
battery,LiionBattery,BAT1,0,6,6,1,0,0,0
grd,StandardACGrid,GRD1,1000,1000,1000,1,0,0,1
elec_cns,StandardElectricalConsumption,CNS1,1000,1000,0,0,0,0,0
name,type,model,min_size,max_size,current_size
pv_roof,PVGenerator,PV2,6,6,6
inv_pv_bat,DynamicInverter,STP-7000TL-20,0,20,0
battery,LiionBattery,BAT1,6,6,6
grd,ElectricalGrid,GRD1,1000,1000,1000
elec_cns,ElectricalConsumption,,,,
injection_price,injection_price_variable,injection/pvpeak,gas_price,gas_price_variable,elec_price,elec_price_variable,network_usage_capacity_fee,network_usage_energy_fee,heat_price,levies_int,levies_ext,concession,electricity_tax_int,electricity_tax_ext,VAT,heat_price_variable,cooling_price,cooling_price_variable,injection_price_gas,injection_price_gas_variable,injection_price_heat,injection_price_heat_variable,injection_price_cooling,injection_price_cooling_variable,elec_emission,gas_emission,yearly_interest,planning_horizon grd_injection_price,grd_price,network_usage_capacity_fee,network_usage_energy_fee,levies_int,levies_ext,concession,electricity_tax_int,electricity_tax_ext,VAT,grd_emission,yearly_interest,planning_horizon
0.0793,0,0.7,0.0606,0,0.3046,0,14.79,0.0506,0,0.0276,0.0496,0.0199,0,0.0205,0.190,0,0,0,0,0,0,0,0,0,0.401,0.21,0.03,20 0.0793,0.3046,14.79,0.0506,0.0276,0.0496,0.0199,0,0.0205,0.19,0.401,0.03,20
from,output,to,input
pv_roof,1,inv_pv_bat,1
inv_pv_bat,1,battery,1
inv_pv_bat,1,grd,1
inv_pv_bat,1,elec_cns,1
battery,1,inv_pv_bat,1
grd,1,inv_pv_bat,1
grd,1,elec_cns,1
comp_name,comp_type,model,min_size,max_size,current_size,pv_roof,inv_pv_bat,battery,grd,elec_cns
pv_roof,StandardPVGenerator,PV2,6,6,6,0,1,0,0,0
inv_pv_bat,Inverter,STP-7000TL-20,0,20,0,0,0,1,1,1
battery,LiionBattery,BAT1,6,6,6,0,1,0,0,0
grd,StandardACGrid,GRD1,1000,1000,1000,0,1,0,0,1
elec_cns,StandardElectricalConsumption,CNS1,1000,1000,0,0,0,0,0,0
name,type,model,min_size,max_size,current_size
pv_roof,PVGenerator,PV2,6,6,6
inv_pv_bat,DynamicInverter,STP-7000TL-20,0,20,0
battery,LiionBattery,BAT1,6,6,6
grd,ElectricalGrid,GRD1,1000,1000,1000
elec_cns,ElectricalConsumption,,,,
injection_price,injection_price_variable,injection/pvpeak,gas_price,gas_price_variable,elec_price,elec_price_variable,heat_price,heat_price_variable,cooling_price,cooling_price_variable,injection_price_gas,injection_price_gas_variable,injection_price_heat,injection_price_heat_variable,injection_price_cooling,injection_price_cooling_variable,elec_emission,gas_emission,yearly_interest,planning_horizon grd_injection_price,grd_price,grd_emission,yearly_interest,planning_horizon
0.0793,0,0.7,0.0606,0,0.3046,0,0,0,0,0,0,0,0,0,0,0,0.401,0.21,0.03,20 0.0793,0.3046,0.401,0.03,20
from,output,to,input
pv_roof,1,inv_pv_bat,1
inv_pv_bat,1,battery,1
inv_pv_bat,1,grd,1
inv_pv_bat,1,elec_cns,1
battery,1,inv_pv_bat,1
grd,1,inv_pv_bat,1
grd,1,elec_cns,1
comp_name,comp_type,model,min_size,max_size,current_size,pv_roof,inv_pv_bat,battery,grd,elec_cns
pv_roof,StandardPVGenerator,PV2,6,6,6,0,1,0,0,0
inv_pv_bat,Inverter,STP-7000TL-20,0,20,0,0,0,1,1,1
battery,LiionBattery,BAT1,6,6,6,0,1,0,0,0
grd,StandardACGrid,GRD1,1000,1000,1000,0,1,0,0,1
elec_cns,StandardElectricalConsumption,CNS1,1000,1000,0,0,0,0,0,0
name,type,model,min_size,max_size,current_size
pv_roof,PVGenerator,PV2,6,6,6
inv_pv_bat,DynamicInverter,STP-7000TL-20,0,20,0
battery,LiionBattery,BAT1,6,6,6
grd,ElectricalGrid,GRD1,1000,1000,1000
elec_cns,ElectricalConsumption,,,,
injection_price,injection_price_variable,injection/pvpeak,gas_price,gas_price_variable,elec_price,elec_price_variable,heat_price,heat_price_variable,cooling_price,cooling_price_variable,injection_price_gas,injection_price_gas_variable,injection_price_heat,injection_price_heat_variable,injection_price_cooling,injection_price_cooling_variable,elec_emission,gas_emission,yearly_interest,planning_horizon grd_injection_price,grd_price,grd_emission,yearly_interest,planning_horizon
0.0793,0,0.7,0.0606,0,0.3046,0,0,0,0,0,0,0,0,0,0,0,0.401,0.21,0.03,20 0.0793,0.3046,0.401,0.03,20
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment