system_assignation/scripts/ep_workflow.py

64 lines
2.1 KiB
Python
Raw Normal View History

import glob
import os
2022-03-24 09:22:39 -04:00
import sys
from pathlib import Path
import csv
2023-03-21 14:27:37 -04:00
from hub.imports.geometry_factory import GeometryFactory
from hub.imports.construction_factory import ConstructionFactory
from hub.imports.usage_factory import UsageFactory
from hub.imports.weather_factory import WeatherFactory
2023-03-21 14:27:37 -04:00
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
from hub.helpers.dictionaries import Dictionaries
from hub.imports.results_factory import ResultFactory
2023-03-21 14:27:37 -04:00
sys.path.append('./')
2022-03-24 09:22:39 -04:00
try:
file_path = (Path(__file__).parent.parent / 'input_files' / 'Citylayers_neighbours_simp2.json')
out_path = (Path(__file__).parent.parent / 'out_files')
files = glob.glob(f'{out_path}/*')
for file in files:
if file != '.gitignore':
os.remove(file)
2022-03-24 09:22:39 -04:00
2022-05-11 07:34:24 -04:00
print('[simulation start]')
2023-03-21 14:27:37 -04:00
city = GeometryFactory('geojson',
path=file_path,
height_field='heightmax',
year_of_construction_field='ANNEE_CONS',
function_field='CODE_UTILI',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
print(f'city created from {file_path}')
ConstructionFactory('nrcan', city).enrich()
2022-05-11 07:34:24 -04:00
print('enrich constructions... done')
2023-03-21 14:27:37 -04:00
UsageFactory('nrcan', city).enrich()
2022-05-11 07:34:24 -04:00
print('enrich usage... done')
WeatherFactory('epw', city).enrich()
print('enrich weather... done')
2022-03-24 09:22:39 -04:00
2022-05-11 07:34:24 -04:00
area = 0
volume = 0
for building in city.buildings:
volume = building.volume
for ground in building.grounds:
area += ground.perimeter_polygon.area
2022-03-24 09:22:39 -04:00
2022-05-11 07:34:24 -04:00
print('exporting:')
_idf = EnergyBuildingsExportsFactory('idf', city, out_path).export()
2022-05-11 07:34:24 -04:00
print(' idf exported...')
_idf.run()
2022-03-24 09:22:39 -04:00
2022-05-11 07:34:24 -04:00
csv_file = str((out_path / f'{city.name}_out.csv').resolve())
eso_file = str((out_path / f'{city.name}_out.eso').resolve())
idf_file = str((out_path / f'{city.name}.idf').resolve())
obj_file = str((out_path / f'{city.name}.obj').resolve())
ResultFactory('energy_plus_multiple_buildings', city, out_path).enrich()
2022-05-11 07:34:24 -04:00
except Exception as ex:
print(ex)
2022-05-11 07:34:24 -04:00
print('error: ', ex)
print('[simulation abort]')
2022-03-24 09:22:39 -04:00
sys.stdout.flush()