Fix broken unit test, change test gml file to 20 buildings instead 2 and correct physic path so standard library is used instead custom one

This commit is contained in:
Guille 2020-11-04 11:56:57 -05:00
parent 3c79c2288c
commit 93a35d359c
7 changed files with 48 additions and 36 deletions

View File

@ -7,8 +7,14 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
class OccupancyHelper: class OccupancyHelper:
occupancy_function = { occupancy_function = {
'C1': 'C-12 Residential',
'D3': 'C-12 Residential',
'D6': 'C-12 Residential',
'I1': 'C-2 Health', 'I1': 'C-2 Health',
'C1': 'C-12 Residential' 'RI': 'C-12 Residential',
'RM': 'C-12 Residential',
'U0': 'C-10 Warehouse',
'W4': 'C-9 School',
} }
@staticmethod @staticmethod

View File

@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Soroush Samareh Abolhassani - soroush.samarehabolhassani@mail.concordia.ca Copyright © 2020 Project Author Soroush Samareh Abolhassani - soroush.samarehabolhassani@mail.concordia.ca
""" """
from geomeppy import IDF from geomeppy import IDF
import os
import esoreader import esoreader
from pathlib import Path from pathlib import Path
@ -62,9 +63,8 @@ class IdfHelper:
_points = IdfHelper._matrix_to_2d_list(building.foot_print.points) _points = IdfHelper._matrix_to_2d_list(building.foot_print.points)
self._idf.add_block(name=building.name, coordinates=_points, height=building.max_height, self._idf.add_block(name=building.name, coordinates=_points, height=building.max_height,
num_stories=int(building.storeys_above_ground)) num_stories=int(building.storeys_above_ground))
# self._idf.intersect_match()
# self._idf.set_default_constructions()
self.add_heating_system(building) self.add_heating_system(building)
self._idf.intersect_match()
def add_surfaces(self, building): def add_surfaces(self, building):
self.add_block(building) self.add_block(building)
@ -78,35 +78,38 @@ class IdfHelper:
print(surface.area) print(surface.area)
wall.setcoords(coordinates) wall.setcoords(coordinates)
def run(self, window_ratio=0.35, display_render=False, output_prefix=None, output_directory='tests', keep_file=None):
self._idf.intersect_match() def run(self, output_directory, window_ratio=0.35, display_render=False, output_prefix=None, keep_file=None):
self._idf.set_default_constructions() self._idf.set_default_constructions()
self._idf.set_wwr(window_ratio, construction="Project External Window") self._idf.set_wwr(window_ratio, construction="Project External Window")
self._idf.translate_to_origin() self._idf.translate_to_origin()
if display_render: if display_render:
self._idf.view_model() self._idf.view_model()
# self._idf.to_obj('ep_outputs/city.obj')
# Run # Run
#self._idf.newidfobject("OUTPUT:METER", Key_Name="Heating:DistrictHeating", Reporting_Frequency="hourly") self._idf.newidfobject("OUTPUT:METER", Key_Name="Heating:DistrictHeating", Reporting_Frequency="hourly")
#self._idf.newidfobject("OUTPUT:METER", Key_Name="Cooling:DistrictCooling", Reporting_Frequency="hourly") self._idf.newidfobject("OUTPUT:METER", Key_Name="Cooling:DistrictCooling", Reporting_Frequency="hourly")
idf_path = None
if keep_file is not None: if keep_file is not None:
idf_path = (keep_file / 'in.idf').resolve() idf_path = (keep_file / 'in.idf').resolve()
print(str(idf_path))
self._idf.saveas(str(idf_path)) self._idf.saveas(str(idf_path))
self._idf.run(output_prefix=output_prefix, output_directory=output_directory, expandobjects=True) if idf_path is None:
idf_path = (Path(__file__).parent / 'in.idf').resolve()
# There is a bug in the IDF class, when called, it return an error, as a work around we call call energy+ directly
run_command = f"energyplus --weather {self._epw_file_path} --output-directory {output_directory} --idd " \
f"{self._idd_file_path} --expandobjects --output-prefix {output_prefix} {idf_path}"
os.system(run_command)
if keep_file is None:
os.remove(idf_path)
return return
@staticmethod @staticmethod
def read_eso(eso_path): def read_eso(eso_file_path):
print("read_eso") dd, data = esoreader.read(eso_file_path)
return [], [] list_values = [v for v in data.values()]
"""
eso = esoreader.read(str(eso_path))
list_values = [v for v in df.values()]
heating = [(float(x)) / 3600000.0 for x in list_values[0]] heating = [(float(x)) / 3600000.0 for x in list_values[0]]
cooling = [(float(x)) / 3600000.0 for x in list_values[1]] cooling = [(float(x)) / 3600000.0 for x in list_values[1]]
return heating, cooling return heating, cooling
"""

