summer_course_2024/tests/test_idf.py

79 lines
3.2 KiB
Python
Raw Normal View History

"""
TestOccupancyFactory test and validate the city model structure schedules parameters
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from pathlib import Path
from unittest import TestCase
from imports.geometry_factory import GeometryFactory
from imports.construction_factory import ConstructionFactory
from imports.usage_factory import UsageFactory
from imports.schedules_factory import SchedulesFactory
2021-08-11 10:29:54 -04:00
from exports.exports_factory import ExportsFactory
import os
import glob
class TestIdf(TestCase):
"""
Test IDF Class
"""
def setUp(self) -> None:
"""
Test setup
:return: None
"""
self._city_gml = None
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
2020-10-27 13:19:50 -04:00
def _get_city(self):
if self._city_gml is None:
file_path = (self._example_path / 'pluto_building.gml').resolve()
self._city_gml = GeometryFactory('citygml', file_path).city
ConstructionFactory('us_new_york', self._city_gml)
2020-10-27 13:19:50 -04:00
UsageFactory('us_new_york', self._city_gml)
2020-11-18 08:58:37 -05:00
UsageFactory('us_new_york', self._city_gml)
2020-12-15 14:57:46 -05:00
SchedulesFactory('demo', self._city_gml)
return self._city_gml
2020-10-27 13:19:50 -04:00
def test_idf_blocks(self):
idd_file_path = (self._example_path / 'energy+.idd').resolve()
idf_file_path = (self._example_path / 'minimal.idf').resolve()
epw_file_path = (self._example_path / 'montreal.epw').resolve()
idf = IdfHelper(idf_file_path, idd_file_path, epw_file_path)
2020-10-27 13:19:50 -04:00
city = self._get_city()
for building in city.buildings:
idf.add_block(building)
test_prefix = 'test_idf_blocks'
idf.run(self._output_path, output_prefix=test_prefix, keep_file=self._output_path)
eso_file_path = (self._output_path / f'{test_prefix}out.eso')
heating, cooling = idf.read_eso(str(eso_file_path))
self.assertEqual(len(heating), len(cooling), "Cooling and Heating doesn't contains the same amount of values")
self.assertNotEqual(len(heating), 0, "Cooling and Heating series are empty")
file_list = glob.glob(str(Path(self._output_path / '*').resolve()))
for file_path in file_list:
os.remove(file_path)
2020-10-26 13:33:03 -04:00
2020-10-27 13:19:50 -04:00
def test_idf_surfaces(self):
idd_file_path = (self._example_path / 'energy+.idd').resolve()
idf_file_path = (self._example_path / 'minimal.idf').resolve()
epw_file_path = (self._example_path / 'montreal.epw').resolve()
2020-10-28 12:20:13 -04:00
idf = IdfHelper(idf_file_path, idd_file_path, epw_file_path)
2020-10-27 13:19:50 -04:00
city = self._get_city()
for building in city.buildings:
idf.add_surfaces(building)
2020-11-18 02:28:29 -05:00
idf.add_schedule(building)
idf.add_occupancy()
test_prefix = 'test_idf_blocks'
idf.run(self._output_path, output_prefix=test_prefix, keep_file=self._output_path)
eso_file_path = (self._output_path / f'{test_prefix}out.eso')
heating, cooling = idf.read_eso(str(eso_file_path))
self.assertEqual(len(heating), len(cooling), "Cooling and Heating doesn't contains the same amount of values")
self.assertNotEqual(len(heating), 0, "Cooling and Heating series are empty")
file_list = glob.glob(str(Path(self._output_path / '*').resolve()))
for file_path in file_list:
os.remove(file_path)