forked from s_ranjbar/city_retrofit
Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
7da26947d7
|
@ -8,7 +8,7 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||||
|
|
||||||
class Catalog:
|
class Catalog:
|
||||||
"""
|
"""
|
||||||
Catalogs base class not implemented instance of the Catalog base class,
|
Catalogs base class
|
||||||
catalog_factories will inherit from this class.
|
catalog_factories will inherit from this class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ from hub.catalog_factories.cost.montreal_custom_catalog import MontrealCustomCat
|
||||||
Catalog = TypeVar('Catalog')
|
Catalog = TypeVar('Catalog')
|
||||||
|
|
||||||
|
|
||||||
class CostCatalogFactory:
|
class CostsCatalogFactory:
|
||||||
"""
|
"""
|
||||||
CostsCatalogFactory class
|
CostsCatalogFactory class
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -24,7 +24,7 @@ class OperationalCost:
|
||||||
def fuels(self) -> List[Fuel]:
|
def fuels(self) -> List[Fuel]:
|
||||||
"""
|
"""
|
||||||
Get fuels listed in capital costs
|
Get fuels listed in capital costs
|
||||||
:return: [FUEL]
|
:return: [Fuel]
|
||||||
"""
|
"""
|
||||||
return self._fuels
|
return self._fuels
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from typing import Union
|
||||||
|
|
||||||
from hub.catalog_factories.data_models.usages.appliances import Appliances
|
from hub.catalog_factories.data_models.usages.appliances import Appliances
|
||||||
from hub.catalog_factories.data_models.usages.lighting import Lighting
|
from hub.catalog_factories.data_models.usages.lighting import Lighting
|
||||||
from hub.catalog_factories.data_models.usages.ocupancy import Occupancy
|
from hub.catalog_factories.data_models.usages.occupancy import Occupancy
|
||||||
from hub.catalog_factories.data_models.usages.thermal_control import ThermalControl
|
from hub.catalog_factories.data_models.usages.thermal_control import ThermalControl
|
||||||
from hub.catalog_factories.data_models.usages.domestic_hot_water import DomesticHotWater
|
from hub.catalog_factories.data_models.usages.domestic_hot_water import DomesticHotWater
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ from hub.catalog_factories.catalog import Catalog
|
||||||
from hub.catalog_factories.data_models.usages.appliances import Appliances
|
from hub.catalog_factories.data_models.usages.appliances import Appliances
|
||||||
from hub.catalog_factories.data_models.usages.content import Content
|
from hub.catalog_factories.data_models.usages.content import Content
|
||||||
from hub.catalog_factories.data_models.usages.lighting import Lighting
|
from hub.catalog_factories.data_models.usages.lighting import Lighting
|
||||||
from hub.catalog_factories.data_models.usages.ocupancy import Occupancy
|
from hub.catalog_factories.data_models.usages.occupancy import Occupancy
|
||||||
from hub.catalog_factories.data_models.usages.domestic_hot_water import DomesticHotWater
|
from hub.catalog_factories.data_models.usages.domestic_hot_water import DomesticHotWater
|
||||||
from hub.catalog_factories.data_models.usages.schedule import Schedule
|
from hub.catalog_factories.data_models.usages.schedule import Schedule
|
||||||
from hub.catalog_factories.data_models.usages.thermal_control import ThermalControl
|
from hub.catalog_factories.data_models.usages.thermal_control import ThermalControl
|
||||||
|
|
|
@ -15,7 +15,7 @@ from hub.catalog_factories.catalog import Catalog
|
||||||
from hub.catalog_factories.data_models.usages.appliances import Appliances
|
from hub.catalog_factories.data_models.usages.appliances import Appliances
|
||||||
from hub.catalog_factories.data_models.usages.content import Content
|
from hub.catalog_factories.data_models.usages.content import Content
|
||||||
from hub.catalog_factories.data_models.usages.lighting import Lighting
|
from hub.catalog_factories.data_models.usages.lighting import Lighting
|
||||||
from hub.catalog_factories.data_models.usages.ocupancy import Occupancy
|
from hub.catalog_factories.data_models.usages.occupancy import Occupancy
|
||||||
from hub.catalog_factories.data_models.usages.domestic_hot_water import DomesticHotWater
|
from hub.catalog_factories.data_models.usages.domestic_hot_water import DomesticHotWater
|
||||||
from hub.catalog_factories.data_models.usages.schedule import Schedule
|
from hub.catalog_factories.data_models.usages.schedule import Schedule
|
||||||
from hub.catalog_factories.data_models.usages.thermal_control import ThermalControl
|
from hub.catalog_factories.data_models.usages.thermal_control import ThermalControl
|
||||||
|
|
|
@ -12,6 +12,8 @@ import copy
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import pickle
|
import pickle
|
||||||
|
import sys
|
||||||
|
import pathlib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
|
@ -293,6 +295,11 @@ class City:
|
||||||
:param city_filename: city filename
|
:param city_filename: city filename
|
||||||
:return: City
|
:return: City
|
||||||
"""
|
"""
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
pathlib.PosixPath = pathlib.WindowsPath
|
||||||
|
elif sys.platform == 'linux':
|
||||||
|
pathlib.WindowsPath = pathlib.PosixPath
|
||||||
|
|
||||||
with open(city_filename, 'rb') as file:
|
with open(city_filename, 'rb') as file:
|
||||||
return pickle.load(file)
|
return pickle.load(file)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ Project Coder Peter Yefi peteryefi@gmail.com
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import subprocess
|
||||||
from typing import List, Union, Dict
|
from typing import List, Union, Dict
|
||||||
import yaml
|
import yaml
|
||||||
from string import Template
|
from string import Template
|
||||||
|
@ -58,7 +59,7 @@ class HeatPumpExport:
|
||||||
# Now run insel
|
# Now run insel
|
||||||
self._delete_existing_output_files()
|
self._delete_existing_output_files()
|
||||||
logging.info(f'Running Insel with user input: {user_input} and coefficients {capacity_coefficient}')
|
logging.info(f'Running Insel with user input: {user_input} and coefficients {capacity_coefficient}')
|
||||||
os.system('insel {}'.format(insel_file))
|
subprocess.run(['insel', str(insel_file)])
|
||||||
# Writer headers to csv output files generated by insel
|
# Writer headers to csv output files generated by insel
|
||||||
self._write_insel_output_headers()
|
self._write_insel_output_headers()
|
||||||
# User output
|
# User output
|
||||||
|
|
|
@ -37,19 +37,19 @@ class TestCityMerge(TestCase):
|
||||||
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
||||||
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
||||||
odd_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
odd_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
||||||
par_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
even_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
||||||
for building in full_city.buildings:
|
for building in full_city.buildings:
|
||||||
if int(building.name) % 2 == 0:
|
if int(building.name) % 2 == 0:
|
||||||
par_city.add_city_object(copy.deepcopy(building))
|
even_city.add_city_object(copy.deepcopy(building))
|
||||||
else:
|
else:
|
||||||
odd_city.add_city_object(copy.deepcopy(building))
|
odd_city.add_city_object(copy.deepcopy(building))
|
||||||
self.assertEqual(8, len(odd_city.buildings), 'Wrong number of odd buildings')
|
self.assertEqual(8, len(odd_city.buildings), 'Wrong number of odd buildings')
|
||||||
self.assertEqual(9, len(par_city.buildings), 'Wrong number of par buildings')
|
self.assertEqual(9, len(even_city.buildings), 'Wrong number of par buildings')
|
||||||
merged_city = odd_city.merge(par_city)
|
merged_city = odd_city.merge(even_city)
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
||||||
merged_city = par_city.merge(odd_city)
|
merged_city = even_city.merge(odd_city)
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
||||||
merged_city = full_city.merge(odd_city).merge(par_city)
|
merged_city = full_city.merge(odd_city).merge(even_city)
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
||||||
|
|
||||||
def test_merge_with_radiation(self):
|
def test_merge_with_radiation(self):
|
||||||
|
@ -57,46 +57,53 @@ class TestCityMerge(TestCase):
|
||||||
file_path = Path('./tests_data/test.geojson').resolve()
|
file_path = Path('./tests_data/test.geojson').resolve()
|
||||||
output_path = Path('./tests_outputs/')
|
output_path = Path('./tests_outputs/')
|
||||||
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
||||||
par_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
even_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
||||||
for building in full_city.buildings:
|
for building in full_city.buildings:
|
||||||
if int(building.name) % 2 == 0:
|
if int(building.name) % 2 == 0:
|
||||||
par_city.add_city_object(copy.deepcopy(building))
|
even_city.add_city_object(copy.deepcopy(building))
|
||||||
ExportsFactory('sra', full_city, output_path).export()
|
ExportsFactory('sra', full_city, output_path).export()
|
||||||
sra_file = str((output_path / f'{full_city.name}_sra.xml').resolve())
|
sra_file = str((output_path / f'{full_city.name}_sra.xml').resolve())
|
||||||
subprocess.run([sra, sra_file], stdout=subprocess.DEVNULL)
|
subprocess.run([sra, sra_file], stdout=subprocess.DEVNULL)
|
||||||
ResultFactory('sra', full_city, output_path).enrich()
|
ResultFactory('sra', full_city, output_path).enrich()
|
||||||
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
||||||
merged_city = full_city.merge(par_city)
|
merged_city = full_city.merge(even_city)
|
||||||
merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
|
||||||
self.assertEqual(447383461, merged_city_building_total_radiation)
|
|
||||||
merged_city = par_city.merge(full_city)
|
|
||||||
merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
|
||||||
self.assertEqual(447383461, merged_city_building_total_radiation)
|
|
||||||
|
|
||||||
for building in par_city.buildings:
|
full_city_building_total_radiation = 0
|
||||||
|
for building in merged_city.buildings:
|
||||||
|
for surface in building.surfaces:
|
||||||
|
if surface.global_irradiance:
|
||||||
|
full_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
|
|
||||||
|
merged_city_building_total_radiation = 0
|
||||||
|
for building in merged_city.buildings:
|
||||||
|
for surface in building.surfaces:
|
||||||
|
if surface.global_irradiance:
|
||||||
|
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
|
self.assertEqual(full_city_building_total_radiation, merged_city_building_total_radiation)
|
||||||
|
|
||||||
|
merged_city = even_city.merge(full_city)
|
||||||
|
merged_city_building_total_radiation = 0
|
||||||
|
for building in merged_city.buildings:
|
||||||
|
for surface in building.surfaces:
|
||||||
|
if surface.global_irradiance:
|
||||||
|
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
|
self.assertEqual(full_city_building_total_radiation, merged_city_building_total_radiation)
|
||||||
|
|
||||||
|
for building in even_city.buildings:
|
||||||
for surface in building.surfaces:
|
for surface in building.surfaces:
|
||||||
surface.global_irradiance[cte.YEAR] = pd.DataFrame([3], columns=['sra_mockup_value'])
|
surface.global_irradiance[cte.YEAR] = pd.DataFrame([3], columns=['sra_mockup_value'])
|
||||||
|
|
||||||
merged_city = full_city.merge(par_city)
|
merged_city = full_city.merge(even_city)
|
||||||
merged_city_building_total_radiation = 0
|
first_merged_city_building_total_radiation = 0
|
||||||
for building in merged_city.buildings:
|
for building in merged_city.buildings:
|
||||||
for surface in building.surfaces:
|
for surface in building.surfaces:
|
||||||
if surface.global_irradiance:
|
if surface.global_irradiance:
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
first_merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
self.assertEqual(202699159, merged_city_building_total_radiation)
|
merged_city = even_city.merge(full_city)
|
||||||
merged_city = par_city.merge(full_city)
|
second_merged_city_building_total_radiation = 0
|
||||||
merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
for building in merged_city.buildings:
|
||||||
for surface in building.surfaces:
|
for surface in building.surfaces:
|
||||||
if surface.global_irradiance:
|
if surface.global_irradiance:
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
second_merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
self.assertEqual(202699159, merged_city_building_total_radiation)
|
self.assertEqual(first_merged_city_building_total_radiation, second_merged_city_building_total_radiation)
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from hub.catalog_factories.costs_catalog_factory import CostCatalogFactory
|
from hub.catalog_factories.costs_catalog_factory import CostsCatalogFactory
|
||||||
|
|
||||||
|
|
||||||
class TestCostsCatalog(TestCase):
|
class TestCostsCatalog(TestCase):
|
||||||
|
|
||||||
def test_costs_catalog(self):
|
def test_costs_catalog(self):
|
||||||
catalog = CostCatalogFactory('montreal_custom').catalog
|
catalog = CostsCatalogFactory('montreal_custom').catalog
|
||||||
catalog_categories = catalog.names()
|
catalog_categories = catalog.names()
|
||||||
self.assertIsNotNone(catalog, 'catalog is none')
|
self.assertIsNotNone(catalog, 'catalog is none')
|
||||||
content = catalog.entries()
|
content = catalog.entries()
|
||||||
|
|
|
@ -5,7 +5,7 @@ Copyright © 2022 Concordia CERC group
|
||||||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||||
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
"""
|
"""
|
||||||
|
import logging.handlers
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
@ -66,7 +66,12 @@ class TestExports(TestCase):
|
||||||
|
|
||||||
def _export(self, export_type, from_pickle=False):
|
def _export(self, export_type, from_pickle=False):
|
||||||
self._complete_city = self._get_complete_city(from_pickle)
|
self._complete_city = self._get_complete_city(from_pickle)
|
||||||
ExportsFactory(export_type, self._complete_city, self._output_path).export()
|
try:
|
||||||
|
ExportsFactory(export_type, self._complete_city, self._output_path).export()
|
||||||
|
except ValueError as err:
|
||||||
|
if export_type != 'stl':
|
||||||
|
logging.warning('No backend export for STL test, skipped')
|
||||||
|
raise err
|
||||||
|
|
||||||
def _export_building_energy(self, export_type, from_pickle=False):
|
def _export_building_energy(self, export_type, from_pickle=False):
|
||||||
self._complete_city = self._get_complete_city(from_pickle)
|
self._complete_city = self._get_complete_city(from_pickle)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user