View File

@ -24,7 +24,7 @@ class TestGeometryFactory(TestCase):
def _get_citygml(self): def _get_citygml(self):
if self._city_gml is None: if self._city_gml is None:
file_path = (self._example_path / 'buildings.gml').resolve() file_path = (self._example_path / '20buildings.gml').resolve()
self._city_gml = GeometryFactory('citygml', file_path).city self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none') self.assertIsNotNone(self._city_gml, 'city is none')
return self._city_gml return self._city_gml
@ -102,8 +102,7 @@ class TestGeometryFactory(TestCase):
self.assertIsNotNone(surface.points_list, 'surface points_list is none') self.assertIsNotNone(surface.points_list, 'surface points_list is none')
self.assertIsNotNone(surface.polygon, 'surface polygon is none') self.assertIsNotNone(surface.polygon, 'surface polygon is none')
self.assertIsNotNone(surface.shapely, 'surface shapely is none') self.assertIsNotNone(surface.shapely, 'surface shapely is none')
self.assertIsNotNone(surface.global_irradiance_hour, 'surface global_irradiance_hour is none') self.assertIsNotNone(surface.global_irradiance, 'monthly irradiance is none')
self.assertIsNotNone(surface.global_irradiance_month, 'surface global_irradiance_month is none')
self.assertIsNotNone(surface.normal, 'surface normal is none') self.assertIsNotNone(surface.normal, 'surface normal is none')
self.assertIsNotNone(surface.projection, 'surface projection is none') self.assertIsNotNone(surface.projection, 'surface projection is none')
self.assertIsNotNone(surface.swr, 'surface swr is none') self.assertIsNotNone(surface.swr, 'surface swr is none')

View File

@ -27,9 +27,9 @@ class TestIdf(TestCase):
def _get_city(self): def _get_city(self):
if self._city_gml is None: if self._city_gml is None:
file_path = (self._example_path / 'buildings.gml').resolve() file_path = (self._example_path / '20buildings.gml').resolve()
self._city_gml = GeometryFactory('citygml', file_path).city self._city_gml = GeometryFactory('citygml', file_path).city
PhysicsFactory('us_new_york', self._city_gml, base_path=self._example_path) PhysicsFactory('us_new_york', self._city_gml)
UsageFactory('us_new_york', self._city_gml) UsageFactory('us_new_york', self._city_gml)
return self._city_gml return self._city_gml
@ -37,14 +37,16 @@ class TestIdf(TestCase):
idd_file_path = (self._example_path / 'energy+.idd').resolve() idd_file_path = (self._example_path / 'energy+.idd').resolve()
idf_file_path = (self._example_path / 'minimal.idf').resolve() idf_file_path = (self._example_path / 'minimal.idf').resolve()
epw_file_path = (self._example_path / 'montreal.epw').resolve() epw_file_path = (self._example_path / 'montreal.epw').resolve()
_idf = IdfHelper(idf_file_path, idd_file_path, epw_file_path) _idf = IdfHelper(idf_file_path, idd_file_path, epw_file_path)
city = self._get_city() city = self._get_city()
for building in city.buildings: for building in city.buildings:
_idf.add_block(building) _idf.add_block(building)
break test_prefix = 'test_idf_blocks'
_idf.run(output_prefix='test_idf_blocks', output_directory="ep_outputs", keep_file=self._output_path) _idf.run(self._output_path, output_prefix=test_prefix, keep_file=self._output_path, display_render=True)
_idf.read_eso(str(self._example_path)) eso_file_path = (self._output_path / f'{test_prefix}out.eso')
self.assertEqual(1, 2, "arent equal") 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")
# todo: clean up the files # todo: clean up the files
def test_idf_surfaces(self): def test_idf_surfaces(self):
@ -56,6 +58,9 @@ class TestIdf(TestCase):
city = self._get_city() city = self._get_city()
for building in city.buildings: for building in city.buildings:
_idf.add_surfaces(building) _idf.add_surfaces(building)
_idf.run(output_prefix='test_idf_surfaces', output_directory="ep_outputs", keep_file=self._output_path) test_prefix = 'test_idf_blocks'
self.assertEqual(1, 2, "arent equal") _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")
# todo: clean up the files # todo: clean up the files

