added city_layers_test.py, solved bugs in gpandas importer and idf exporter
This commit is contained in:
parent
db30870fc1
commit
23cca13359
|
@ -456,20 +456,16 @@ class Idf:
|
|||
self._idf.intersect_match()
|
||||
|
||||
def _add_shading(self, building):
|
||||
for internal_zone in building.internal_zones:
|
||||
for thermal_zone in internal_zone.thermal_zones:
|
||||
for boundary in thermal_zone.thermal_boundaries:
|
||||
shading = self._idf.newidfobject(self._SHADING, Name=f'{boundary.parent_surface.name}')
|
||||
coordinates = self._matrix_to_list(boundary.parent_surface.solid_polygon.coordinates,
|
||||
self._city.lower_corner)
|
||||
shading.setcoords(coordinates)
|
||||
solar_reflectance = 1.0 - boundary.outside_solar_absorptance
|
||||
visible_reflectance = 1.0 - boundary.outside_visible_absorptance
|
||||
self._idf.newidfobject(self._SHADING_PROPERTY,
|
||||
Shading_Surface_Name=f'{boundary.parent_surface.name}',
|
||||
Diffuse_Solar_Reflectance_of_Unglazed_Part_of_Shading_Surface=solar_reflectance,
|
||||
Diffuse_Visible_Reflectance_of_Unglazed_Part_of_Shading_Surface=visible_reflectance,
|
||||
Fraction_of_Shading_Surface_That_Is_Glazed=0)
|
||||
for surface in building.surfaces:
|
||||
shading = self._idf.newidfobject(self._SHADING, Name=f'{surface.name}')
|
||||
coordinates = self._matrix_to_list(surface.solid_polygon.coordinates,
|
||||
self._city.lower_corner)
|
||||
shading.setcoords(coordinates)
|
||||
solar_reflectance = surface.short_wave_reflectance
|
||||
self._idf.newidfobject(self._SHADING_PROPERTY,
|
||||
Shading_Surface_Name=f'{surface.name}',
|
||||
Diffuse_Solar_Reflectance_of_Unglazed_Part_of_Shading_Surface=solar_reflectance,
|
||||
Fraction_of_Shading_Surface_That_Is_Glazed=0)
|
||||
|
||||
# todo: Add properties for that name
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class SimplifiedRadiosityAlgorithm:
|
|||
for surface in building.surfaces:
|
||||
surface_dict = {
|
||||
'@id': f'{surface.id}',
|
||||
'@ShortWaveReflectance': f'{surface.swr}'
|
||||
'@ShortWaveReflectance': f'{surface.short_wave_reflectance}'
|
||||
}
|
||||
for point_index, point in enumerate(surface.perimeter_polygon.coordinates):
|
||||
point = self._correct_point(point)
|
||||
|
|
|
@ -58,8 +58,7 @@ class GPandas:
|
|||
if self._city is None:
|
||||
self._city = City(self._lower_corner, self._upper_corner, self._srs_name)
|
||||
for scene_index, bldg in self._scene.iterrows():
|
||||
geometry = bldg.geom
|
||||
polygon = ShapelyPoly(geometry['coordinates'][0])
|
||||
polygon = bldg.geometry
|
||||
height = float(bldg['height'])
|
||||
building_mesh = trimesh.creation.extrude_polygon(polygon, height)
|
||||
trimesh.repair.fill_holes(building_mesh)
|
||||
|
@ -71,7 +70,6 @@ class GPandas:
|
|||
function = cte.RESIDENTIAL
|
||||
else:
|
||||
function = cte.INDUSTRY
|
||||
|
||||
surfaces = []
|
||||
for face_index, face in enumerate(building_mesh.faces):
|
||||
points = []
|
||||
|
|
81
unittests/city_layers_test.py
Normal file
81
unittests/city_layers_test.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
"""
|
||||
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 imports.geometry_factory import GeometryFactory
|
||||
from imports.usage_factory import UsageFactory
|
||||
from imports.construction_factory import ConstructionFactory
|
||||
from 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):
|
||||
t0 = time.time()
|
||||
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"
|
||||
print(filepath)
|
||||
print(newfilepath)
|
||||
os.rename(filepath, newfilepath)
|
||||
print(f"It took {round((time.time() - t0), 0)} seconds")
|
||||
return newfilepath
|
||||
|
||||
def test_city_layers(self):
|
||||
json_path = str((Path(__file__).parent / 'tests_data' / 'city_layers.json').resolve())
|
||||
with open(json_path) as json_file:
|
||||
data = json.loads(json_file.read())
|
||||
self._genidf(data)
|
363
unittests/tests_data/city_layers.json
Normal file
363
unittests/tests_data/city_layers.json
Normal file
|
@ -0,0 +1,363 @@
|
|||
{
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user