honeybee-core 1.64.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- honeybee/__init__.py +23 -0
- honeybee/__main__.py +4 -0
- honeybee/_base.py +331 -0
- honeybee/_basewithshade.py +310 -0
- honeybee/_lockable.py +99 -0
- honeybee/altnumber.py +47 -0
- honeybee/aperture.py +997 -0
- honeybee/boundarycondition.py +358 -0
- honeybee/checkdup.py +173 -0
- honeybee/cli/__init__.py +118 -0
- honeybee/cli/compare.py +132 -0
- honeybee/cli/create.py +265 -0
- honeybee/cli/edit.py +559 -0
- honeybee/cli/lib.py +103 -0
- honeybee/cli/setconfig.py +43 -0
- honeybee/cli/validate.py +224 -0
- honeybee/colorobj.py +363 -0
- honeybee/config.json +5 -0
- honeybee/config.py +347 -0
- honeybee/dictutil.py +54 -0
- honeybee/door.py +746 -0
- honeybee/extensionutil.py +208 -0
- honeybee/face.py +2360 -0
- honeybee/facetype.py +153 -0
- honeybee/logutil.py +79 -0
- honeybee/model.py +4272 -0
- honeybee/orientation.py +132 -0
- honeybee/properties.py +845 -0
- honeybee/room.py +3485 -0
- honeybee/search.py +107 -0
- honeybee/shade.py +514 -0
- honeybee/shademesh.py +362 -0
- honeybee/typing.py +498 -0
- honeybee/units.py +88 -0
- honeybee/writer/__init__.py +7 -0
- honeybee/writer/aperture.py +6 -0
- honeybee/writer/door.py +6 -0
- honeybee/writer/face.py +6 -0
- honeybee/writer/model.py +6 -0
- honeybee/writer/room.py +6 -0
- honeybee/writer/shade.py +6 -0
- honeybee/writer/shademesh.py +6 -0
- honeybee_core-1.64.12.dist-info/METADATA +94 -0
- honeybee_core-1.64.12.dist-info/RECORD +48 -0
- honeybee_core-1.64.12.dist-info/WHEEL +5 -0
- honeybee_core-1.64.12.dist-info/entry_points.txt +2 -0
- honeybee_core-1.64.12.dist-info/licenses/LICENSE +661 -0
- honeybee_core-1.64.12.dist-info/top_level.txt +1 -0
honeybee/search.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Collection of methods for searching for keywords and filtering lists by keywords.
|
|
2
|
+
This module also included methods to get nested attributes of objects.
|
|
3
|
+
|
|
4
|
+
This is useful for cases like the following:
|
|
5
|
+
|
|
6
|
+
* Searching through the honeybee-radiance modifier library.
|
|
7
|
+
* Searching through the honeybee-energy material, construction, schedule,
|
|
8
|
+
constructionset, or programtype libraries.
|
|
9
|
+
* Searching through EnergyPlus IDD or RDD to find possible output variables
|
|
10
|
+
to request form the simulation.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def filter_array_by_keywords(array, keywords, parse_phrases=True):
|
|
15
|
+
"""Filter an array of strings to get only those containing the given keywords.
|
|
16
|
+
|
|
17
|
+
This method is case insensitive, allowing the searching of keywords across
|
|
18
|
+
different cases of letters.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
array: An array of strings which will be filtered to get only those containing
|
|
22
|
+
the given keywords.
|
|
23
|
+
keywords: An array of strings representing keywords.
|
|
24
|
+
parse_phrases: If True, this method will automatically parse any strings of
|
|
25
|
+
multiple keywords (separated by spaces) into separate keywords for
|
|
26
|
+
searching. This results in a greater likelihood that someone finds what
|
|
27
|
+
they are searching for in large arrays but it may not be appropriate for
|
|
28
|
+
all cases. You may want to set it to False when you are searching for a
|
|
29
|
+
specific phrase that includes spaces. Default: True.
|
|
30
|
+
"""
|
|
31
|
+
# split any keywords separated by spaces
|
|
32
|
+
if parse_phrases:
|
|
33
|
+
keywords = [kw for words in keywords for kw in words.upper().split()]
|
|
34
|
+
else:
|
|
35
|
+
keywords = [kw.upper() for kw in keywords]
|
|
36
|
+
|
|
37
|
+
# filter the input array
|
|
38
|
+
return [item for item in array if any_keywords_in_string(item.upper(), keywords)]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def any_keywords_in_string(name, keywords):
|
|
42
|
+
"""Check whether any keywords in an array exist within a given string.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
name: A string which will be tested for whether it possesses any of the keywords.
|
|
46
|
+
keywords: An array of strings representing keywords, which will be searched for
|
|
47
|
+
in the name.
|
|
48
|
+
"""
|
|
49
|
+
return all(kw in name for kw in keywords)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_attr_nested(obj_instance, attr_name, decimal_count=None, cast_to_str=True):
|
|
53
|
+
"""Get the attribute of an object while allowing the request of nested attributes.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
obj_instance: An instance of a Python object. Typically, this is a honeybee
|
|
57
|
+
object like a Model, Room, Face, Aperture, Door, or Shade.
|
|
58
|
+
attr_name: A string of an attribute that the input obj_instance should have.
|
|
59
|
+
This can have '.' that separate the nested attributes from one another.
|
|
60
|
+
For example, 'properties.energy.construction'.
|
|
61
|
+
decimal_count: An optional integer to be used to round the property to a
|
|
62
|
+
number of decimal places if it is a float. (Default: None).
|
|
63
|
+
cast_to_str: Boolean to note whether attributes with a type other than
|
|
64
|
+
float should be cast to strings. If False, the attribute will be
|
|
65
|
+
returned with the original object type. (Default: True).
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
A string or number for tha attribute assigned ot the obj_instance. If the
|
|
69
|
+
input attr_name is a valid attribute for the object but None is assigned,
|
|
70
|
+
the output will be 'None'. If the input attr_name is not valid for
|
|
71
|
+
the input object, 'N/A' will be returned.
|
|
72
|
+
"""
|
|
73
|
+
if '.' in attr_name: # nested attribute
|
|
74
|
+
attributes = attr_name.split('.') # get all the sub-attributes
|
|
75
|
+
current_obj = obj_instance
|
|
76
|
+
try:
|
|
77
|
+
for attribute in attributes:
|
|
78
|
+
if current_obj is None:
|
|
79
|
+
raise AttributeError
|
|
80
|
+
elif isinstance(current_obj, dict):
|
|
81
|
+
current_obj = current_obj.get(attribute, None)
|
|
82
|
+
else:
|
|
83
|
+
current_obj = getattr(current_obj, attribute)
|
|
84
|
+
if isinstance(current_obj, float) and decimal_count:
|
|
85
|
+
val = round(current_obj, decimal_count)
|
|
86
|
+
return str(val) if cast_to_str else val
|
|
87
|
+
elif callable(current_obj):
|
|
88
|
+
return str(current_obj()) if cast_to_str else current_obj()
|
|
89
|
+
else:
|
|
90
|
+
return str(current_obj) if cast_to_str else current_obj
|
|
91
|
+
except AttributeError as e:
|
|
92
|
+
if 'NoneType' in str(e): # it's a valid attribute but it's not assigned
|
|
93
|
+
return 'None'
|
|
94
|
+
else: # it's not a valid attribute
|
|
95
|
+
return 'N/A'
|
|
96
|
+
else: # honeybee-core attribute
|
|
97
|
+
try:
|
|
98
|
+
current_obj = getattr(obj_instance, attr_name)
|
|
99
|
+
if isinstance(current_obj, float) and decimal_count:
|
|
100
|
+
val = round(current_obj, decimal_count)
|
|
101
|
+
return str(val) if cast_to_str else val
|
|
102
|
+
elif callable(current_obj):
|
|
103
|
+
return str(current_obj()) if cast_to_str else current_obj()
|
|
104
|
+
else:
|
|
105
|
+
return str(current_obj) if cast_to_str else current_obj
|
|
106
|
+
except AttributeError:
|
|
107
|
+
return 'N/A'
|
honeybee/shade.py
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
"""Honeybee Shade."""
|
|
3
|
+
from __future__ import division
|
|
4
|
+
import math
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from ladybug_geometry.geometry3d.pointvector import Point3D
|
|
8
|
+
from ladybug_geometry.geometry3d.face import Face3D
|
|
9
|
+
from ladybug.color import Color
|
|
10
|
+
|
|
11
|
+
from ._base import _Base
|
|
12
|
+
from .typing import clean_string
|
|
13
|
+
from .search import get_attr_nested
|
|
14
|
+
from .properties import ShadeProperties
|
|
15
|
+
import honeybee.writer.shade as writer
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Shade(_Base):
|
|
19
|
+
"""A single planar shade.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
identifier: Text string for a unique Shade ID. Must be < 100 characters and
|
|
23
|
+
not contain any spaces or special characters.
|
|
24
|
+
geometry: A ladybug-geometry Face3D.
|
|
25
|
+
is_detached: Boolean to note whether this object is detached from other
|
|
26
|
+
geometry. Cases where this should be True include shade representing
|
|
27
|
+
surrounding buildings or context. (Default: False).
|
|
28
|
+
|
|
29
|
+
Properties:
|
|
30
|
+
* identifier
|
|
31
|
+
* display_name
|
|
32
|
+
* is_detached
|
|
33
|
+
* parent
|
|
34
|
+
* top_level_parent
|
|
35
|
+
* has_parent
|
|
36
|
+
* is_indoor
|
|
37
|
+
* geometry
|
|
38
|
+
* vertices
|
|
39
|
+
* upper_left_vertices
|
|
40
|
+
* normal
|
|
41
|
+
* center
|
|
42
|
+
* area
|
|
43
|
+
* perimeter
|
|
44
|
+
* min
|
|
45
|
+
* max
|
|
46
|
+
* tilt
|
|
47
|
+
* altitude
|
|
48
|
+
* azimuth
|
|
49
|
+
* type_color
|
|
50
|
+
* bc_color
|
|
51
|
+
* user_data
|
|
52
|
+
"""
|
|
53
|
+
__slots__ = ('_geometry', '_parent', '_is_indoor', '_is_detached')
|
|
54
|
+
TYPE_COLORS = {
|
|
55
|
+
(False, False): Color(120, 75, 190),
|
|
56
|
+
(False, True): Color(80, 50, 128),
|
|
57
|
+
(True, False): Color(159, 99, 255),
|
|
58
|
+
(True, True): Color(159, 99, 255)
|
|
59
|
+
}
|
|
60
|
+
BC_COLOR = Color(120, 75, 190)
|
|
61
|
+
|
|
62
|
+
def __init__(self, identifier, geometry, is_detached=False):
|
|
63
|
+
"""A single planar shade."""
|
|
64
|
+
_Base.__init__(self, identifier) # process the identifier
|
|
65
|
+
|
|
66
|
+
# process the geometry and basic properties
|
|
67
|
+
assert isinstance(geometry, Face3D), \
|
|
68
|
+
'Expected ladybug_geometry Face3D. Got {}'.format(type(geometry))
|
|
69
|
+
self._geometry = geometry
|
|
70
|
+
self._parent = None # _parent will be set when the Shade is added to an object
|
|
71
|
+
self._is_indoor = False # this will be set by the _parent
|
|
72
|
+
self.is_detached = is_detached
|
|
73
|
+
|
|
74
|
+
# initialize properties for extensions
|
|
75
|
+
self._properties = ShadeProperties(self)
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
def from_dict(cls, data):
|
|
79
|
+
"""Initialize an Shade from a dictionary.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
data: A dictionary representation of an Shade object.
|
|
83
|
+
"""
|
|
84
|
+
try:
|
|
85
|
+
# check the type of dictionary
|
|
86
|
+
assert data['type'] == 'Shade', 'Expected Shade dictionary. ' \
|
|
87
|
+
'Got {}.'.format(data['type'])
|
|
88
|
+
|
|
89
|
+
# serialize the dictionary to an object
|
|
90
|
+
is_det = data['is_detached'] if 'is_detached' in data else False
|
|
91
|
+
shade = cls(data['identifier'], Face3D.from_dict(data['geometry']), is_det)
|
|
92
|
+
if 'display_name' in data and data['display_name'] is not None:
|
|
93
|
+
shade.display_name = data['display_name']
|
|
94
|
+
if 'user_data' in data and data['user_data'] is not None:
|
|
95
|
+
shade.user_data = data['user_data']
|
|
96
|
+
|
|
97
|
+
if data['properties']['type'] == 'ShadeProperties':
|
|
98
|
+
shade.properties._load_extension_attr_from_dict(data['properties'])
|
|
99
|
+
return shade
|
|
100
|
+
except Exception as e:
|
|
101
|
+
cls._from_dict_error_message(data, e)
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def from_vertices(cls, identifier, vertices, is_detached=False):
|
|
105
|
+
"""Create a Shade from vertices with each vertex as an iterable of 3 floats.
|
|
106
|
+
|
|
107
|
+
Note that this method is not recommended for a shade with one or more holes
|
|
108
|
+
since the distinction between hole vertices and boundary vertices cannot
|
|
109
|
+
be derived from a single list of vertices.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
identifier: Text string for a unique Shade ID. Must be < 100 characters and
|
|
113
|
+
not contain any spaces or special characters.
|
|
114
|
+
vertices: A flattened list of 3 or more vertices as (x, y, z).
|
|
115
|
+
is_detached: Boolean to note whether this object is detached from other
|
|
116
|
+
geometry. Cases where this should be True include shade representing
|
|
117
|
+
surrounding buildings or context. (Default: False).
|
|
118
|
+
"""
|
|
119
|
+
geometry = Face3D(tuple(Point3D(*v) for v in vertices))
|
|
120
|
+
return cls(identifier, geometry, is_detached)
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def is_detached(self):
|
|
124
|
+
"""Get or set a boolean for whether this object is detached from other geometry.
|
|
125
|
+
|
|
126
|
+
This will automatically be set to False if the shade is assigned to
|
|
127
|
+
parent objects.
|
|
128
|
+
"""
|
|
129
|
+
return self._is_detached
|
|
130
|
+
|
|
131
|
+
@is_detached.setter
|
|
132
|
+
def is_detached(self, value):
|
|
133
|
+
try:
|
|
134
|
+
self._is_detached = bool(value)
|
|
135
|
+
if self._is_detached:
|
|
136
|
+
assert not self.has_parent, 'Shade cannot be detached when it has ' \
|
|
137
|
+
'a parent Room, Face, Aperture or Door.'
|
|
138
|
+
except TypeError:
|
|
139
|
+
raise TypeError(
|
|
140
|
+
'Expected boolean for Shade.is_detached. Got {}.'.format(value))
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def parent(self):
|
|
144
|
+
"""Get the parent object if assigned. None if not assigned.
|
|
145
|
+
|
|
146
|
+
The parent object can be either a Room, Face, Aperture or Door.
|
|
147
|
+
"""
|
|
148
|
+
return self._parent
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def top_level_parent(self):
|
|
152
|
+
"""Get the top-level parent object if assigned.
|
|
153
|
+
|
|
154
|
+
This will be the highest-level parent in the hierarchy of the parent-child
|
|
155
|
+
chain. Will be None if no parent is assigned.
|
|
156
|
+
"""
|
|
157
|
+
if self.has_parent:
|
|
158
|
+
if self._parent.has_parent:
|
|
159
|
+
if self._parent._parent.has_parent:
|
|
160
|
+
return self._parent._parent._parent
|
|
161
|
+
return self._parent._parent
|
|
162
|
+
return self._parent
|
|
163
|
+
return None
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def has_parent(self):
|
|
167
|
+
"""Get a boolean noting whether this Shade has a parent object."""
|
|
168
|
+
return self._parent is not None
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def is_indoor(self):
|
|
172
|
+
"""Get a boolean for whether this Shade is on the indoors of its parent object.
|
|
173
|
+
|
|
174
|
+
Note that, if there is no parent assigned to this Shade, this property will
|
|
175
|
+
be False.
|
|
176
|
+
"""
|
|
177
|
+
return self._is_indoor
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def geometry(self):
|
|
181
|
+
"""Get a ladybug_geometry Face3D object representing the Shade."""
|
|
182
|
+
return self._geometry
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def vertices(self):
|
|
186
|
+
"""Get a list of vertices for the shade (in counter-clockwise order)."""
|
|
187
|
+
return self._geometry.vertices
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def upper_left_vertices(self):
|
|
191
|
+
"""Get a list of vertices starting from the upper-left corner.
|
|
192
|
+
|
|
193
|
+
This property should be used when exporting to EnergyPlus / OpenStudio.
|
|
194
|
+
"""
|
|
195
|
+
return self._geometry.upper_left_counter_clockwise_vertices
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def normal(self):
|
|
199
|
+
"""Get a ladybug_geometry Vector3D for the direction the shade is pointing.
|
|
200
|
+
"""
|
|
201
|
+
return self._geometry.normal
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def center(self):
|
|
205
|
+
"""Get a ladybug_geometry Point3D for the center of the shade.
|
|
206
|
+
|
|
207
|
+
Note that this is the center of the bounding rectangle around this geometry
|
|
208
|
+
and not the area centroid.
|
|
209
|
+
"""
|
|
210
|
+
return self._geometry.center
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def area(self):
|
|
214
|
+
"""Get the area of the shade."""
|
|
215
|
+
return self._geometry.area
|
|
216
|
+
|
|
217
|
+
@property
|
|
218
|
+
def perimeter(self):
|
|
219
|
+
"""Get the perimeter of the shade."""
|
|
220
|
+
return self._geometry.perimeter
|
|
221
|
+
|
|
222
|
+
@property
|
|
223
|
+
def min(self):
|
|
224
|
+
"""Get a Point3D for the minimum of the bounding box around the object."""
|
|
225
|
+
return self._geometry.min
|
|
226
|
+
|
|
227
|
+
@property
|
|
228
|
+
def max(self):
|
|
229
|
+
"""Get a Point3D for the maximum of the bounding box around the object."""
|
|
230
|
+
return self._geometry.max
|
|
231
|
+
|
|
232
|
+
@property
|
|
233
|
+
def tilt(self):
|
|
234
|
+
"""Get the tilt of the geometry between 0 (up) and 180 (down)."""
|
|
235
|
+
return math.degrees(self._geometry.tilt)
|
|
236
|
+
|
|
237
|
+
@property
|
|
238
|
+
def altitude(self):
|
|
239
|
+
"""Get the altitude of the geometry between +90 (up) and -90 (down)."""
|
|
240
|
+
return math.degrees(self._geometry.altitude)
|
|
241
|
+
|
|
242
|
+
@property
|
|
243
|
+
def azimuth(self):
|
|
244
|
+
"""Get the azimuth of the geometry, between 0 and 360.
|
|
245
|
+
|
|
246
|
+
Given Y-axis as North, 0 = North, 90 = East, 180 = South, 270 = West
|
|
247
|
+
This will be zero if the Face3D is perfectly horizontal.
|
|
248
|
+
"""
|
|
249
|
+
return math.degrees(self._geometry.azimuth)
|
|
250
|
+
|
|
251
|
+
@property
|
|
252
|
+
def gbxml_type(self):
|
|
253
|
+
"""Get text for the type of object this is in gbXML schema."""
|
|
254
|
+
return 'Shade'
|
|
255
|
+
|
|
256
|
+
@property
|
|
257
|
+
def type_color(self):
|
|
258
|
+
"""Get a Color to be used in visualizations by type."""
|
|
259
|
+
return self.TYPE_COLORS[(self.is_indoor, self.is_detached)]
|
|
260
|
+
|
|
261
|
+
@property
|
|
262
|
+
def bc_color(self):
|
|
263
|
+
"""Get a Color to be used in visualizations by boundary condition."""
|
|
264
|
+
return self.BC_COLOR
|
|
265
|
+
|
|
266
|
+
def add_prefix(self, prefix):
|
|
267
|
+
"""Change the identifier of this object by inserting a prefix.
|
|
268
|
+
|
|
269
|
+
This is particularly useful in workflows where you duplicate and edit
|
|
270
|
+
a starting object and then want to combine it with the original object
|
|
271
|
+
into one Model (like making a model of repeated rooms) since all objects
|
|
272
|
+
within a Model must have unique identifiers.
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
prefix: Text that will be inserted at the start of this object's identifier
|
|
276
|
+
and display_name. It is recommended that this prefix be short to
|
|
277
|
+
avoid maxing out the 100 allowable characters for honeybee identifiers.
|
|
278
|
+
"""
|
|
279
|
+
self._identifier = clean_string('{}_{}'.format(prefix, self.identifier))
|
|
280
|
+
self.display_name = '{}_{}'.format(prefix, self.display_name)
|
|
281
|
+
self.properties.add_prefix(prefix)
|
|
282
|
+
|
|
283
|
+
def rename_by_attribute(
|
|
284
|
+
self, format_str='{display_name} - {gbxml_type}'
|
|
285
|
+
):
|
|
286
|
+
"""Set the display name of this Shade using a format string with attributes.
|
|
287
|
+
|
|
288
|
+
Args:
|
|
289
|
+
format_str: Text string for the pattern with which the Shade will be
|
|
290
|
+
renamed. Any property on this class may be used (eg. energyplus_type)
|
|
291
|
+
and each property should be put in curly brackets. Nested
|
|
292
|
+
properties can be specified by using "." to denote nesting levels
|
|
293
|
+
(eg. properties.energy.construction.display_name). Functions that
|
|
294
|
+
return string outputs can also be passed here as long as these
|
|
295
|
+
functions defaults specified for all arguments.
|
|
296
|
+
"""
|
|
297
|
+
matches = re.findall(r'{([^}]*)}', format_str)
|
|
298
|
+
attributes = [get_attr_nested(self, m, decimal_count=2) for m in matches]
|
|
299
|
+
for attr_name, attr_val in zip(matches, attributes):
|
|
300
|
+
format_str = format_str.replace('{{{}}}'.format(attr_name), attr_val)
|
|
301
|
+
self.display_name = format_str
|
|
302
|
+
return format_str
|
|
303
|
+
|
|
304
|
+
def move(self, moving_vec):
|
|
305
|
+
"""Move this Shade along a vector.
|
|
306
|
+
|
|
307
|
+
Args:
|
|
308
|
+
moving_vec: A ladybug_geometry Vector3D with the direction and distance
|
|
309
|
+
to move the face.
|
|
310
|
+
"""
|
|
311
|
+
self._geometry = self.geometry.move(moving_vec)
|
|
312
|
+
self.properties.move(moving_vec)
|
|
313
|
+
|
|
314
|
+
def rotate(self, axis, angle, origin):
|
|
315
|
+
"""Rotate this Shade by a certain angle around an axis and origin.
|
|
316
|
+
|
|
317
|
+
Args:
|
|
318
|
+
axis: A ladybug_geometry Vector3D axis representing the axis of rotation.
|
|
319
|
+
angle: An angle for rotation in degrees.
|
|
320
|
+
origin: A ladybug_geometry Point3D for the origin around which the
|
|
321
|
+
object will be rotated.
|
|
322
|
+
"""
|
|
323
|
+
self._geometry = self.geometry.rotate(axis, math.radians(angle), origin)
|
|
324
|
+
self.properties.rotate(axis, angle, origin)
|
|
325
|
+
|
|
326
|
+
def rotate_xy(self, angle, origin):
|
|
327
|
+
"""Rotate this Shade counterclockwise in the world XY plane by a certain angle.
|
|
328
|
+
|
|
329
|
+
Args:
|
|
330
|
+
angle: An angle in degrees.
|
|
331
|
+
origin: A ladybug_geometry Point3D for the origin around which the
|
|
332
|
+
object will be rotated.
|
|
333
|
+
"""
|
|
334
|
+
self._geometry = self.geometry.rotate_xy(math.radians(angle), origin)
|
|
335
|
+
self.properties.rotate_xy(angle, origin)
|
|
336
|
+
|
|
337
|
+
def reflect(self, plane):
|
|
338
|
+
"""Reflect this Shade across a plane.
|
|
339
|
+
|
|
340
|
+
Args:
|
|
341
|
+
plane: A ladybug_geometry Plane across which the object will
|
|
342
|
+
be reflected.
|
|
343
|
+
"""
|
|
344
|
+
self._geometry = self.geometry.reflect(plane.n, plane.o)
|
|
345
|
+
self.properties.reflect(plane)
|
|
346
|
+
|
|
347
|
+
def scale(self, factor, origin=None):
|
|
348
|
+
"""Scale this Shade by a factor from an origin point.
|
|
349
|
+
|
|
350
|
+
Args:
|
|
351
|
+
factor: A number representing how much the object should be scaled.
|
|
352
|
+
origin: A ladybug_geometry Point3D representing the origin from which
|
|
353
|
+
to scale. If None, it will be scaled from the World origin (0, 0, 0).
|
|
354
|
+
"""
|
|
355
|
+
self._geometry = self.geometry.scale(factor, origin)
|
|
356
|
+
self.properties.scale(factor, origin)
|
|
357
|
+
|
|
358
|
+
def remove_colinear_vertices(self, tolerance=0.01):
|
|
359
|
+
"""Remove all colinear and duplicate vertices from this object's geometry.
|
|
360
|
+
|
|
361
|
+
Args:
|
|
362
|
+
tolerance: The minimum distance between a vertex and the boundary segments
|
|
363
|
+
at which point the vertex is considered colinear. Default: 0.01,
|
|
364
|
+
suitable for objects in meters.
|
|
365
|
+
"""
|
|
366
|
+
try:
|
|
367
|
+
self._geometry = self.geometry.remove_colinear_vertices(tolerance)
|
|
368
|
+
except AssertionError as e: # usually a sliver face of some kind
|
|
369
|
+
raise ValueError(
|
|
370
|
+
'Shade "{}" is invalid with dimensions less than the '
|
|
371
|
+
'tolerance.\n{}'.format(self.full_id, e))
|
|
372
|
+
|
|
373
|
+
def is_geo_equivalent(self, shade, tolerance=0.01):
|
|
374
|
+
"""Get a boolean for whether this object is geometrically equivalent to another.
|
|
375
|
+
|
|
376
|
+
The total number of vertices and the ordering of these vertices can be
|
|
377
|
+
different but the geometries must share the same center point and be
|
|
378
|
+
next to one another to within the tolerance.
|
|
379
|
+
|
|
380
|
+
Args:
|
|
381
|
+
shade: Another Shade for which geometric equivalency will be tested.
|
|
382
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
383
|
+
vertices at which they can be considered geometrically equivalent.
|
|
384
|
+
|
|
385
|
+
Returns:
|
|
386
|
+
True if geometrically equivalent. False if not geometrically equivalent.
|
|
387
|
+
"""
|
|
388
|
+
meta_1 = (self.display_name, self.is_detached)
|
|
389
|
+
meta_2 = (shade.display_name, shade.is_detached)
|
|
390
|
+
if meta_1 != meta_2:
|
|
391
|
+
return False
|
|
392
|
+
if abs(self.area - shade.area) > tolerance * self.area:
|
|
393
|
+
return False
|
|
394
|
+
return self.geometry.is_centered_adjacent(shade.geometry, tolerance)
|
|
395
|
+
|
|
396
|
+
def check_planar(self, tolerance=0.01, raise_exception=True, detailed=False):
|
|
397
|
+
"""Check whether all of the Shade's vertices lie within the same plane.
|
|
398
|
+
|
|
399
|
+
Args:
|
|
400
|
+
tolerance: The minimum distance between a given vertex and a the
|
|
401
|
+
object's plane at which the vertex is said to lie in the plane.
|
|
402
|
+
Default: 0.01, suitable for objects in meters.
|
|
403
|
+
raise_exception: Boolean to note whether an ValueError should be
|
|
404
|
+
raised if a vertex does not lie within the object's plane.
|
|
405
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
406
|
+
dicts with error info or a string with a message. (Default: False).
|
|
407
|
+
|
|
408
|
+
Returns:
|
|
409
|
+
A string with the message or a list with a dictionary if detailed is True.
|
|
410
|
+
"""
|
|
411
|
+
try:
|
|
412
|
+
self.geometry.check_planar(tolerance, raise_exception=True)
|
|
413
|
+
except ValueError as e:
|
|
414
|
+
msg = 'Shade "{}" is not planar.\n{}'.format(self.full_id, e)
|
|
415
|
+
full_msg = self._validation_message(
|
|
416
|
+
msg, raise_exception, detailed, '000101',
|
|
417
|
+
error_type='Non-Planar Geometry')
|
|
418
|
+
if detailed: # add the out-of-plane points to helper_geometry
|
|
419
|
+
help_pts = [
|
|
420
|
+
p.to_dict() for p in self.geometry.non_planar_vertices(tolerance)
|
|
421
|
+
]
|
|
422
|
+
full_msg[0]['helper_geometry'] = help_pts
|
|
423
|
+
return full_msg
|
|
424
|
+
return [] if detailed else ''
|
|
425
|
+
|
|
426
|
+
def check_self_intersecting(self, tolerance=0.01, raise_exception=True,
|
|
427
|
+
detailed=False):
|
|
428
|
+
"""Check whether the edges of the Shade intersect one another (like a bowtie).
|
|
429
|
+
|
|
430
|
+
Args:
|
|
431
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
432
|
+
vertices at which they can be considered equivalent. Default: 0.01,
|
|
433
|
+
suitable for objects in meters.
|
|
434
|
+
raise_exception: If True, a ValueError will be raised if the object
|
|
435
|
+
intersects with itself. Default: True.
|
|
436
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
437
|
+
dicts with error info or a string with a message. (Default: False).
|
|
438
|
+
|
|
439
|
+
Returns:
|
|
440
|
+
A string with the message or a list with a dictionary if detailed is True.
|
|
441
|
+
"""
|
|
442
|
+
if self.geometry.is_self_intersecting:
|
|
443
|
+
msg = 'Shade "{}" has self-intersecting edges.'.format(self.full_id)
|
|
444
|
+
try: # see if it is self-intersecting because of a duplicate vertex
|
|
445
|
+
new_geo = self.geometry.remove_duplicate_vertices(tolerance)
|
|
446
|
+
if not new_geo.is_self_intersecting:
|
|
447
|
+
return [] if detailed else '' # valid with removed dup vertex
|
|
448
|
+
except AssertionError:
|
|
449
|
+
return [] if detailed else '' # degenerate geometry
|
|
450
|
+
full_msg = self._validation_message(
|
|
451
|
+
msg, raise_exception, detailed, '000102',
|
|
452
|
+
error_type='Self-Intersecting Geometry')
|
|
453
|
+
if detailed: # add the self-intersection points to helper_geometry
|
|
454
|
+
help_pts = [p.to_dict() for p in self.geometry.self_intersection_points]
|
|
455
|
+
full_msg[0]['helper_geometry'] = help_pts
|
|
456
|
+
return full_msg
|
|
457
|
+
return [] if detailed else ''
|
|
458
|
+
|
|
459
|
+
def display_dict(self):
|
|
460
|
+
"""Get a list of DisplayFace3D dictionaries for visualizing the object."""
|
|
461
|
+
return [self._display_face(self.geometry, self.type_color)]
|
|
462
|
+
|
|
463
|
+
@property
|
|
464
|
+
def to(self):
|
|
465
|
+
"""Shade writer object.
|
|
466
|
+
|
|
467
|
+
Use this method to access Writer class to write the shade in different formats.
|
|
468
|
+
|
|
469
|
+
Usage:
|
|
470
|
+
|
|
471
|
+
.. code-block:: python
|
|
472
|
+
|
|
473
|
+
shade.to.idf(shade) -> idf string.
|
|
474
|
+
shade.to.radiance(shade) -> Radiance string.
|
|
475
|
+
"""
|
|
476
|
+
return writer
|
|
477
|
+
|
|
478
|
+
def to_dict(self, abridged=False, included_prop=None, include_plane=True):
|
|
479
|
+
"""Return Shade as a dictionary.
|
|
480
|
+
|
|
481
|
+
Args:
|
|
482
|
+
abridged: Boolean to note whether the extension properties of the
|
|
483
|
+
object (ie. modifiers, transmittance schedule) should be included in
|
|
484
|
+
detail (False) or just referenced by identifier (True). Default: False.
|
|
485
|
+
included_prop: List of properties to filter keys that must be included in
|
|
486
|
+
output dictionary. For example ['energy'] will include 'energy' key if
|
|
487
|
+
available in properties to_dict. By default all the keys will be
|
|
488
|
+
included. To exclude all the keys from extensions use an empty list.
|
|
489
|
+
include_plane: Boolean to note wether the plane of the Face3D should be
|
|
490
|
+
included in the output. This can preserve the orientation of the
|
|
491
|
+
X/Y axes of the plane but is not required and can be removed to
|
|
492
|
+
keep the dictionary smaller. (Default: True).
|
|
493
|
+
"""
|
|
494
|
+
base = {'type': 'Shade'}
|
|
495
|
+
base['identifier'] = self.identifier
|
|
496
|
+
base['display_name'] = self.display_name
|
|
497
|
+
base['properties'] = self.properties.to_dict(abridged, included_prop)
|
|
498
|
+
enforce_upper_left = True if 'energy' in base['properties'] else False
|
|
499
|
+
base['geometry'] = self._geometry.to_dict(include_plane, enforce_upper_left)
|
|
500
|
+
if self.is_detached:
|
|
501
|
+
base['is_detached'] = self.is_detached
|
|
502
|
+
if self.user_data is not None:
|
|
503
|
+
base['user_data'] = self.user_data
|
|
504
|
+
return base
|
|
505
|
+
|
|
506
|
+
def __copy__(self):
|
|
507
|
+
new_shade = Shade(self.identifier, self.geometry, self.is_detached)
|
|
508
|
+
new_shade._display_name = self._display_name
|
|
509
|
+
new_shade._user_data = None if self.user_data is None else self.user_data.copy()
|
|
510
|
+
new_shade._properties._duplicate_extension_attr(self._properties)
|
|
511
|
+
return new_shade
|
|
512
|
+
|
|
513
|
+
def __repr__(self):
|
|
514
|
+
return 'Shade: %s' % self.display_name
|