103 lines
3.8 KiB
Python
103 lines
3.8 KiB
Python
"""
|
|
TestPeakLoadsWorkflow test
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2022 Concordia CERC group
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from unittest import TestCase
|
|
import pandas as pd
|
|
import hub.helpers.constants as cte
|
|
from helpers.monthly_values import MonthlyValues
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
from hub.imports.usage_factory import UsageFactory
|
|
from hub.imports.weather_factory import WeatherFactory
|
|
from peak_loads import PeakLoads
|
|
|
|
|
|
class TestPeakLoadsWorkflow(TestCase):
|
|
"""
|
|
TestPeakLoadsWorkflow class
|
|
"""
|
|
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()
|
|
self._city = GeometryFactory('citygml', path=file_path).city
|
|
self.assertIsNotNone(self._city, 'city is none')
|
|
return self._city
|
|
|
|
@property
|
|
def _read_sra_file(self) -> []:
|
|
path = (self._example_path / "one_building_in_kelowna_sra_SW.out").resolve()
|
|
_results = pd.read_csv(path, sep='\s+', header=0)
|
|
id_building = ''
|
|
header_building = []
|
|
_radiation = []
|
|
for column in _results.columns.values:
|
|
if id_building != column.split(':')[1]:
|
|
id_building = column.split(':')[1]
|
|
if len(header_building) > 0:
|
|
_radiation.append(pd.concat([MonthlyValues().month_hour, _results[header_building]], axis=1))
|
|
header_building = [column]
|
|
else:
|
|
header_building.append(column)
|
|
_radiation.append(pd.concat([MonthlyValues().month_hour, _results[header_building]], axis=1))
|
|
return _radiation
|
|
|
|
def _set_irradiance_surfaces(self, city, irradiance_format):
|
|
"""
|
|
saves in building surfaces the correspondent irradiance at different time-scales depending on the mode
|
|
if building is None, it saves all buildings' surfaces in file, if building is specified, it saves only that
|
|
specific building values
|
|
:parameter city: city
|
|
:return: none
|
|
"""
|
|
for radiation in self._read_sra_file:
|
|
city_object_name = radiation.columns.values.tolist()[1].split(':')[1]
|
|
building = city.city_object(city_object_name)
|
|
for column in radiation.columns.values:
|
|
if column == cte.MONTH:
|
|
continue
|
|
header_id = column
|
|
surface_id = header_id.split(':')[2]
|
|
surface = building.surface_by_id(surface_id)
|
|
new_value = pd.DataFrame(radiation[[header_id]].to_numpy(), columns=[irradiance_format])
|
|
surface.global_irradiance[cte.HOUR] = new_value
|
|
|
|
def _enrich_city(self, city, weather_file, weather_format, irradiance_format, construction_format, usage_format):
|
|
WeatherFactory(weather_format, city, file_name=weather_file).enrich()
|
|
self._set_irradiance_surfaces(city, irradiance_format)
|
|
|
|
for building in city.buildings:
|
|
building.year_of_construction = 2006
|
|
if building.function is None:
|
|
building.function = cte.LARGE_OFFICE
|
|
|
|
ConstructionFactory(construction_format, city).enrich()
|
|
UsageFactory(usage_format, city).enrich()
|
|
|
|
def test_workflow(self):
|
|
outputs_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
|
|
|
gml_file = 'one_building_in_kelowna.gml'
|
|
city = self._get_citygml(gml_file)
|
|
|
|
weather_file = 'CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw'
|
|
weather_format = 'epw'
|
|
irradiance_format = 'sra'
|
|
construction_format = 'nrcan'
|
|
usage_format = 'nrcan'
|
|
self._enrich_city(city, weather_file, weather_format, irradiance_format, construction_format, usage_format)
|
|
PeakLoads(city, outputs_path, weather_format, irradiance_format)
|