View File

@ -34,7 +34,7 @@ class TestOccupancyFactory(TestCase):
def _get_citygml_with_usage(self): def _get_citygml_with_usage(self):
if self._city_gml_with_usage is None: if self._city_gml_with_usage is None:
file_path = (self._example_path / 'buildings.gml').resolve() file_path = (self._example_path / '20buildings.gml').resolve()
self._city_gml_with_usage = GeometryFactory('citygml', file_path).city self._city_gml_with_usage = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml_with_usage, 'city is none') self.assertIsNotNone(self._city_gml_with_usage, 'city is none')
UsageFactory(self._handler, self._city_gml_with_usage) UsageFactory(self._handler, self._city_gml_with_usage)
@ -47,4 +47,3 @@ class TestOccupancyFactory(TestCase):
for building in city.buildings: for building in city.buildings:
for usage_zone in building.usage_zones: for usage_zone in building.usage_zones:
self.assertTrue(usage_zone.schedules) self.assertTrue(usage_zone.schedules)
print(len(Occupancy().get_complete_year_schedule(usage_zone.schedules['Occupancy'])))

View File

@ -25,7 +25,7 @@ class TestPhysicsFactory(TestCase):
def _get_citygml(self): def _get_citygml(self):
if self._city_gml is None: if self._city_gml is None:
file_path = (self._example_path / 'buildings.gml').resolve() file_path = (self._example_path / '20buildings.gml').resolve()
self._city_gml = GeometryFactory('citygml', file_path).city self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none') self.assertIsNotNone(self._city_gml, 'city is none')
return self._city_gml return self._city_gml
@ -33,7 +33,7 @@ class TestPhysicsFactory(TestCase):
def _get_city_with_physics(self): def _get_city_with_physics(self):
if self._nyc_with_physics is None: if self._nyc_with_physics is None:
self._nyc_with_physics = self._get_citygml() self._nyc_with_physics = self._get_citygml()
PhysicsFactory('us_new_york', self._nyc_with_physics, base_path=self._example_path) PhysicsFactory('us_new_york', self._nyc_with_physics)
return self._nyc_with_physics return self._nyc_with_physics
def test_city_with_physics(self): def test_city_with_physics(self):

View File

@ -26,7 +26,7 @@ class TestWeatherFactory(TestCase):
def _get_citygml(self): def _get_citygml(self):
if self._city_gml is None: if self._city_gml is None:
file_path = (self._example_path / 'buildings.gml').resolve() file_path = (self._example_path / '20buildings.gml').resolve()
self._city_gml = GeometryFactory('citygml', file_path).city self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none') self.assertIsNotNone(self._city_gml, 'city is none')
return self._city_gml return self._city_gml