Quality improvements

This commit is contained in:
Guille Gutierrez 2021-08-26 13:27:43 -04:00
parent 58066a45cc
commit 312a9c34be
20 changed files with 224 additions and 180 deletions

View File

@ -554,7 +554,7 @@ class Polygon:
def _order_points(edges_list):
# todo: not sure that this method works for any case -> RECHECK
points = edges_list[0]
for j in range(0, len(points)):
for _ in range(0, len(points)):
for i in range(1, len(edges_list)):
point_1 = edges_list[i][0]
point_2 = points[len(points)-1]

View File

@ -5,14 +5,11 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
"""
from pathlib import Path
from os.path import exists
from exports.formats.stl import Stl
from exports.formats.obj import Obj
from exports.formats.energy_ade import EnergyAde
from exports.formats.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from exports.formats.idf import Idf
from exports.formats.obj import Obj
from exports.formats.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from exports.formats.stl import Stl
class ExportsFactory:
@ -73,7 +70,7 @@ class ExportsFactory:
idf_data_path = (Path(__file__).parent / './formats/idf_files/').resolve()
# todo: create a get epw file function based on the city
weather_path = (Path(__file__).parent / '../data/weather/epw/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').resolve()
Idf(self._city, self._path, (idf_data_path / f'Minimal.idf'), (idf_data_path / f'Energy+.idd'), weather_path)
return Idf(self._city, self._path, (idf_data_path / 'Minimal.idf'), (idf_data_path / 'Energy+.idd'), weather_path)
@property
def _sra(self):
@ -85,10 +82,3 @@ class ExportsFactory:
:return: None
"""
return getattr(self, self._export_type, lambda: None)
def _debug_export(self):
"""
Export the city model structure to the given export type
:return: None
"""
self._idf()

View File

@ -3,21 +3,24 @@ ExportsFactory export a city into several formats
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
import xmltodict
import uuid
import datetime
from pathlib import Path
import xmltodict
import helpers.constants as cte
class EnergyAde:
"""
Export the city to citygml + energy ade
"""
def __init__(self, city, path):
self._city = city
self._path = path
self._surface_members = None
self._export()
def _export(self):
energy_ade = {
'core:CityModel': {
@ -162,7 +165,6 @@ class EnergyAde:
}
return demand
def _building_geometry(self, building, building_dic, city):
building_dic['bldg:Building']['bldg:function'] = building.function
@ -183,7 +185,6 @@ class EnergyAde:
raise NotImplementedError('Only lod 1 and 2 can be exported')
return building_dic
def _lod1(self, building, building_dic, city):
raise NotImplementedError('Only lod 1 and 2 can be exported')
@ -373,8 +374,5 @@ class EnergyAde:
}
}
}
thermal_boundaries.append(thermal_boundary_dic)
return thermal_boundaries

View File

@ -4,10 +4,12 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Soroush Samareh Abolhassani - soroush.samarehabolhassani@mail.concordia.ca
"""
from geomeppy import IDF
from pathlib import Path
class Idf:
"""
Export city to IDF
"""
_THERMOSTAT = 'HVACTEMPLATE:THERMOSTAT'
_IDEAL_LOAD_AIR_SYSTEM = 'HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM'
_SURFACE = 'BUILDINGSURFACE:DETAILED'
@ -269,10 +271,8 @@ class Idf:
for boundary in thermal_zone.thermal_boundaries:
idf_surface_type = self.idf_surfaces[boundary.surface.type]
for usage_zone in thermal_zone.usage_zones:
surface = self._idf.newidfobject(self._SURFACE, Name=f'{boundary.surface.name}',
Surface_Type=idf_surface_type, Zone_Name=usage_zone.id,
Construction_Name=boundary.construction_name)
coordinates = self._matrix_to_list(boundary.surface.solid_polygon.coordinates)
surface.setcoords(coordinates)

View File

@ -4,18 +4,23 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from exports.formats.triangular import Triangular
from pathlib import Path
from imports.geometry_factory import GeometryFactory
import trimesh.exchange.obj
from exports.formats.triangular import Triangular
from imports.geometry_factory import GeometryFactory
class Obj(Triangular):
"""
Export to obj format
"""
def __init__(self, city, path):
super().__init__(city, path, 'obj')
def to_ground_points(self):
"""
Move closer to the origin
"""
file_name_in = self._city.name + '.' + self._triangular_format
file_name_out = self._city.name + '_ground.' + self._triangular_format
file_path_in = (Path(self._path).resolve() / file_name_in).resolve()

View File

@ -3,12 +3,13 @@ Simplified Radiosity Algorithm
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guillermo.GutierrezMorote@concordia.ca
"""
from pathlib import Path
import xmltodict
class SimplifiedRadiosityAlgorithm:
"""
Export to SRA format
"""
def __init__(self, city, file_name, begin_month=1, begin_day=1, end_month=12, end_day=31):
self._file_name = file_name
self._begin_month = begin_month
@ -83,7 +84,5 @@ class SimplifiedRadiosityAlgorithm:
}
}
}
with open(self._file_name, "w") as file:
file.write(xmltodict.unparse(sra, pretty=True, short_empty_elements=True))
return

