-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(properties): Add ModelIDAICEProperties with validation for IDAICE
- Loading branch information
1 parent
6f32b68
commit 0e81434
Showing
6 changed files
with
192 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
from .writer import model_to_idm | ||
from honeybee.model import Model | ||
# coding=utf-8 | ||
# import all of the modules for writing geometry to IDAICE | ||
from honeybee.properties import ModelProperties | ||
|
||
Model.to_idm = model_to_idm | ||
from .properties.model import ModelIDAICEProperties | ||
|
||
# set a hidden ies attribute on each core geometry Property class to None | ||
# define methods to produce ies property instances on each Property instance | ||
ModelProperties._idaice = None | ||
|
||
|
||
def model_idaice_properties(self): | ||
if self._idaice is None: | ||
self._idaice = ModelIDAICEProperties(self.host) | ||
return self._idaice | ||
|
||
|
||
# add IDAICE property methods to the Properties classes | ||
ModelProperties.idaice = property(model_idaice_properties) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""honeybee-ies properties.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# coding=utf-8 | ||
"""Model IDAICE Properties.""" | ||
|
||
|
||
class ModelIDAICEProperties(object): | ||
"""IDAICE Properties for Honeybee Model. | ||
Args: | ||
host: A honeybee_core Model object that hosts these properties. | ||
Properties: | ||
* host | ||
""" | ||
|
||
def __init__(self, host): | ||
"""Initialize ModelIDAICEProperties.""" | ||
self._host = host | ||
|
||
@property | ||
def host(self): | ||
"""Get the Model object hosting these properties.""" | ||
return self._host | ||
|
||
def check_for_extension(self, raise_exception=True, detailed=False): | ||
"""Check that the Model is valid for IDAICE simulation. | ||
This process includes all relevant honeybee-core checks as well as checks | ||
that apply only for IDAICE. | ||
Args: | ||
raise_exception: Boolean to note whether a ValueError should be raised | ||
if any errors are found. If False, this method will simply | ||
return a text string with all errors that were found. (Default: True). | ||
detailed: Boolean for whether the returned object is a detailed list of | ||
dicts with error info or a string with a message. (Default: False). | ||
Returns: | ||
A text string with all errors that were found or a list if detailed is True. | ||
This string (or list) will be empty if no errors were found. | ||
""" | ||
# set up defaults to ensure the method runs correctly | ||
detailed = False if raise_exception else detailed | ||
msgs = [] | ||
tol = self.host.tolerance | ||
ang_tol = self.host.angle_tolerance | ||
|
||
# perform checks for duplicate identifiers, which might mess with other checks | ||
msgs.append(self.host.check_all_duplicate_identifiers(False, detailed)) | ||
|
||
# perform several checks for the Honeybee schema geometry rules | ||
msgs.append(self.host.check_planar(tol, False, detailed)) | ||
msgs.append(self.host.check_self_intersecting(tol, False, detailed)) | ||
msgs.append(self.host.check_degenerate_rooms(tol, False, detailed)) | ||
|
||
# perform geometry checks related to parent-child relationships | ||
msgs.append(self.host.check_sub_faces_valid(tol, ang_tol, False, detailed)) | ||
msgs.append(self.host.check_sub_faces_overlapping(tol, False, detailed)) | ||
msgs.append(self.host.check_upside_down_faces(ang_tol, False, detailed)) | ||
msgs.append(self.host.check_rooms_solid(tol, ang_tol, False, detailed)) | ||
|
||
# perform checks related to adjacency relationships | ||
msgs.append(self.host.check_room_volume_collisions(tol, False, detailed)) | ||
|
||
# output a final report of errors or raise an exception | ||
full_msgs = [msg for msg in msgs if msg] | ||
if detailed: | ||
return [m for msg in full_msgs for m in msg] | ||
full_msg = '\n'.join(full_msgs) | ||
if raise_exception and len(full_msgs) != 0: | ||
raise ValueError(full_msg) | ||
return full_msg | ||
|
||
def to_dict(self): | ||
"""Return Model IDAICE properties as a dictionary.""" | ||
return {'ies': {'type': 'ModelIDAICEProperties'}} | ||
|
||
def apply_properties_from_dict(self, data): | ||
"""Apply the energy properties of a dictionary to the host Model of this object. | ||
Args: | ||
data: A dictionary representation of an entire honeybee-core Model. | ||
Note that this dictionary must have ModelIDAICEProperties in order | ||
for this method to successfully apply the IDAICE properties. | ||
""" | ||
assert 'idaice' in data['properties'], \ | ||
'Dictionary possesses no ModelIDAICEProperties.' | ||
|
||
def ToString(self): | ||
return self.__repr__() | ||
|
||
def __repr__(self): | ||
return 'Model IDAICE Properties: [host: {}]'.format(self.host.display_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import pathlib | ||
from honeybee.model import Model | ||
from honeybee_idaice.writer import model_to_idm | ||
|
||
|
||
def test_model(): | ||
in_file = './tests/assets/revit_sample_model_wall_finish.hbjson' | ||
out_folder = pathlib.Path('./tests/assets/temp') | ||
out_folder.mkdir(parents=True, exist_ok=True) | ||
out_folder.mkdir(parents=True, exist_ok=True) | ||
model = Model.from_hbjson(in_file) | ||
outf = model.to_idm(out_folder.as_posix(), name='revit_sample_model_wall_finish') | ||
outf = model_to_idm( | ||
model, out_folder.as_posix(), | ||
name='revit_sample_model_wall_finish') | ||
assert outf.exists() |