2021-06-09 10:47:46 -04:00
|
|
|
"""
|
|
|
|
TestExports test and validate the city export formats
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2022-04-08 09:35:33 -04:00
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
|
|
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2021-06-09 10:47:46 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from unittest import TestCase
|
|
|
|
import pandas as pd
|
2023-01-24 10:51:50 -05:00
|
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
|
|
from hub.imports.geometry.helpers.geometry_helper import GeometryHelper
|
|
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
|
|
from hub.imports.usage_factory import UsageFactory
|
|
|
|
from hub.exports.exports_factory import ExportsFactory
|
|
|
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
|
|
|
import hub.helpers.constants as cte
|
|
|
|
from hub.city_model_structure.city import City
|
2021-06-09 10:47:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestExports(TestCase):
|
|
|
|
"""
|
|
|
|
TestExports class contains the unittest for export functionality
|
|
|
|
"""
|
|
|
|
def setUp(self) -> None:
|
|
|
|
"""
|
|
|
|
Test setup
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
self._city = None
|
|
|
|
self._complete_city = None
|
|
|
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
|
|
|
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
|
|
|
|
|
|
|
def _get_citygml(self, file):
|
|
|
|
file_path = (self._example_path / file).resolve()
|
2022-11-21 13:53:58 -05:00
|
|
|
self._city = GeometryFactory('citygml', path=file_path).city
|
2021-06-09 10:47:46 -04:00
|
|
|
self.assertIsNotNone(self._city, 'city is none')
|
|
|
|
return self._city
|
|
|
|
|
|
|
|
def _get_complete_city(self, from_pickle):
|
|
|
|
if self._complete_city is None:
|
|
|
|
if from_pickle:
|
|
|
|
file_path = (self._example_path / 'ConcordiaSWGcampus.pickle').resolve()
|
|
|
|
self._complete_city = City.load(file_path)
|
|
|
|
else:
|
|
|
|
file_path = (self._example_path / 'one_building_in_kelowna.gml').resolve()
|
|
|
|
self._complete_city = self._get_citygml(file_path)
|
2022-03-24 16:51:01 -04:00
|
|
|
for building in self._complete_city.buildings:
|
|
|
|
building.function = GeometryHelper().libs_function_from_hft(building.function)
|
2022-04-26 19:14:12 -04:00
|
|
|
building.year_of_construction = 2006
|
2021-11-16 07:57:47 -05:00
|
|
|
ConstructionFactory('nrel', self._complete_city).enrich()
|
2021-06-09 10:47:46 -04:00
|
|
|
UsageFactory('ca', self._complete_city).enrich()
|
2022-11-07 11:49:59 -05:00
|
|
|
cli = (self._example_path / 'weather' / 'inseldb_Summerland.cli').resolve()
|
2021-06-09 10:47:46 -04:00
|
|
|
self._complete_city.climate_file = Path(cli)
|
|
|
|
self._complete_city.climate_reference_city = 'Summerland'
|
|
|
|
dummy_measures = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
|
|
|
for building in self._complete_city.buildings:
|
|
|
|
building.heating[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures})
|
|
|
|
building.cooling[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures})
|
|
|
|
building.heating[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]})
|
|
|
|
building.cooling[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]})
|
|
|
|
return self._complete_city
|
|
|
|
|
|
|
|
def _export(self, export_type, from_pickle=False):
|
|
|
|
self._complete_city = self._get_complete_city(from_pickle)
|
|
|
|
ExportsFactory(export_type, self._complete_city, self._output_path).export()
|
|
|
|
|
|
|
|
def test_obj_export(self):
|
2021-08-27 12:51:30 -04:00
|
|
|
"""
|
|
|
|
export to obj
|
|
|
|
"""
|
2021-06-10 08:29:24 -04:00
|
|
|
self._export('obj', False)
|
2021-06-09 10:47:46 -04:00
|
|
|
|
|
|
|
def test_stl_export(self):
|
2021-08-27 12:51:30 -04:00
|
|
|
"""
|
|
|
|
export to stl
|
|
|
|
"""
|
2021-06-10 08:29:24 -04:00
|
|
|
self._export('stl', False)
|
2021-06-09 10:47:46 -04:00
|
|
|
|
|
|
|
def test_energy_ade_export(self):
|
2021-08-27 12:51:30 -04:00
|
|
|
"""
|
|
|
|
export to energy ADE
|
|
|
|
"""
|
2021-06-09 10:47:46 -04:00
|
|
|
self._export('energy_ade')
|
|
|
|
|
|
|
|
def test_sra_export(self):
|
2021-08-27 12:51:30 -04:00
|
|
|
"""
|
|
|
|
export to SRA
|
|
|
|
"""
|
2021-06-09 10:47:46 -04:00
|
|
|
self._export('sra')
|
2022-11-07 15:04:51 -05:00
|
|
|
|
|
|
|
def test_idf_export(self):
|
|
|
|
"""
|
|
|
|
export to IDF
|
|
|
|
"""
|
|
|
|
city = self._get_citygml('EV_GM_MB_LoD2.gml')
|
|
|
|
for building in city.buildings:
|
|
|
|
building.year_of_construction = 2006
|
|
|
|
if building.function is None:
|
|
|
|
building.function = 'large office'
|
|
|
|
ConstructionFactory('nrel', city).enrich()
|
|
|
|
UsageFactory('comnet', city).enrich()
|
|
|
|
try:
|
2022-12-01 11:47:21 -05:00
|
|
|
EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
|
|
|
|
EnergyBuildingsExportsFactory('idf', city, self._output_path,
|
|
|
|
target_buildings=['gml_1066158', 'gml_1066159']).export()
|
2022-11-07 15:04:51 -05:00
|
|
|
except Exception:
|
|
|
|
self.fail("Idf ExportsFactory raised ExceptionType unexpectedly!")
|
|
|
|
|
|
|
|
|