View File

@ -8,5 +8,8 @@ from exports.formats.triangular import Triangular
class Stl(Triangular):
"""
Export to STL
"""
def __init__(self, city, path):
super().__init__(city, path, 'stl', write_mode='wb')

View File

@ -8,6 +8,9 @@ from trimesh import Trimesh
class Triangular:
"""
Superclass to export to triangular format (STL or OBJ)
"""
def __init__(self, city, path, triangular_format, write_mode='w'):
self._city = city
self._path = path

View File

@ -1,3 +1,10 @@
"""
Constant module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
# universal constants
KELVIN = 273.15
@ -48,4 +55,3 @@ RETAIL = 'retail'
HALL = 'hall'
RESTAURANT = 'restaurant'
EDUCATION = 'education'

View File

@ -10,25 +10,50 @@ from imports.schedules_factory import SchedulesFactory
class EnrichCity:
"""
Enrich city
"""
def __init__(self, city):
self._city = city
self._enriched_city = None
self._errors = []
@property
def errors(self):
def errors(self) -> [str]:
"""
Error list
"""
return self._errors
def enriched_city(self, construction_format=None, usage_format=None, schedules_format=None):
"""
Enrich the city with the given formats
:return: City
"""
if self._enriched_city is None:
self._errors = []
print('original:', len(self._city.buildings))
if construction_format is not None:
self._enriched_city = self._construction(construction_format)
if len(self._errors) != 0:
return self._enriched_city
if usage_format is not None:
self._enriched_city = self._usage(usage_format)
if len(self._errors) != 0:
return self._enriched_city
if schedules_format is not None:
self._enriched_city = self._schedules(schedules_format)
if len(self._errors) != 0:
return self._enriched_city
self._enriched_city = self._city
return self._enriched_city
def _construction(self, construction_format):
# todo: in construction factory, when adding the values to the thermal zones,
# these are created using the just read storeys_above_ground -> review where to assign this value!!
ConstructionFactory(construction_format, self._city).enrich()
for building in self._city.buildings:
# infiltration_rate_system_off is a mandatory parameter.
# If it is not returned, extract the building from the calculation list
@ -39,8 +64,9 @@ class EnrichCity:
self._enriched_city = self._city
return self._enriched_city
print('enriched with construction:', len(self._city.buildings))
return self._city
if usage_format is not None:
def _usage(self, usage_format):
UsageFactory(usage_format, self._city).enrich()
for building in self._city.buildings:
# At least one thermal zone must be created.
@ -52,8 +78,9 @@ class EnrichCity:
self._enriched_city = self._city
return self._enriched_city
print('enriched with usage:', len(self._city.buildings))
return self._city
if schedules_format is not None:
def _schedules(self, schedules_format):
SchedulesFactory(schedules_format, self._city).enrich()
for building in self._city.buildings:
counter_schedules = 0
@ -69,6 +96,4 @@ class EnrichCity:
self._enriched_city = self._city
return self._enriched_city
print('enriched with occupancy:', len(self._city.buildings))
self._enriched_city = self._city
return self._enriched_city
return self._city

View File

@ -9,10 +9,10 @@ import numpy as np
import requests
from trimesh import Trimesh
from trimesh import intersections
from helpers.configuration_helper import ConfigurationHelper
from city_model_structure.attributes.polygon import Polygon
from city_model_structure.attributes.polyhedron import Polyhedron
from helpers.location import Location
from helpers.configuration_helper import ConfigurationHelper
class GeometryHelper:
@ -47,7 +47,6 @@ class GeometryHelper:
delta = math.fabs(a1 - a2)
return delta <= self._area_delta
def is_almost_same_surface(self, s1, s2):
"""
Compare two surfaces and decides if they are almost equal (quadratic error under delta)
@ -82,11 +81,13 @@ class GeometryHelper:
if minimum_distance > self._delta or s1.intersect(s2) is None:
return False
else:
return True
@staticmethod
def segment_list_to_trimesh(lines) -> Trimesh:
"""
Transform a list of segments into a Trimesh
"""
line_points = [lines[0][0], lines[0][1]]
lines.remove(lines[0])
while len(lines) > 1:
@ -97,7 +98,7 @@ class GeometryHelper:
line_points.append(line[1])
lines.pop(i - 1)
break
elif GeometryHelper.distance_between_points(line[1], line_points[len(line_points) - 1]) < 1e-8:
if GeometryHelper.distance_between_points(line[1], line_points[len(line_points) - 1]) < 1e-8:
line_points.append(line[0])
lines.pop(i - 1)
break
@ -161,17 +162,19 @@ class GeometryHelper:
return [trimesh_1, trimesh_2]
@staticmethod
def get_location(latitude, longitude):
def get_location(latitude, longitude) -> Location:
"""
Get Location from latitude and longitude
"""
url = 'https://nominatim.openstreetmap.org/reverse?lat={latitude}&lon={longitude}&format=json'
response = requests.get(url.format(latitude=latitude, longitude=longitude))
if response.status_code != 200:
# This means something went wrong.
raise Exception('GET /tasks/ {}'.format(response.status_code))
else:
response = response.json()
# todo: this is wrong, remove in the future
city = 'new_york_city'
country = 'us'
city = 'Unknown'
country = 'ca'
if 'city' in response['address']:
city = response['address']['city']
if 'country_code' in response['address']:

View File

@ -1,12 +1,29 @@
"""
Location module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
class Location:
"""
Location
"""
def __init__(self, country, city):
self._country = country
self._city = city
@property
def city(self):
"""
City name
"""
return self._city
@property
def country(self):
"""
Country code
"""
return self._country

View File

@ -3,9 +3,9 @@ monthly_to_hourly_demand module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import calendar as cal
import pandas as pd
from city_model_structure.building_demand.occupants import Occupants
import calendar as cal
import helpers.constants as cte
@ -44,7 +44,7 @@ class MonthlyToHourlyDemand:
for month in range(1, 13):
temp_grad_month = 0
month_range = cal.monthrange(2015, month)[1]
for day in range(1, month_range+1):
for _ in range(1, month_range+1):
external_temp_med = 0
for hour in range(0, 24):
external_temp_med += external_temp[key][i]/24
@ -66,10 +66,8 @@ class MonthlyToHourlyDemand:
temp_grad_month += temp_grad_day[i]
i += 1
for day in range(1, month_range + 1):
for _ in range(1, month_range + 1):
for hour in range(0, 24):
# monthly_demand = self._building.heating[cte.MONTH]['INSEL'][month-1] or maybe:
# monthly_demand = self._building.heating[cte.MONTH].INSEL[month-1]
monthly_demand = self._building.heating[cte.MONTH][month-1]
if monthly_demand == 'NaN':
monthly_demand = 0
@ -104,7 +102,7 @@ class MonthlyToHourlyDemand:
for month in range(1, 13):
temp_grad_month = 0
month_range = cal.monthrange(2015, month)[1]
for day in range(1, month_range[1] + 1):
for _ in range(1, month_range[1] + 1):
for hour in range(0, 24):
if external_temp[key][i] > temp_set and cooling_schedule[month - 1] == 1:
if occupancy[hour] > 0:
@ -123,7 +121,7 @@ class MonthlyToHourlyDemand:
temp_grad_month += temp_grad_day[i]
i += 1
for day in range(1, month_range[1] + 1):
for _ in range(1, month_range[1] + 1):
for hour in range(0, 24):
# monthly_demand = self._building.heating[cte.MONTH]['INSEL'][month-1]
monthly_demand = self._building.cooling[cte.MONTH][month - 1]

View File

@ -4,11 +4,8 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import sys
from imports.construction.nrel_physics_interface import NrelPhysicsInterface
from imports.construction.helpers.construction_helper import ConstructionHelper
from city_model_structure.building_demand.layer import Layer
from city_model_structure.building_demand.material import Material
from imports.construction.nrel_physics_interface import NrelPhysicsInterface
class CaPhysicsParameters(NrelPhysicsInterface):

View File

@ -8,6 +8,9 @@ from helpers import constants as cte
class ConstructionHelper:
"""
Construction helper
"""
# NREL
function_to_nrel = {
cte.RESIDENTIAL: 'residential',

View File

@ -16,6 +16,7 @@ class NrelPhysicsInterface:
"""
NrelPhysicsInterface abstract class
"""
def __init__(self, base_path, constructions_file='us_constructions.xml',
archetypes_file='us_archetypes.xml'):
self._building_archetypes = []
@ -177,4 +178,7 @@ class NrelPhysicsInterface:
raise Exception('Construction type not found')
def enrich_buildings(self):
"""
Raise not implemented error
"""
raise NotImplementedError

View File

@ -3,9 +3,9 @@ ConstructionFactory (before PhysicsFactory) retrieve the specific construction m
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from pathlib import Path
from imports.construction.us_physics_parameters import UsPhysicsParameters
from imports.construction.ca_physics_parameters import CaPhysicsParameters
from pathlib import Path
class ConstructionFactory:
@ -23,9 +23,6 @@ class ConstructionFactory:
def _nrcan(self):
CaPhysicsParameters(self._city, self._base_path).enrich_buildings()
def _other_construction_library_format(self):
raise NotImplementedError
def enrich(self):
"""
Enrich the city with the construction information

