Select Git revision
runme.py 12.04 KiB
import os
import pandas as pd
import numpy as np
import Tooling.input_profile_processor.input_profile_processor
import Model_Library.Prosumer.main as main_prosumer
import Model_Library.District.main as main_district
from enum import Enum
import os
import random
import pickle
class SimulationScope(Enum):
PROSUMER = 1
DISTRICT = 2
# Define a function to split strings and extract base names
def extract_base_name(s):
splits = s.split("_")
return splits[0] + "_" + splits[1]
# Define a function to split strings and extract base names
def extract_str_name(s):
splits = s.split("_")
if len(splits) == 3 and 'STR' in splits[2]: # only storage in prosumer -> return original
return s
elif len(splits) == 3 and 'PV' in splits[2]: # only pv in prosumer --> add storage
return s + '_STR'
else: # pv and storage in prosumer --> return original
return s
# Define a function to split strings and extract base names
def extract_pv_name(s):
splits = s.split("_")
if len(splits) > 2 and 'PV' in splits[2]: # only give back pv system
return splits[0] + "_" + splits[1] + "_" + splits[2]
else: # there is a storage in the prosumer --> exclude it
return splits[0] + "_" + splits[1]
simulation_scope = SimulationScope.DISTRICT
t_start = pd.Timestamp("2019-01-01 00:00:00") # start time of simulation
t_horizon = 8760 # number of time steps to be simulated
t_step = 1 # length of a time step in hours
folder_building_configs = 'building_types_aachen_2022'
inputpath_dataframe_district = 'input_files/models/prosumer_models/building_types_aachen_2022/running_77_2022.csv'
inputpath_dataframe_all = 'input_files/models/prosumer_models/building_types_aachen_2022/running_info_2022.csv'
#inputpath_dataframe = 'input_files/models/district_models/quarter_extraction_df_Q_0.csv'
building_types_district = pd.read_csv(inputpath_dataframe_district)
building_types = pd.read_csv(inputpath_dataframe_all)
# Initialize empty lists to store the results
only_pv = [] # contains the community without storage
original_names = [] # contains the original community names
full_storage = [] # community with added storage to all prosumers
# Loop over the column of interest and store the indices and strings that match the conditions
indices = []
for i, s in enumerate(building_types_district["ID_Building"]):
if "STR" in s or "PV" in s:
indices.append(i)
original_names.append(s)
full_storage.append(extract_str_name(s))
only_pv.append(extract_pv_name(s))
input_profile_dict = {'pv_factors_aachen_1': ['pv_factors', 'input_files/data/irradiance/aachen_pv_factors_ninja_2019_1h_to_2019_15min.csv'],
'pv_factors_germany_1': ['pv_factors', 'input_files/data/irradiance/irr_ren_ninja_avg_Germany.csv'],
'temperature_1': ['air_temperature', 'input_files/data/temperature/temperature_TRY2010.csv'],
'elec_demand_htw': ['elec_demand', 'input_files/data/demand/electricity/PL_SUM_15.csv'],
'room_heating_sfh_passive': ['room_heating_demand', 'input_files/data/demand/room_heating/synPRO_passive_single_family_house_rh_2021_to_2019_kW.csv'],
'dhw_shf_passive': ['hot_water_demand', 'input_files/data/demand/domestic_hot_water/synPRO_passive_single_family_house_dhw_2021_to_2019_kW.csv'],
'room_heating_mfh_passive': ['room_heating_demand', 'input_files/data/demand/room_heating/synPRO_passive_multi_party_house_rh_2021_to_2019_kW.csv'],
'dhw_mhf_passive': ['hot_water_demand', 'input_files/data/demand/domestic_hot_water/synPRO_passive_multi_party_house_dhw_2021_to_2019_kW.csv'],
'elec_price_1': ['prices', 'input_files/data/prices/day-ahead/hourly_price.csv']}
for i in building_types.index[:]:
if building_types.iloc[i]['ID_building'] not in (only_pv + original_names + full_storage):
continue
if 'A_' in building_types.iloc[i]['ID_building']:
pass
else:
if len(building_types['Profile_el'][i]) > 2:
profile_list = building_types['Profile_el'][i].split('+')
input_profile_dict['elec_demand_prosumer_' + str(building_types.loc[i, 'ID_building'])] = ['elec_demand','generate',
building_types['Electricity_demand'][i],
profile_list[0]]
input_profile_dict['Add_elec_demand_prosumer_' + str(building_types.loc[i, 'ID_building'])] = ['elec_demand','generate',
building_types['Electricity_demand'][i],
profile_list[1]]
else:
input_profile_dict['elec_demand_prosumer_' + str(building_types.loc[i, 'ID_building'])] = ['elec_demand', 'generate',
building_types['Electricity_demand'][i],
building_types['Profile_el'][i]]
input_profiles = Tooling.input_profile_processor.input_profile_processor.process_input_profiles(input_profile_dict, t_start, t_horizon, t_step)
for i in input_profiles['elec_demand_htw']:
input_profiles['ref_elec_demand_id_' + str(i)] = input_profiles['elec_demand_htw'][i]
for i in input_profiles.keys():
if 'Add_' in i:
strings = i.split('Add_')
profile2 = input_profiles[i]
input_profiles[strings[1]] += profile2
# get the annual electric, heating and hw demand s of the example buildings
ref_yearly_elec_demand = input_profiles['elec_demand_htw'].sum()*t_step # in kWh
ref_yearly_rh_demand = input_profiles['room_heating_mfh_passive'].sum()*t_step # in kWh
ref_yearly_dhw_demand = input_profiles['dhw_mhf_passive'].sum()*t_step # in kWh
# Create a new column in building_types to store the index of the closest value
building_types['closest_index'] = building_types.apply(
lambda row: np.abs(row['Electricity_demand'] - ref_yearly_elec_demand).idxmin(),
axis=1)
# 'config_path': path to global configurations like prices, injection prices, emission costs, etc.
# 'topology_path': path to directory that contains the matrices that define the prosumer topology
prosumer_dict = {}
# drop the heatpump
building_types_district.drop(index=141, inplace=True)
building_types_district.reset_index(inplace=True)
# building_types.index[53:61]
community_sample = random.sample(range(197),30)
# how many storages
ids = building_types_district.loc[:]['ID_Building']
string_str = 'STR'
string_pv = 'PV'
string_ac = 'AC'
count_str = 0
count_pv = 0
count_ac = 0
for string in ids:
count_str += string.count(string_str)
count_pv += string.count(string_pv)
count_ac += string.count(string_ac)
print('Number of storages: ' + str(count_str))
print('Number of PV: ' + str(count_pv))
print('Number of AC: ' + str(count_ac))
ps_count = 1
for i in building_types.index[:]:
if len(prosumer_dict) > 2:
continue
if building_types.iloc[i]['ID_building'] not in original_names or 'HP' in building_types.iloc[i]['ID_building']:
continue
else:
prosumer_name = building_types.iloc[i]['ID_building'] + '_Q_' + str(ps_count)
ps_count += 1
if building_types.iloc[i]['ID_building'] != 'A_21_PV28.0_STR':
pass
if 'A_' in building_types.iloc[i]['ID_building']:
# get the index of the reference profile for this building type
index_ref_elec_demand = building_types['closest_index'][i]
# scale profiles based on the reference data
# ELECTRICITY
scaled_heat_demand = building_types['Electricity_demand'][i] / ref_yearly_elec_demand[index_ref_elec_demand] * input_profiles['ref_elec_demand_id_' + str(index_ref_elec_demand)]
input_profiles['elec_demand_prosumer_' + str(building_types.loc[i, 'ID_building'])] = scaled_heat_demand
# ROOM HEATING
scaled_heat_demand = building_types['Thermal_demand'][i] / ref_yearly_rh_demand * input_profiles['room_heating_mfh_passive']
input_profiles['room_heat_demand_prosumer_' + str(building_types.loc[i,'ID_building'])] = scaled_heat_demand
# HOT WATER
scaled_hot_water_demand = building_types['HotWater_demand'][i] / ref_yearly_rh_demand * input_profiles['dhw_mhf_passive']
input_profiles['hot_water_demand_prosumer_' + str(building_types.loc[i, 'ID_building'])] = scaled_hot_water_demand
if 'HP' in building_types.loc[i, 'ID_building']:
prosumer_dict[prosumer_name]= {'config_path': 'input_files/models/prosumer_models/building_types_aachen_2022/'+ str(building_types.loc[i,'ID_building']) + '/config.csv',
'topology_path': 'input_files/models/prosumer_models/building_types_aachen_2022/'+ str(building_types.loc[i,'ID_building']),
'profiles':{'elec_cns': 'elec_demand_prosumer_' + str(building_types.loc[i, 'ID_building']),
'therm_cns': 'room_heat_demand_prosumer_' + str(building_types.loc[i,'ID_building']),
'dhw_dmd': 'hot_water_demand_prosumer_' + str(building_types.loc[i, 'ID_building']),
'pv_roof': ['pv_factors_aachen_1'],
'heat_pump': 'temperature_1'}}
elif 'PV' in building_types.loc[i,'ID_building']:
prosumer_dict[prosumer_name] = {'config_path': 'input_files/models/prosumer_models/' + folder_building_configs + '/' + str(building_types.loc[i, 'ID_building']) + '/config.csv',
'topology_path': 'input_files/models/prosumer_models/' + folder_building_configs + '/' + str(building_types.loc[i, 'ID_building']),
'profiles': {'elec_cns': 'elec_demand_prosumer_' + str(building_types.loc[i, 'ID_building']),
'pv_roof': ['pv_factors_aachen_1']}}
else:
prosumer_dict[prosumer_name] = {'config_path': 'input_files/models/prosumer_models/' + folder_building_configs + '/' + str(building_types.loc[i, 'ID_building']) + '/config.csv',
'topology_path': 'input_files/models/prosumer_models/' + folder_building_configs + '/' + str(building_types.loc[i, 'ID_building']),
'profiles': {'elec_cns': 'elec_demand_prosumer_' + str(building_types.loc[i, 'ID_building'])}}
num=0
prosumer_main = main_prosumer.ProsumerMain(prosumer_dict, input_profiles, t_horizon, t_step)
prosumer_sizing_strategy = 'annuity'
prosumer_main.optimize_sizing(prosumer_sizing_strategy)
prosumer_main.save_results()
prosumers = prosumer_main.prosumers
if simulation_scope == SimulationScope.PROSUMER:
exit()
district_assets_dict = {'da_bat': {'config_path': 'input_files/models/district_models/example_CA/config.csv',
'topology_path': 'input_files/models/district_models/example_CA',
'profiles': {}}}
district_assets_dict = {}
district_assets = main_prosumer.DistrictAssetMain(district_assets_dict, input_profiles, t_horizon, t_step).district_assets
district_dict = {'community': {'config_path': 'input_files/models/district_models/example_community/config.csv',
'profiles': {'elec_price': 'elec_price_1'}}}
district_main = main_district.DistrictMain(district_dict, prosumers, district_assets, input_profiles, t_horizon, t_step)
district_sizing_strategy = 'max_operational_profit'
district_main.optimize_sizing(district_sizing_strategy)
district_operation_strategy = 'max_operational_profit'
district_main.optimize_operation(district_operation_strategy)
district_main.save_results()