diff --git a/python_scripts/run_simstadt_from_python/variable_window_ratio.py b/python_scripts/run_simstadt_from_python/variable_window_ratio.py index fb0827e8ae2da13097e80b77accbc1aeb4a9e652..54ef48b1f4e1f1a48aea7034665cba092e31be39 100644 --- a/python_scripts/run_simstadt_from_python/variable_window_ratio.py +++ b/python_scripts/run_simstadt_from_python/variable_window_ratio.py @@ -1,29 +1,59 @@ from pathlib import Path import shutil -from run_simstadt_workflow import find_simstadt, check_paths, SCRIPT_DIR, prepare_workflow, run_workflow +from xml.etree import ElementTree as et +import pandas as pd + +from run_simstadt_workflow import find_simstadt, SCRIPT_DIR, run_workflow SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/' REPO_PATH = Path.home() / 'git' / 'simstadt2' / 'TestRepository' PROJECT_NAME = 'Gruenbuehl' -CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010_2buildings.gml'] +CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010.gml'] PROJECT_PATH = REPO_PATH / f'{PROJECT_NAME}.proj' PARAMS = 'params.xml' +BUILDING_PHYSICS_LIBRARY = 'GermanBuildingTypologyLibrary_IWU.xml' + print(find_simstadt(SIMSTADT2_GLOB)) TEMPLATE_NAME = '99_HeatDemand' -TEMPLATE = SCRIPT_DIR / 'Template' / f'{TEMPLATE_NAME}.flow' # Heat demand, with custom BuildingPhysics +template = SCRIPT_DIR / 'Template' / f'{TEMPLATE_NAME}.flow' # Heat demand, with custom BuildingPhysics + +workflow_path = PROJECT_PATH / f'{TEMPLATE_NAME}.flow' + +shutil.copytree(template, workflow_path, dirs_exist_ok=True) +print(workflow_path) + +physics_processor_step = workflow_path / '01_Preprocessing.step/02_PhysicsPreprocessor.step' + + +############# Specify custom lib ######################### +custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY + +physics_processor_params = physics_processor_step / PARAMS -WORKFLOW_PATH = PROJECT_PATH / f'{TEMPLATE_NAME}.flow' +tree = et.parse(physics_processor_params) +root = tree.getroot() -shutil.copytree(TEMPLATE, WORKFLOW_PATH, dirs_exist_ok=True) +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) +########################################################## +output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), workflow_path, CITYGMLS) +heat_demand_csv = next(file for file in output_files if 'HEATING.csv' in file.name) +################### Parse heat demand ######################## -output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), WORKFLOW_PATH, CITYGMLS) +df = pd.read_csv(heat_demand_csv, + skiprows=list(range(19)) + [20], + sep=';', + decimal=',' + ) -print(next(file for file in output_files if 'HEATING.csv' in file.name)) +heat_demand_MWh = df['Yearly Heating demand'].sum() / 1000 +print(f"Total heat demand : {heat_demand_MWh:.0f} MWh / a")