View File

@ -20,13 +20,10 @@ class UsageFactory:
self._base_path = base_path
def _hft(self):
HftUsageParameters(self._city, self._base_path).enrich_buildings()
return HftUsageParameters(self._city, self._base_path).enrich_buildings()
def _ca(self):
CaUsageParameters(self._city, self._base_path).enrich_buildings()
def _other_usage_library_format(self):
raise Exception('Not implemented')
return CaUsageParameters(self._city, self._base_path).enrich_buildings()
def enrich(self):
"""

View File

@ -19,23 +19,16 @@ class WeatherFactory:
self._base_path = base_path
self._file_name = file_name
def _tmy3(self):
raise Exception('Not implemented')
def _tm2(self):
# Meteonorm (https://meteonorm.com/en/product/typical-years)
raise Exception('Not implemented')
def _epw(self):
# EnergyPlus Weather
# to download files: https://energyplus.net/weather
# description of the format: https://energyplus.net/sites/default/files/pdfs_v8.3.0/AuxiliaryPrograms.pdf
_path = Path(self._base_path / 'epw').resolve()
EpwWeatherParameters(self._city, _path, self._file_name)
return EpwWeatherParameters(self._city, _path, self._file_name)
def _xls(self):
name = 'ISO_52016_1_BESTEST_ClimData_2016.08.24'
XlsWeatherParameters(self._city, self._base_path, name)
return XlsWeatherParameters(self._city, self._base_path, name)
def enrich(self):
"""

View File

@ -52,3 +52,9 @@ class TestSchedulesFactory(TestCase):
city = self._get_citygml(file)
occupancy_handler = 'doe_idf'
SchedulesFactory(occupancy_handler, city).enrich()
for building in city.buildings:
for usage_zone in building.usage_zones:
for schedule in usage_zone.schedules:
print(schedule)
print(usage_zone.schedules[schedule])