add weather file to the EnergyBuildingsExportsFactory

This commit is contained in:
Guille Gutierrez 2024-09-23 17:56:58 +02:00
parent c4636c2c3c
commit ef62e2531f

View File

@ -20,9 +20,10 @@ class EnergyBuildingsExportsFactory:
""" """
Energy Buildings exports factory class Energy Buildings exports factory class
""" """
def __init__(self, handler, city, path, custom_insel_block='d18599', target_buildings=None): def __init__(self, handler, city, path, custom_insel_block='d18599', target_buildings=None, weather_file=None):
self._city = city self._city = city
self._export_type = '_' + handler.lower() self._export_type = '_' + handler.lower()
self._weather_file = weather_file
validate_import_export_type(EnergyBuildingsExportsFactory, handler) validate_import_export_type(EnergyBuildingsExportsFactory, handler)
if isinstance(path, str): if isinstance(path, str):
path = Path(path) path = Path(path)
@ -53,12 +54,13 @@ class EnergyBuildingsExportsFactory:
""" """
idf_data_path = (Path(__file__).parent / './building_energy/idf_files/').resolve() idf_data_path = (Path(__file__).parent / './building_energy/idf_files/').resolve()
url = wh().epw_file(self._city.region_code) url = wh().epw_file(self._city.region_code)
weather_path = (Path(__file__).parent.parent / f'data/weather/epw/{url.rsplit("/", 1)[1]}').resolve() if self._weather_file is None:
if not weather_path.exists(): self._weather_file = (Path(__file__).parent.parent / f'data/weather/epw/{url.rsplit("/", 1)[1]}').resolve()
with open(weather_path, 'wb') as epw_file: if not self._weather_file.exists():
with open(self._weather_file, 'wb') as epw_file:
epw_file.write(requests.get(url, allow_redirects=True).content) 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, return Idf(self._city, self._path, (idf_data_path / 'Minimal.idf'), (idf_data_path / 'Energy+.idd'),
target_buildings=self._target_buildings) self._weather_path, target_buildings=self._target_buildings)
@property @property
def _insel_monthly_energy_balance(self): def _insel_monthly_energy_balance(self):