Commits (4)
%% Cell type:code id:d2c68f35 tags:
``` python
import pandas as pd
```
%% Cell type:code id:66f2a037 tags:
``` python
df = pd.read_csv(r"C:\Users\eric.duminil\git\simstadt2\TestRepository\Gruenbuehl.proj\99_HeatDemand.flow\04_MonthlyEnergyBalance.step\Gruenbuehl_LOD2_ALKIS_1010_DIN18599_HEATING.csv",
skiprows=list(range(19)) + [20],
sep=';',
decimal=','
)
```
%% Cell type:code id:c94d6456 tags:
``` python
df
```
%%%% Output: execute_result
GMLId ParentGMLId Latitude Longitude X-coordinate \
0 DEBW_LOD2_1004495 NaN 48.87950 9.21478 3515829.63
1 DEBW_LOD2_1004496 NaN 48.87939 9.21456 3515813.56
2 DEBW_LOD2_1003853 NaN 48.87800 9.21559 3515888.84
3 DEBW_LOD2_1003651 NaN 48.87778 9.21467 3515821.59
4 DEBW_LOD2_1003854 NaN 48.87811 9.21559 3515889.08
.. ... ... ... ... ...
100 DEBW_LOD2_2158 NaN 48.87861 9.21813 3516075.53
101 DEBW_LOD2_2200 NaN 48.87856 9.21908 3516145.22
102 DEBW_LOD2_2147 NaN 48.87856 9.21771 3516044.74
103 DEBW_LOD2_2146 NaN 48.87869 9.21771 3516044.42
104 DEBW_LOD2_1249 NaN 48.87922 9.21722 3516008.53
Y-coordinate LOD Year of construction Year of refurbishment \
0 5415809.40 LOD_2 1968 NaN
1 5415796.91 LOD_2 1968 NaN
2 5415642.86 LOD_2 1968 NaN
3 5415617.69 LOD_2 1957 NaN
4 5415655.22 LOD_2 1968 NaN
.. ... ... ... ...
100 5415710.81 LOD_2 1968 NaN
101 5415705.71 LOD_2 1994 NaN
102 5415705.26 LOD_2 1968 NaN
103 5415719.66 LOD_2 1968 NaN
104 5415779.04 LOD_2 1968 NaN
Refurbishment Variant ... March Heating demand April Heating demand \
0 Original ... 15987 4566
1 Original ... 3973 1011
2 Original ... 2998 868
3 Original ... 11847 2785
4 Original ... 3669 1102
.. ... ... ... ...
100 Original ... 8581 2153
101 Original ... 15099 2708
102 Original ... 8622 2174
103 Original ... 6895 1762
104 Original ... 7505 1981
May Heating demand June Heating demand July Heating demand \
0 673 2 0
1 117 0 0
2 125 0 0
3 333 1 0
4 154 0 0
.. ... ... ...
100 289 1 0
101 207 1 0
102 298 1 0
103 226 1 0
104 254 0 0
August Heating demand September Heating demand October Heating demand \
0 0 690 8449
1 0 120 2085
2 0 120 1578
3 0 401 6428
4 0 140 1938
.. ... ... ...
100 0 286 4447
101 0 295 7775
102 0 292 4476
103 0 284 3871
104 0 307 4159
November Heating demand December Heating demand
0 19075 26508
1 4933 6905
2 3597 5006
3 15161 21212
4 4310 5964
.. ... ...
100 10780 15176
101 20013 28298
102 10820 15219
103 8580 11813
104 9307 12859
[105 rows x 54 columns]
%% Cell type:code id:adbf8c7c tags:
``` python
df['Yearly Heating demand'].sum()
```
%%%% Output: execute_result
8001948
%% Cell type:code id:9c62ba61 tags:
``` python
```
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_345" class="java.beans.XMLDecoder">
<object class="eu.simstadt.workflowsteps.MonthlyEnergyBalanceStep">
<void property="calculationMode">
<object class="java.lang.Enum" method="valueOf">
<class>de.hft.stuttgart.simstadt2.buildingenergymodels.MonthlyBalanceDIN18599$CalculationMode</class>
<string>HEATING_AND_COOLING</string>
</object>
</void>
<void property="name">
<string>Base</string>
</void>
......
from pathlib import Path
import shutil
from xml.etree import ElementTree as et
import logging
import pandas as pd
import re
import matplotlib.pyplot as plt
from run_simstadt_workflow import find_simstadt, SCRIPT_DIR, run_workflow
# logging.getLogger().setLevel(logging.WARN)
import logging
logging.getLogger().setLevel(logging.WARN)
#######################################################################
# User params
SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/'
REPO_PATH = Path.home() / 'git' / 'simstadt2' / 'TestRepository'
PROJECT_NAME = 'Gruenbuehl'
CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010.gml']
CITYGML = 'Gruenbuehl_LOD2_ALKIS_1010.gml'
SURFACES = ['outWalls', 'pitchedRoof']
WINDOW_RATIOS = [0, 0.5, 1]
# Heat demand, with custom BuildingPhysics
TEMPLATE_NAME = '99_HeatDemand'
#######################################################################
#######################################################################
XML_LIB_URL = 'http://www.simstadt.eu/BuildingPhysicsLibraries'
NAMESPACE = {'': XML_LIB_URL}
PROJECT_PATH = REPO_PATH / f'{PROJECT_NAME}.proj'
PARAMS = 'params.xml'
BUILDING_PHYSICS_LIBRARY = 'GermanBuildingTypologyLibrary_IWU.xml'
#######################################################################
WINDOW_RATIOS = [0, 0.5, 1]
TEMPLATE_NAME = '99_HeatDemand'
template = SCRIPT_DIR / 'Template' / f'{TEMPLATE_NAME}.flow' # Heat demand, with custom BuildingPhysics
def copy_workflow_from_template(template_name, project_path):
template = SCRIPT_DIR / 'Template' / f'{template_name}.flow'
workflow_path = project_path / f'{template_name}.flow'
workflow_path = PROJECT_PATH / f'{TEMPLATE_NAME}.flow'
shutil.copytree(template, workflow_path, dirs_exist_ok=True)
shutil.copytree(template, workflow_path, dirs_exist_ok=True)
print(workflow_path)
physics_processor_step = workflow_path / '01_Preprocessing.step/02_PhysicsPreprocessor.step'
return workflow_path, physics_processor_step
physics_processor_step = workflow_path / '01_Preprocessing.step/02_PhysicsPreprocessor.step'
def set_custom_library(physics_processor_step):
custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY
############# Specify custom lib #########################
custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY
physics_processor_params = physics_processor_step / PARAMS
physics_processor_params = physics_processor_step / PARAMS
param_tree = et.parse(physics_processor_params)
root = param_tree.getroot()
tree = et.parse(physics_processor_params)
root = tree.getroot()
lib_node = root.find(
".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string")
lib_node.text = str(custom_library_path)
param_tree.write(physics_processor_params)
return custom_library_path
lib_node = root.find(".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string")
lib_node.text = str(custom_library_path)
tree.write(physics_processor_params)
##########################################################
with open(custom_library_path) as library_file:
content = library_file.read()
for window_ratio in WINDOW_RATIOS:
def parse_library(library_path: Path) -> et.ElementTree:
et.register_namespace('', XML_LIB_URL)
return et.parse(library_path)
#################### Update lib with custom values ############################
new_content = re.sub(r"<name>[\w ]+</name>",
f"<name>Custom Physics Library with Window Ratio : {window_ratio}</name>",
content, 1)
# FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio
new_content = re.sub(r"<windowRatio>[\d\.]+</windowRatio>",
f"<windowRatio>{window_ratio}</windowRatio>",
new_content)
def set_custom_window_ratio(tree: et.ElementTree, window_ratio_node: float, export_path: Path):
root = tree.getroot()
root.find('name', NAMESPACE).text = f"Custom Physics Library with Window Ratio : {window_ratio}"
for surface in SURFACES:
for node in root.findall(f'.//{surface}', NAMESPACE):
window_ratio_node = node.find('./windowRatio', NAMESPACE)
if window_ratio_node is not None:
window_ratio_node.text = str(window_ratio)
tree.write(export_path)
with open(custom_library_path, 'w') as library_file:
library_file.write(new_content)
#################################################################################
output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), workflow_path, CITYGMLS)
def parse_results(window_ratio, heat_demand_csv):
df = pd.read_csv(heat_demand_csv,
skiprows=list(range(19)) + [20],
sep=';',
decimal=','
)
heat_demand_csv = next(file for file in output_files if 'HEATING.csv' in file.name)
heating_demand_MWh = df['Yearly Heating demand'].sum() / 1000
cooling_demand_MWh = df['Yearly Cooling demand'].sum() / 1000
print(f"Window Ratio : {window_ratio * 100} %")
print(f"Total heating demand : {heating_demand_MWh:.0f} MWh / a")
print(f"Total cooling demand : {cooling_demand_MWh:.0f} MWh / a")
return {'WindowRatio': window_ratio,
'HeatingDemand': heating_demand_MWh,
'CoolingDemand': cooling_demand_MWh}
workflow_path, physics_processor_step = copy_workflow_from_template(TEMPLATE_NAME, PROJECT_PATH)
custom_library_path = set_custom_library(physics_processor_step)
lib_tree = parse_library(custom_library_path)
all_results = []
for window_ratio in WINDOW_RATIOS:
# TODO: Status quo too
set_custom_window_ratio(lib_tree, window_ratio, custom_library_path)
output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), workflow_path, [CITYGML])
heat_demand_csv = next(file for file in output_files if 'HEATING_AND_COOLING.csv' in file.name)
################### Parse heat demand ########################
df = pd.read_csv(heat_demand_csv,
skiprows=list(range(19)) + [20],
sep=';',
decimal=','
)
all_results.append(parse_results(window_ratio, heat_demand_csv))
heat_demand_MWh = df['Yearly Heating demand'].sum() / 1000
print(f"Window Ratio : {window_ratio * 100} %")
print(f"Total heat demand : {heat_demand_MWh:.0f} MWh / a")
df = pd.DataFrame(all_results).set_index('WindowRatio')
print(df)
df.plot()
plt.ylabel('MWh')
plt.title("Demands depending on Window Ratio")
plt.show()