from pathlib import Path from hub.imports.geometry_factory import GeometryFactory from hub.imports.construction_factory import ConstructionFactory from hub.imports.usage_factory import UsageFactory from hub.helpers.dictionaries import Dictionaries from hub.imports.energy_systems_factory import EnergySystemsFactory import hub.helpers.constants as cte from results import Results from monthly_energy_balance_engine import MonthlyEnergyBalanceEngine from sra_engine import SraEngine try: file_path = (Path(__file__).parent / 'input_files' / 'output_buildings.geojson') construction_format = 'nrcan' usage_format = 'nrcan' energy_systems_format = 'montreal_custom' out_path = (Path(__file__).parent / 'output_files') tmp_folder = (Path(__file__).parent / 'tmp') print('[simulation start]') city = GeometryFactory('geojson', path=file_path, height_field='height', year_of_construction_field='year_of_construction', function_field='function', function_to_hub=Dictionaries().montreal_function_to_hub_function).city print(f'city created from {file_path}') ConstructionFactory(construction_format, city).enrich() print('enrich constructions... done') UsageFactory(usage_format, city).enrich() print('enrich usage... done') i = 1 x = len(city.buildings) for building in city.buildings: if i < x: building.energy_systems_archetype_name = 'system 1 gas' else: building.energy_systems_archetype_name = 'system 6 gas' i = i + 1 EnergySystemsFactory(energy_systems_format, city).enrich() print('enrich systems... done') print('exporting:') SraEngine(city, tmp_folder) print(' sra processed...') MonthlyEnergyBalanceEngine(city, tmp_folder) print(' insel processed...') for building in city.buildings: for energy_system in building.energy_systems: if cte.HEATING in energy_system.demand_types: energy_system.generation_system.heat_power = building.heating_peak_load[cte.YEAR][0] if cte.COOLING in energy_system.demand_types: energy_system.generation_system.cooling_power = building.cooling_peak_load[cte.YEAR][0] print('importing results:') results = Results(city, out_path) results.print() print('results printed...') print('[simulation end]') except Exception as ex: print(ex) print('error: ', ex) print('[simulation abort]')