From 37c09df93200ca815141a671711e7acb063d997d Mon Sep 17 00:00:00 2001 From: Guille Date: Tue, 25 Jul 2023 09:29:39 -0400 Subject: [PATCH] IDF export will not longer blindly assign the Montreal as weather file --- hub/exports/energy_building_exports_factory.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hub/exports/energy_building_exports_factory.py b/hub/exports/energy_building_exports_factory.py index 3fefaeea..952e4a12 100644 --- a/hub/exports/energy_building_exports_factory.py +++ b/hub/exports/energy_building_exports_factory.py @@ -7,10 +7,13 @@ Project Coder Pilar Monsalvete Alvarez de uribarri pilar.monsalvete@concordia.ca from pathlib import Path +import requests + from hub.exports.building_energy.energy_ade import EnergyAde from hub.exports.building_energy.idf import Idf from hub.exports.building_energy.insel.insel_monthly_energy_balance import InselMonthlyEnergyBalance from hub.helpers.utils import validate_import_export_type +from hub.imports.weather.helpers.weather import Weather as wh class EnergyBuildingsExportsFactory: @@ -49,8 +52,11 @@ class EnergyBuildingsExportsFactory: :return: None """ idf_data_path = (Path(__file__).parent / './building_energy/idf_files/').resolve() - # todo: create a get epw file function based on the city - weather_path = (Path(__file__).parent / '../data/weather/epw/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').resolve() + url = wh().epw_file(self._city.region_code) + weather_path = (Path(__file__).parent.parent / f'data/weather/epw/{url.rsplit("/", 1)[1]}').resolve() + if not weather_path.exists(): + with open(weather_path, 'wb') as epw_file: + epw_file.write(requests.get(url, allow_redirects=True).content) return Idf(self._city, self._path, (idf_data_path / 'Minimal.idf'), (idf_data_path / 'Energy+.idd'), weather_path, target_buildings=self._target_buildings)