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

Merge branch 'dev_cvo_input_format' into 'main'

New input format

See merge request focus/focus-framework!24
parents ebe9bc95 4568706c
No related branches found
No related tags found
No related merge requests found
Showing
with 385 additions and 72 deletions
Subproject commit dc5c2facdbb74e782cb7b88408551306342ed8f9 Subproject commit c8a6e383d2d805027a98da620d2806e221efbc47
Subproject commit a83e46cf62a9327d5a8e51547feffd788adbea31 Subproject commit 06ec20da77b07351fb0b33c1fd5a1985cab65c08
"""
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!")
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,,,,
grd_injection_price,grd_price,grd_emission,yearly_interest,planning_horizon
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
{
"components": {
"inv_pv_bat": {
"type": "DynamicInverter",
"model": "STP-7000TL-20",
"min_size": 0.0,
"max_size": 20.0
},
"battery": {
"type": "LiionBattery",
"model": "BAT1",
"min_size": 0.0,
"max_size": 6.0
},
"grd": {
"type": "ElectricalGrid",
"model": "GRD1",
"min_size": 1000.0,
"max_size": 1000.0,
"price": 0.3046,
"injection_price": 0.0793,
"emission": 0.401
},
"elec_cns": {
"type": "ElectricalConsumption"
}
},
"connections": [
{
"from": "inv_pv_bat",
"output": 1,
"to": "battery",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "grd",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "elec_cns",
"input": 1
},
{
"from": "battery",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "grd",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "grd",
"output": 1,
"to": "elec_cns",
"input": 1
}
],
"yearly_interest": 0.03,
"planning_horizon": 20
}
\ No newline at end of file
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,,,,
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.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
{
"network_usage_capacity_fee": 14.79,
"network_usage_energy_fee": 0.0506,
"levies_int": 0.0276,
"levies_ext": 0.0496,
"concession": 0.0199,
"electricity_tax_int": 0,
"electricity_tax_ext": 0.0205,
"VAT": 0.19
}
\ No newline at end of file
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,,,,
grd_injection_price,grd_price,grd_emission,yearly_interest,planning_horizon
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
{
"components": {
"pv_roof": {
"type": "PVGenerator",
"model": "PV2",
"min_size": 6.0,
"max_size": 6.0
},
"inv_pv_bat": {
"type": "DynamicInverter",
"model": "STP-7000TL-20",
"min_size": 0.0,
"max_size": 20.0
},
"battery": {
"type": "LiionBattery",
"model": "BAT1",
"min_size": 6.0,
"max_size": 6.0
},
"grd": {
"type": "ElectricalGrid",
"model": "GRD1",
"min_size": 1000.0,
"max_size": 1000.0,
"price": 0.3046,
"injection_price": 0.0793,
"emission": 0.401
},
"elec_cns": {
"type": "ElectricalConsumption"
}
},
"connections": [
{
"from": "pv_roof",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "battery",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "grd",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "elec_cns",
"input": 1
},
{
"from": "battery",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "grd",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "grd",
"output": 1,
"to": "elec_cns",
"input": 1
}
],
"yearly_interest": 0.03,
"planning_horizon": 20
}
\ No newline at end of file
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,,,,
grd_injection_price,grd_price,grd_emission,yearly_interest,planning_horizon
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
{
"components": {
"pv_roof": {
"type": "PVGenerator",
"model": "PV2",
"min_size": 6.0,
"max_size": 6.0
},
"inv_pv_bat": {
"type": "DynamicInverter",
"model": "STP-7000TL-20",
"min_size": 0.0,
"max_size": 20.0
},
"battery": {
"type": "LiionBattery",
"model": "BAT1",
"min_size": 6.0,
"max_size": 6.0
},
"grd": {
"type": "ElectricalGrid",
"model": "GRD1",
"min_size": 1000.0,
"max_size": 1000.0,
"price": 0.3046,
"injection_price": 0.0793,
"emission": 0.401
},
"elec_cns": {
"type": "ElectricalConsumption"
}
},
"connections": [
{
"from": "pv_roof",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "battery",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "grd",
"input": 1
},
{
"from": "inv_pv_bat",
"output": 1,
"to": "elec_cns",
"input": 1
},
{
"from": "battery",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "grd",
"output": 1,
"to": "inv_pv_bat",
"input": 1
},
{
"from": "grd",
"output": 1,
"to": "elec_cns",
"input": 1
}
],
"yearly_interest": 0.03,
"planning_horizon": 20
}
\ No newline at end of file
name,type,model,min_size,max_size,current_size
grd,ElectricalGrid,GRD1,100000,100000,0
elec_cns,ElectricalConsumption,,,,
gas_boi,GasBoiler,BOI1,10,10,0
gas_grd,GasGrid,GAS1,100000,100000,0
therm_cns,HeatConsumption,,,,
dhw_dmd,HotWaterConsumption,,,,
water_tes,HotWaterStorage,TES1,40,40,0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment