Code style and remove old test and un-used files

This commit is contained in:
Guille Gutierrez 2023-05-18 10:35:05 -04:00
parent 84ae32bcdb
commit c72f30a476
15 changed files with 41 additions and 545 deletions

View File

@ -1,71 +0,0 @@
"""
CityLayersTest
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Concordia CERC group
Project Coder: Milad Aghamohamadnia --- milad.aghamohamadnia@concordia.ca
"""
from unittest import TestCase
import json
import os
import time
import uuid
from pathlib import Path
from hub.imports.geometry_factory import GeometryFactory
from hub.imports.usage_factory import UsageFactory
from hub.imports.construction_factory import ConstructionFactory
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
import pandas as pd
from geopandas import GeoDataFrame
from shapely.geometry import Polygon
class CityLayerTest(TestCase):
@staticmethod
def _prepare_buildings(bldgs_group):
target_json = bldgs_group['target']
adjacent_json = bldgs_group['adjacent']
target_buildings = [f"building_{target_json['index']}"]
adjacent_buildings = [f"building_{el}" for el in adjacent_json['Ids']]
target_dict = [dict(
name=f"building_{target_json['index']}",
height=target_json['height_max'],
idx=target_json['index'],
uid=target_json['uid'],
year_built=2005,
# year_built= 2005 if target_json['year_built']==9999 else target_json['year_built'],
coords=target_json['coords'],
function="residential",
# function= "residential" if target_json['year_built']>2000 else "industry",
)]
adjacent_dict = [dict(
name=f"building_{el['index']}",
height=el['height_max'],
idx=el['index'],
uid=el['uid'],
year_built=2005,
# year_built=2005 if el['year_built']==9999 else el['year_built'],
coords=el['geom']['coordinates'],
function="residential",
# function= "residential" if el['year_built']>2000 else "industry",
) for el in adjacent_json['data']]
df = pd.DataFrame(target_dict + adjacent_dict)
geometries = [Polygon(row['coords'][0]) for ix, row in df.iterrows()]
gdf = GeoDataFrame(df, crs="EPSG:4326", geometry=geometries)
gdf = gdf.set_crs('EPSG:4326')
gdf = gdf.to_crs('EPSG:26911')
return gdf, target_buildings, adjacent_buildings
def _genidf(self, bldgs_group):
buildings_df, target_buildings, adjacent_buildings = self._prepare_buildings(bldgs_group)
output_path = (Path(__file__).parent / 'tests_outputs').resolve()
city = GeometryFactory('gpandas', data_frame=buildings_df).city
ConstructionFactory('nrel', city).enrich()
UsageFactory('comnet', city).enrich()
EnergyBuildingsExportsFactory('idf', city, output_path, target_buildings=target_buildings).export_debug()
filepath = os.path.join(output_path, city.name + ".idf")
newfilepath = filepath[:-4] + "_" + uuid.uuid4().hex[:10] + ".idf"
os.rename(filepath, newfilepath)
return newfilepath

View File

@ -4,13 +4,13 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez Guillermo.GutierrezMorote@concordia.ca
"""
from pathlib import Path
from unittest import TestCase
from hub.imports.geometry_factory import GeometryFactory
import platform
from hub.exports.exports_factory import ExportsFactory
import subprocess
from pathlib import Path
from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
from unittest import TestCase
from hub.exports.exports_factory import ExportsFactory
from hub.imports.geometry_factory import GeometryFactory
from hub.imports.results_factory import ResultFactory
@ -60,5 +60,11 @@ class TestCityMerge(TestCase):
self.assertEqual(round(merged_city.buildings[1].surfaces[0].global_irradiance['year'].iloc[0]), 254)
self.assertEqual(merged_city.buildings[0].surfaces[0].global_irradiance, {})
self.assertEqual(merged_city.buildings[0].surfaces[2].global_irradiance, {})
self.assertEqual(city_one.buildings[0].surfaces[0].global_irradiance, merged_city.buildings[0].surfaces[0].global_irradiance)
self.assertEqual(city_two.buildings[0].surfaces[0].global_irradiance, merged_city.buildings[1].surfaces[0].global_irradiance)
self.assertEqual(
city_one.buildings[0].surfaces[0].global_irradiance,
merged_city.buildings[0].surfaces[0].global_irradiance
)
self.assertEqual(
city_two.buildings[0].surfaces[0].global_irradiance,
merged_city.buildings[1].surfaces[0].global_irradiance
)

View File

@ -51,4 +51,3 @@ class TestConstructionCatalog(TestCase):
with self.assertRaises(IndexError):
catalog.get_entry('unknown')

View File

@ -12,7 +12,7 @@ from hub.city_model_structure.energy_systems.air_source_hp import AirSourceHP
from hub.exports.energy_systems_factory import EnergySystemsExportFactory
import os
# User defined paramenters
# User defined parameters
user_input = {
'StartYear': 2020,
'EndYear': 2021,

View File

@ -5,28 +5,13 @@ Copyright © 2022 Concordia CERC group
Project Coder Peter Yefi peteryefi@gmail.com
"""
from unittest import TestCase
from hub.imports.geometry_factory import GeometryFactory
from hub.imports.energy_systems_factory import EnergySystemsFactory
from hub.city_model_structure.energy_systems.water_to_water_hp import WaterToWaterHP
from hub.exports.energy_systems_factory import EnergySystemsExportFactory
import pandas as pd
import os
# User defined paramenters
user_input = {
'StartYear': 2020,
'EndYear': 2021,
'MaximumHPEnergyInput': 8000,
'HoursOfStorageAtMaxDemand': 1,
'BuildingSuppTemp': 40,
'TemperatureDifference': 15,
'FuelLHV': 47100,
'FuelPrice': 0.12,
'FuelEF': 1887,
'FuelDensity': 0.717,
'HPSupTemp': 60
}
from hub.city_model_structure.energy_systems.water_to_water_hp import WaterToWaterHP
from hub.exports.energy_systems_factory import EnergySystemsExportFactory
from hub.imports.energy_systems_factory import EnergySystemsFactory
from hub.imports.geometry_factory import GeometryFactory
class TestEnergySystemsFactory(TestCase):
@ -51,7 +36,7 @@ class TestEnergySystemsFactory(TestCase):
self.assertEqual(self._city.energy_systems[2].water_to_water_hp.model, 'ClimateMaster 335 kW')
def test_water_to_water_heat_pump_export(self):
# User defined paramenters
# User defined parameters
user_input = {
'StartYear': 2020,
'EndYear': 2021,

View File

@ -116,4 +116,3 @@ class TestExports(TestCase):
except Exception:
self.fail("Idf ExportsFactory raised ExceptionType unexpectedly!")

View File

@ -171,7 +171,3 @@ class TestGeometryFactory(TestCase):
self.assertEqual('3', city.city_object('2').neighbours[1].name)
self.assertEqual('1', city.city_object('3').neighbours[0].name)
self.assertEqual('2', city.city_object('3').neighbours[1].name)

View File

@ -35,4 +35,3 @@ class TestGreeneryCatalog(TestCase):
self.assertTrue(len(catalog.entries().vegetations) == 4)
self.assertTrue(len(catalog.entries().plants) == 14)
self.assertTrue(len(catalog.entries().soils) == 6)

View File

@ -5,17 +5,17 @@ Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
import csv
import hub.helpers.constants as cte
from unittest import TestCase
import hub.helpers.constants as cte
from hub.city_model_structure.greenery.plant import Plant
from hub.city_model_structure.greenery.soil import Soil
from hub.city_model_structure.greenery.vegetation import Vegetation
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
from hub.imports.construction_factory import ConstructionFactory
from hub.imports.geometry_factory import GeometryFactory
from hub.imports.usage_factory import UsageFactory
from hub.imports.construction_factory import ConstructionFactory
from hub.imports.weather_factory import WeatherFactory
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
from hub.city_model_structure.greenery.vegetation import Vegetation
from hub.city_model_structure.greenery.soil import Soil
from hub.city_model_structure.greenery.plant import Plant
class GreeneryInIdf(TestCase):
@ -76,4 +76,3 @@ class GreeneryInIdf(TestCase):
WeatherFactory('epw', city, file_name='CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').enrich()
_idf = EnergyBuildingsExportsFactory('idf', city, output_path).export()
self.assertIsNotNone(_idf)

View File

@ -12,7 +12,7 @@ from hub.imports.results_factory import ResultFactory
import os
from pandas.core.series import Series
# User defined paramenters
# User defined parameters
user_input = {
'StartYear': 2020,
'EndYear': 2021,

View File

@ -140,8 +140,10 @@ class TestExports(TestCase):
self.assertIsNotNone(usage.thermal_control, f'usage zone {usage.name} thermal_control is none')
self.assertIsNotNone(usage.hours_day, f'usage zone {usage.name} hours_day is none')
self.assertIsNotNone(usage.days_year, f'usage zone {usage.name} days_year is none')
self.assertIsNotNone(usage.mechanical_air_change, f'usage zone {usage.name} '
f'mechanical_air_change is none')
self.assertIsNotNone(
usage.mechanical_air_change,
f'usage zone {usage.name} mechanical_air_change is none'
)
# export files
try:
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, self._output_path).export()

View File

@ -1,55 +0,0 @@
"""
Building test
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Atiya atiya.atiya@mail.concordia.ca
"""
from pathlib import Path
from unittest import TestCase
from hub.imports.geometry_factory import GeometryFactory
from hub.imports.life_cycle_assessment_factory import LifeCycleAssessment
class TestLifeCycleAssessment(TestCase):
"""
TestBuilding TestCase 1
"""
def setUp(self) -> None:
"""
Test setup
:return: None
"""
self._city_gml = None
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
def test_fuel(self):
city_file = "tests_data/C40_Final.gml"
city = GeometryFactory('citygml', path=city_file).city
LifeCycleAssessment('fuel', city).enrich()
for fuel in city.fuels:
self.assertTrue(len(city.fuels) > 0)
def test_vehicle(self):
city_file = "tests_data/C40_Final.gml"
city = GeometryFactory('citygml', path=city_file).city
LifeCycleAssessment('vehicle', city).enrich()
for vehicle in city.vehicles:
self.assertTrue(len(city.vehicles) > 0)
def test_machine(self):
city_file = "tests_data/C40_Final.gml"
city = GeometryFactory('citygml', path=city_file).city
LifeCycleAssessment('machine', city).enrich()
for machine in city.machines:
self.assertTrue(len(city.machines) > 0)
def test_material(self):
city_file = "tests_data/C40_Final.gml"
city = GeometryFactory('citygml', path=city_file).city
LifeCycleAssessment('material', city).enrich()
for material in city.lca_materials:
self.assertTrue(len(city.lca_materials) > 0)

View File

@ -109,7 +109,3 @@ class TestResultsImport(TestCase):
expected_monthly['expected'],
check_names=False
)

View File

@ -76,8 +76,9 @@ class TestSystemsFactory(TestCase):
energy_systems_connection = self._city.energy_systems_connection_table
for building in self._city.buildings:
_building_energy_systems = []
energy_systems = energy_systems_connection['Energy System Type']\
.where(energy_systems_connection['Building'] == building.name)
energy_systems = energy_systems_connection['Energy System Type'].where(
energy_systems_connection['Building'] == building.name
)
for energy_system in energy_systems:
_generic_building_energy_systems = self._city.generic_energy_systems[energy_system]
for _generic_building_energy_system in _generic_building_energy_systems:
@ -85,14 +86,17 @@ class TestSystemsFactory(TestCase):
_building_energy_equipment.demand_types = _generic_building_energy_system.demand_types
_building_distribution_system = DistributionSystem()
_building_distribution_system.generic_distribution_system = \
_building_distribution_system.generic_distribution_system = (
copy.deepcopy(_generic_building_energy_system.distribution_system)
)
_building_emission_system = EmissionSystem()
_building_emission_system.generic_emission_system = \
_building_emission_system.generic_emission_system = (
copy.deepcopy(_generic_building_energy_system.emission_system)
)
_building_generation_system = GenerationSystem()
_building_generation_system.generic_generation_system = \
_building_generation_system.generic_generation_system = (
copy.deepcopy(_generic_building_energy_system.generation_system)
)
if cte.HEATING in _building_energy_equipment.demand_types:
_building_generation_system.heat_power = building.heating_peak_load[cte.YEAR]['heating peak loads'][0]
if cte.COOLING in _building_energy_equipment.demand_types:

View File

@ -1,363 +0,0 @@
{
"target": {
"layerName": "public.building_footprint_year_built_height_max",
"height_max": 13,
"index": 287809,
"year_built": 1952,
"uid": 1039258,
"centroid": [
-73.59838038682938,
45.493163447971085
],
"area": 119.59674983363819,
"coords": [
[
[
-73.59848499298096,
45.49319823193981
],
[
-73.59841525554657,
45.493239596593924
],
[
-73.5982757806778,
45.49313054425838
],
[
-73.59834551811218,
45.49308541909225
],
[
-73.59848499298096,
45.49319823193981
]
]
]
},
"adjacent": {
"data": [
{
"__typename": "building_footprint_year_built_height_max",
"index": 1586,
"height_max": 12,
"geom": {
"type": "Polygon",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"coordinates": [
[
[
-73.59812,
45.493495
],
[
-73.598085,
45.493525
],
[
-73.598017,
45.493487
],
[
-73.59812,
45.493398
],
[
-73.59821,
45.493449
],
[
-73.598142,
45.493508
],
[
-73.59812,
45.493495
]
]
]
},
"year_built": 1929,
"uid": 1039256
},
{
"__typename": "building_footprint_year_built_height_max",
"index": 11964,
"height_max": 11,
"geom": {
"type": "Polygon",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"coordinates": [
[
[
-73.5984992790639,
45.4929564079915
],
[
-73.598462,
45.493019
],
[
-73.598313,
45.492975
],
[
-73.5983570524121,
45.4929010354563
],
[
-73.5984992790639,
45.4929564079915
]
]
]
},
"year_built": 1965,
"uid": 1039090
},
{
"__typename": "building_footprint_year_built_height_max",
"index": 11965,
"height_max": 11,
"geom": {
"type": "Polygon",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"coordinates": [
[
[
-73.5983570524121,
45.4929010354563
],
[
-73.598394,
45.492839
],
[
-73.598543,
45.492883
],
[
-73.5984992790639,
45.4929564079915
],
[
-73.5983570524121,
45.4929010354563
]
]
]
},
"year_built": 1965,
"uid": 1039088
},
{
"__typename": "building_footprint_year_built_height_max",
"index": 252931,
"height_max": 22,
"geom": {
"type": "Polygon",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"coordinates": [
[
[
-73.598625,
45.492713
],
[
-73.598668,
45.49268
],
[
-73.598755,
45.492735
],
[
-73.598659,
45.49281
],
[
-73.598521,
45.492723
],
[
-73.598575,
45.492682
],
[
-73.598625,
45.492713
]
]
]
},
"year_built": 1983,
"uid": 1039086
},
{
"__typename": "building_footprint_year_built_height_max",
"index": 275748,
"height_max": 12,
"geom": {
"type": "Polygon",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"coordinates": [
[
[
-73.597909,
45.493307
],
[
-73.598014,
45.493349
],
[
-73.597928,
45.493454
],
[
-73.597823,
45.493412
],
[
-73.597909,
45.493307
]
]
]
},
"year_built": 1929,
"uid": 1039091
},
{
"__typename": "building_footprint_year_built_height_max",
"index": 308721,
"height_max": 15,
"geom": {
"type": "Polygon",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"coordinates": [
[
[
-73.598655,
45.493348
],
[
-73.598681,
45.493326
],
[
-73.59876,
45.493373
],
[
-73.598652,
45.493462
],
[
-73.598595,
45.493427
],
[
-73.598621,
45.493406
],
[
-73.598571,
45.493376
],
[
-73.598627,
45.493331
],
[
-73.598655,
45.493348
]
]
]
},
"year_built": 1950,
"uid": 1039163
},
{
"__typename": "building_footprint_year_built_height_max",
"index": 312417,
"height_max": 14,
"geom": {
"type": "Polygon",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"coordinates": [
[
[
-73.598836,
45.49324
],
[
-73.598723,
45.493191
],
[
-73.598873,
45.493021
],
[
-73.598985,
45.493069
],
[
-73.598836,
45.49324
]
]
]
},
"year_built": 1890,
"uid": 1039165
}
],
"Ids": [
1586,
11964,
11965,
252931,
275748,
308721,
312417
]
}
}