from pathlib import Path import shutil 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.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 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 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) 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 ######################## df = pd.read_csv(heat_demand_csv, skiprows=list(range(19)) + [20], sep=';', decimal=',' ) heat_demand_MWh = df['Yearly Heating demand'].sum() / 1000 print(f"Total heat demand : {heat_demand_MWh:.0f} MWh / a")