dragonfly-radiance 0.4.56__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.

Potentially problematic release.


This version of dragonfly-radiance might be problematic. Click here for more details.

@@ -0,0 +1,438 @@
1
+ # coding=utf-8
2
+ """Model Radiance Properties."""
3
+ try:
4
+ from itertools import izip as zip # python 2
5
+ except ImportError:
6
+ pass # python 3
7
+
8
+ from honeybee.checkdup import check_duplicate_identifiers
9
+ from honeybee.extensionutil import room_extension_dicts
10
+ import honeybee_radiance.properties.model as hb_model_properties
11
+ from honeybee_radiance.lib.modifiersets import generic_modifier_set_visible
12
+ from honeybee_radiance.lib.modifiers import generic_context
13
+
14
+ from dragonfly.extensionutil import model_extension_dicts
15
+
16
+
17
+ class ModelRadianceProperties(object):
18
+ """Radiance Properties for Dragonfly Model.
19
+
20
+ Args:
21
+ host: A dragonfly_core Model object that hosts these properties.
22
+
23
+ Properties:
24
+ * host
25
+ * modifiers
26
+ * shade_modifiers
27
+ * modifier_sets
28
+ * global_modifier_set
29
+ """
30
+
31
+ def __init__(self, host):
32
+ """Initialize Model Radiance properties."""
33
+ self._host = host
34
+
35
+ @property
36
+ def host(self):
37
+ """Get the Model object hosting these properties."""
38
+ return self._host
39
+
40
+ @property
41
+ def modifiers(self):
42
+ """List of all unique modifiers contained within the model.
43
+
44
+ This includes modifiers across all Room2Ds, Stories, and Building
45
+ ModifierSets but it does NOT include the Honeybee generic default
46
+ modifier set.
47
+ """
48
+ bldg_mods = []
49
+ for mod_set in self.modifier_sets:
50
+ bldg_mods.extend(mod_set.modified_modifiers_unique)
51
+ all_mods = bldg_mods + self.face_modifiers + self.shade_modifiers
52
+ return list(set(all_mods))
53
+
54
+ @property
55
+ def face_modifiers(self):
56
+ """Get a list of all unique modifiers assigned to Faces, Apertures and Doors.
57
+
58
+ These objects only exist under the Building.room_3ds property.
59
+ """
60
+ modifiers = []
61
+ for bldg in self.host.buildings:
62
+ for face in bldg.room_3d_faces:
63
+ self._check_and_add_obj_modifier(face, modifiers)
64
+ for ap in face.apertures:
65
+ self._check_and_add_obj_modifier(ap, modifiers)
66
+ for dr in face.doors:
67
+ self._check_and_add_obj_modifier(dr, modifiers)
68
+ return list(set(modifiers))
69
+
70
+ @property
71
+ def shade_modifiers(self):
72
+ """A list of all unique modifiers assigned to ContextShades in the model."""
73
+ modifiers = []
74
+ for shade in self.host.context_shades:
75
+ self._check_and_add_obj_modifier(shade, modifiers)
76
+ for bldg in self.host.buildings:
77
+ for shd in bldg.room_3d_shades:
78
+ self._check_and_add_obj_modifier(shd, modifiers)
79
+ return list(set(modifiers))
80
+
81
+ @property
82
+ def modifier_sets(self):
83
+ """A list of all unique Building-Assigned ModifierSets in the Model.
84
+
85
+ Note that this includes ModifierSets assigned to individual Stories and
86
+ Room2Ds in the Building.
87
+ """
88
+ modifier_sets = []
89
+ for bldg in self.host.buildings:
90
+ self._check_and_add_obj_mod_set(bldg, modifier_sets)
91
+ for story in bldg.unique_stories:
92
+ self._check_and_add_obj_mod_set(story, modifier_sets)
93
+ for room in story.room_2ds:
94
+ self._check_and_add_obj_mod_set(room, modifier_sets)
95
+ for room in bldg.room_3ds:
96
+ self._check_and_add_obj_mod_set(room, modifier_sets)
97
+ return list(set(modifier_sets)) # catch equivalent modifier sets
98
+
99
+ @property
100
+ def global_modifier_set(self):
101
+ """The global radiance modifier set.
102
+
103
+ This is what is used whenever there is no modifier_set assigned to a
104
+ Room2D, a parent Story, or a parent Building.
105
+ """
106
+ return generic_modifier_set_visible
107
+
108
+ def check_for_extension(self, raise_exception=True, detailed=False):
109
+ """Check that the Model is valid for Radiance simulation.
110
+
111
+ This process includes all relevant dragonfly-core checks as well as checks
112
+ that apply only for Radiance.
113
+
114
+ Args:
115
+ raise_exception: Boolean to note whether a ValueError should be raised
116
+ if any errors are found. If False, this method will simply
117
+ return a text string with all errors that were found. (Default: True).
118
+ detailed: Boolean for whether the returned object is a detailed list of
119
+ dicts with error info or a string with a message. (Default: False).
120
+
121
+ Returns:
122
+ A text string with all errors that were found or a list if detailed is True.
123
+ This string (or list) will be empty if no errors were found.
124
+ """
125
+ # set up defaults to ensure the method runs correctly
126
+ detailed = False if raise_exception else detailed
127
+ msgs = []
128
+ tol = self.host.tolerance
129
+ ang_tol = self.host.angle_tolerance
130
+
131
+ # perform checks for duplicate identifiers, which might mess with other checks
132
+ msgs.append(self.host.check_all_duplicate_identifiers(False, detailed))
133
+
134
+ # perform checks for key dragonfly model schema rules
135
+ msgs.append(self.host.check_degenerate_room_2ds(tol, False, detailed))
136
+ msgs.append(self.host.check_self_intersecting_room_2ds(tol, False, detailed))
137
+ msgs.append(self.host.check_plenum_depths(tol, False, detailed))
138
+ msgs.append(self.host.check_window_parameters_valid(tol, False, detailed))
139
+ msgs.append(self.host.check_no_room2d_overlaps(tol, False, detailed))
140
+ msgs.append(self.host.check_collisions_between_stories(tol, False, detailed))
141
+ msgs.append(self.host.check_roofs_above_rooms(tol, False, detailed))
142
+ msgs.append(self.host.check_room2d_floor_heights_valid(False, detailed))
143
+ msgs.append(self.host.check_all_room3d(tol, ang_tol, False, detailed))
144
+
145
+ # output a final report of errors or raise an exception
146
+ full_msgs = [msg for msg in msgs if msg]
147
+ if detailed:
148
+ return [m for msg in full_msgs for m in msg]
149
+ full_msg = '\n'.join(full_msgs)
150
+ if raise_exception and len(full_msgs) != 0:
151
+ raise ValueError(full_msg)
152
+ return full_msg
153
+
154
+ def check_generic(self, raise_exception=True, detailed=False):
155
+ """Check generic of the aspects of the Model radiance properties.
156
+
157
+ This includes checks for everything except duplicate identifiers for
158
+ modifiers and modifier sets. Typically, these checks just add to the
159
+ validation time without providing useful information since extension
160
+ objects with duplicate IDs are lost during HBJSON serialization.
161
+
162
+ Args:
163
+ raise_exception: Boolean to note whether a ValueError should be raised
164
+ if any errors are found. If False, this method will simply
165
+ return a text string with all errors that were found.
166
+ detailed: Boolean for whether the returned object is a detailed list of
167
+ dicts with error info or a string with a message. (Default: False).
168
+
169
+ Returns:
170
+ A text string with all errors that were found or a list if detailed is True.
171
+ This string (or list) will be empty if no errors were found.
172
+ """
173
+ # set up defaults to ensure the method runs correctly
174
+ detailed = False if raise_exception else detailed
175
+ msgs = []
176
+ # perform checks for specific radiance simulation rules
177
+ # output a final report of errors or raise an exception
178
+ full_msgs = [msg for msg in msgs if msg]
179
+ if detailed:
180
+ return [m for msg in full_msgs for m in msg]
181
+ full_msg = '\n'.join(full_msgs)
182
+ if raise_exception and len(full_msgs) != 0:
183
+ raise ValueError(full_msg)
184
+ return full_msg
185
+
186
+ def check_all(self, raise_exception=True, detailed=False):
187
+ """Check all of the aspects of the Model radiance properties.
188
+
189
+ Args:
190
+ raise_exception: Boolean to note whether a ValueError should be raised
191
+ if any errors are found. If False, this method will simply
192
+ return a text string with all errors that were found.
193
+ detailed: Boolean for whether the returned object is a detailed list of
194
+ dicts with error info or a string with a message. (Default: False).
195
+
196
+ Returns:
197
+ A text string with all errors that were found or a list if detailed is True.
198
+ This string (or list) will be empty if no errors were found.
199
+ """
200
+ # set up defaults to ensure the method runs correctly
201
+ detailed = False if raise_exception else detailed
202
+ msgs = []
203
+ # perform checks for duplicate identifiers
204
+ msgs.append(self.check_all_duplicate_identifiers(False, detailed))
205
+ # perform checks for specific radiance simulation rules
206
+ # output a final report of errors or raise an exception
207
+ full_msgs = [msg for msg in msgs if msg]
208
+ if detailed:
209
+ return [m for msg in full_msgs for m in msg]
210
+ full_msg = '\n'.join(full_msgs)
211
+ if raise_exception and len(full_msgs) != 0:
212
+ raise ValueError(full_msg)
213
+ return full_msg
214
+
215
+ def check_all_duplicate_identifiers(self, raise_exception=True, detailed=False):
216
+ """Check that there are no duplicate identifiers for any geometry objects.
217
+
218
+ This includes Rooms, Faces, Apertures, Doors, Shades, and ShadeMeshes.
219
+
220
+ Args:
221
+ raise_exception: Boolean to note whether a ValueError should be raised
222
+ if any Model errors are found. If False, this method will simply
223
+ return a text string with all errors that were found. (Default: True).
224
+ detailed: Boolean for whether the returned object is a detailed list of
225
+ dicts with error info or a string with a message. (Default: False).
226
+
227
+ Returns:
228
+ A text string with all errors that were found or a list if detailed is True.
229
+ This string (or list) will be empty if no errors were found.
230
+ """
231
+ # set up defaults to ensure the method runs correctly
232
+ detailed = False if raise_exception else detailed
233
+ msgs = []
234
+ # perform checks for duplicate identifiers
235
+ msgs.append(self.check_duplicate_modifier_identifiers(False, detailed))
236
+ msgs.append(self.check_duplicate_modifier_set_identifiers(False, detailed))
237
+ # output a final report of errors or raise an exception
238
+ full_msgs = [msg for msg in msgs if msg]
239
+ if detailed:
240
+ return [m for msg in full_msgs for m in msg]
241
+ full_msg = '\n'.join(full_msgs)
242
+ if raise_exception and len(full_msgs) != 0:
243
+ raise ValueError(full_msg)
244
+ return full_msg
245
+
246
+ def check_duplicate_modifier_identifiers(self, raise_exception=True, detailed=False):
247
+ """Check that there are no duplicate Modifier identifiers in the model.
248
+
249
+ Args:
250
+ raise_exception: Boolean to note whether a ValueError should be raised
251
+ if duplicate identifiers are found. (Default: True).
252
+ detailed: Boolean for whether the returned object is a detailed list of
253
+ dicts with error info or a string with a message. (Default: False).
254
+
255
+ Returns:
256
+ A string with the message or a list with a dictionary if detailed is True.
257
+ """
258
+ return check_duplicate_identifiers(
259
+ self.modifiers, raise_exception, 'Radiance Modifier',
260
+ detailed, '010001', 'Radiance', error_type='Duplicate Modifier Identifier')
261
+
262
+ def check_duplicate_modifier_set_identifiers(
263
+ self, raise_exception=True, detailed=False):
264
+ """Check that there are no duplicate ModifierSet identifiers in the model.
265
+
266
+ Args:
267
+ raise_exception: Boolean to note whether a ValueError should be raised
268
+ if duplicate identifiers are found. (Default: True).
269
+ detailed: Boolean for whether the returned object is a detailed list of
270
+ dicts with error info or a string with a message. (Default: False).
271
+
272
+ Returns:
273
+ A string with the message or a list with a dictionary if detailed is True.
274
+ """
275
+ return check_duplicate_identifiers(
276
+ self.modifier_sets, raise_exception, 'ModifierSet',
277
+ detailed, '010002', 'Radiance',
278
+ error_type='Duplicate ModifierSet Identifier')
279
+
280
+ def apply_properties_from_dict(self, data):
281
+ """Apply the radiance properties of a dictionary to the host Model of this object.
282
+
283
+ Args:
284
+ data: A dictionary representation of an entire dragonfly-core Model.
285
+ Note that this dictionary must have ModelRadianceProperties in order
286
+ for this method to successfully apply the radiance properties.
287
+ """
288
+ assert 'radiance' in data['properties'], \
289
+ 'Dictionary possesses no ModelRadianceProperties.'
290
+ modifiers, modifier_sets = \
291
+ hb_model_properties.ModelRadianceProperties.load_properties_from_dict(data)
292
+
293
+ # collect lists of radiance property dictionaries
294
+ building_e_dicts, story_e_dicts, room2d_e_dicts, context_e_dicts = \
295
+ model_extension_dicts(data, 'radiance', [], [], [], [])
296
+
297
+ # apply radiance properties to objects using the radiance property dictionaries
298
+ for bldg, b_dict in zip(self.host.buildings, building_e_dicts):
299
+ if b_dict is not None:
300
+ bldg.properties.radiance.apply_properties_from_dict(
301
+ b_dict, modifier_sets)
302
+ if bldg.has_room_3ds and b_dict is not None and 'room_3ds' in b_dict and \
303
+ b_dict['room_3ds'] is not None:
304
+ room_e_dicts, face_e_dicts, shd_e_dicts, ap_e_dicts, dr_e_dicts = \
305
+ room_extension_dicts(b_dict['room_3ds'], 'radiance', [], [], [], [], [])
306
+ for room, r_dict in zip(bldg.room_3ds, room_e_dicts):
307
+ if r_dict is not None:
308
+ room.properties.radiance.apply_properties_from_dict(
309
+ r_dict, modifier_sets)
310
+ for face, f_dict in zip(bldg.room_3d_faces, face_e_dicts):
311
+ if f_dict is not None:
312
+ face.properties.radiance.apply_properties_from_dict(
313
+ f_dict, modifiers)
314
+ for aperture, a_dict in zip(bldg.room_3d_apertures, ap_e_dicts):
315
+ if a_dict is not None:
316
+ aperture.properties.radiance.apply_properties_from_dict(
317
+ a_dict, modifiers)
318
+ for door, d_dict in zip(bldg.room_3d_doors, dr_e_dicts):
319
+ if d_dict is not None:
320
+ door.properties.radiance.apply_properties_from_dict(
321
+ d_dict, modifiers)
322
+ for shade, s_dict in zip(bldg.room_3d_shades, shd_e_dicts):
323
+ if s_dict is not None:
324
+ shade.properties.radiance.apply_properties_from_dict(
325
+ s_dict, modifiers)
326
+ for story, s_dict in zip(self.host.stories, story_e_dicts):
327
+ if s_dict is not None:
328
+ story.properties.radiance.apply_properties_from_dict(
329
+ s_dict, modifier_sets)
330
+ for room, r_dict in zip(self.host.room_2ds, room2d_e_dicts):
331
+ if r_dict is not None:
332
+ room.properties.radiance.apply_properties_from_dict(
333
+ r_dict, modifier_sets)
334
+ for shade, s_dict in zip(self.host.context_shades, context_e_dicts):
335
+ if s_dict is not None:
336
+ shade.properties.radiance.apply_properties_from_dict(s_dict, modifiers)
337
+
338
+ def to_dict(self):
339
+ """Return Model radiance properties as a dictionary."""
340
+ base = {'radiance': {'type': 'ModelRadianceProperties'}}
341
+
342
+ # add the global modifier set to the dictionary
343
+ gs = self.global_modifier_set.to_dict(abridged=True, none_for_defaults=False)
344
+ gs['type'] = 'GlobalModifierSet'
345
+ del gs['identifier']
346
+ g_mods = self.global_modifier_set.modifiers_unique
347
+ gs['modifiers'] = [mod.to_dict() for mod in g_mods]
348
+ gs['context_modifier'] = generic_context.identifier
349
+ gs['modifiers'].append(generic_context.to_dict())
350
+ base['radiance']['global_modifier_set'] = gs
351
+
352
+ # add all ModifierSets to the dictionary
353
+ base['radiance']['modifier_sets'] = []
354
+ modifier_sets = self.modifier_sets
355
+ for mod_set in modifier_sets:
356
+ base['radiance']['modifier_sets'].append(mod_set.to_dict(abridged=True))
357
+
358
+ # add all unique Modifiers to the dictionary
359
+ room_mods = []
360
+ for mod_set in modifier_sets:
361
+ room_mods.extend(mod_set.modified_modifiers_unique)
362
+ all_mods = room_mods + self.face_modifiers + self.shade_modifiers
363
+ modifiers = tuple(set(all_mods))
364
+ base['radiance']['modifiers'] = []
365
+ for mod in modifiers:
366
+ base['radiance']['modifiers'].append(mod.to_dict())
367
+
368
+ return base
369
+
370
+ def to_honeybee(self, new_host):
371
+ """Get a honeybee version of this object.
372
+
373
+ Args:
374
+ new_host: A honeybee-core Model object that will host these properties.
375
+ """
376
+ hb_rad_props = hb_model_properties.ModelRadianceProperties(new_host)
377
+ # gather all of the sensor grid parameters across the model
378
+ sg_dict = {}
379
+ for rm_2d in self.host.room_2ds:
380
+ if len(rm_2d.properties.radiance._grid_parameters) != 0:
381
+ sg_dict[rm_2d.identifier] = rm_2d.properties.radiance._grid_parameters
382
+ # generate and assign sensor grids to the rooms of the new_host
383
+ if len(sg_dict) != 0:
384
+ sensor_grids = []
385
+ for rm_id, g_par in sg_dict.items():
386
+ for room in new_host.rooms:
387
+ if room.identifier == rm_id:
388
+ for gp in g_par:
389
+ sg = gp.generate_grid_from_room(room)
390
+ if sg is not None:
391
+ sensor_grids.append(sg)
392
+ break
393
+ hb_rad_props.sensor_grids = sensor_grids
394
+ return hb_rad_props
395
+
396
+ def duplicate(self, new_host=None):
397
+ """Get a copy of this Model.
398
+
399
+ Args:
400
+ new_host: A new Model object that hosts these properties.
401
+ If None, the properties will be duplicated with the same host.
402
+ """
403
+ _host = new_host or self._host
404
+ return ModelRadianceProperties(_host)
405
+
406
+ def _check_and_add_obj_modifier(self, obj, modifiers):
407
+ """Check if a modifier is assigned to an object and add it to a list."""
408
+ mod = obj.properties.radiance._modifier
409
+ if mod is not None:
410
+ if not self._instance_in_array(mod, modifiers):
411
+ modifiers.append(mod)
412
+
413
+ def _check_and_add_obj_mod_set(self, obj, modifier_sets):
414
+ """Check if a modifier set is assigned to an object and add it to a list."""
415
+ m_set = obj.properties.radiance._modifier_set
416
+ if m_set is not None:
417
+ if not self._instance_in_array(m_set, modifier_sets):
418
+ modifier_sets.append(m_set)
419
+
420
+ @staticmethod
421
+ def _instance_in_array(object_instance, object_array):
422
+ """Check if a specific object instance is already in an array.
423
+
424
+ This can be much faster than `if object_instance in object_array`
425
+ when you expect to be testing a lot of the same instance of an object for
426
+ inclusion in an array since the builtin method uses an == operator to
427
+ test inclusion.
428
+ """
429
+ for val in object_array:
430
+ if val is object_instance:
431
+ return True
432
+ return False
433
+
434
+ def ToString(self):
435
+ return self.__repr__()
436
+
437
+ def __repr__(self):
438
+ return 'Model Radiance Properties: {}'.format(self.host.identifier)
@@ -0,0 +1,230 @@
1
+ # coding=utf-8
2
+ """Room2D Radiance Properties."""
3
+ from honeybee_radiance.properties.room import RoomRadianceProperties
4
+ from honeybee_radiance.modifierset import ModifierSet
5
+ from honeybee_radiance.lib.modifiersets import generic_modifier_set_visible
6
+
7
+ import dragonfly_radiance.gridpar as sg_par
8
+ from ..gridpar import _GridParameterBase, RoomGridParameter, RoomRadialGridParameter
9
+
10
+
11
+ class Room2DRadianceProperties(object):
12
+ """Radiance Properties for Dragonfly Room2D.
13
+
14
+ Args:
15
+ host: A dragonfly_core Room2D object that hosts these properties.
16
+ modifier_set: A honeybee ModifierSet object to specify all default
17
+ modifiers for the Faces of the Room2D. If None, the Room2D will use
18
+ the honeybee default modifier set, which is only representative
19
+ of typical indoor conditions in the visible spectrum. (Default: None).
20
+ grid_parameters: An optional list of GridParameter objects to describe
21
+ how sensor grids should be generated for the Room2D. (Default: None).
22
+
23
+ Properties:
24
+ * host
25
+ * modifier_set
26
+ * grid_parameters
27
+ """
28
+ __slots__ = ('_host', '_modifier_set', '_grid_parameters')
29
+
30
+ def __init__(self, host, modifier_set=None, grid_parameters=None):
31
+ """Initialize Room2D Radiance properties."""
32
+ self._host = host
33
+ self.modifier_set = modifier_set
34
+ self.grid_parameters = grid_parameters
35
+
36
+ @property
37
+ def host(self):
38
+ """Get the Room2D object hosting these properties."""
39
+ return self._host
40
+
41
+ @property
42
+ def modifier_set(self):
43
+ """Get or set the Room2D ModifierSet object.
44
+
45
+ If not set, it will be set by the parent Story or will be the Honeybee
46
+ default generic ModifierSet.
47
+ """
48
+ if self._modifier_set is not None: # set by the user
49
+ return self._modifier_set
50
+ elif self._host.has_parent: # set by parent story
51
+ return self._host.parent.properties.radiance.modifier_set
52
+ else:
53
+ return generic_modifier_set_visible
54
+
55
+ @modifier_set.setter
56
+ def modifier_set(self, value):
57
+ if value is not None:
58
+ assert isinstance(value, ModifierSet), \
59
+ 'Expected ModifierSet. Got {}'.format(type(value))
60
+ value.lock() # lock in case modifier set has multiple references
61
+ self._modifier_set = value
62
+
63
+ @property
64
+ def grid_parameters(self):
65
+ """Get or set a list of GridParameters to generate sensor grids for the room.
66
+ """
67
+ return tuple(self._grid_parameters)
68
+
69
+ @grid_parameters.setter
70
+ def grid_parameters(self, value):
71
+ if value is not None:
72
+ if not isinstance(value, list):
73
+ value = list(value)
74
+ for sg in value:
75
+ assert isinstance(sg, _GridParameterBase), \
76
+ 'Expected GridParameter. Got {}'.format(type(sg))
77
+ else:
78
+ value = []
79
+ self._grid_parameters = value
80
+
81
+ def remove_grid_parameters(self):
82
+ """Remove all grid_parameters from the Room2D."""
83
+ self._grid_parameters = []
84
+
85
+ def add_grid_parameter(self, grid_parameter):
86
+ """Add a GridParameter to this Room2D.
87
+
88
+ Args:
89
+ grid_parameter: An GridParameter objects to describe how sensor grids
90
+ should be generated for the Room2D.
91
+ """
92
+ assert isinstance(grid_parameter, _GridParameterBase), \
93
+ 'Expected GridParameter. Got {}.'.format(type(grid_parameter))
94
+ self._grid_parameters.append(grid_parameter)
95
+
96
+ def make_plenum(self):
97
+ """Turn the host Room2D into a plenum with no grid parameters inside the room.
98
+
99
+ Grid parameters for exterior facades will be kept. This is useful to
100
+ appropriately assign properties for closets, underfloor spaces, and
101
+ drop ceilings.
102
+ """
103
+ plenum_g_par = []
104
+ for g_par in self._grid_parameters:
105
+ if not isinstance(g_par, (RoomGridParameter, RoomRadialGridParameter)):
106
+ plenum_g_par.append(g_par)
107
+ self._grid_parameters = plenum_g_par
108
+
109
+ @classmethod
110
+ def from_dict(cls, data, host):
111
+ """Create Room2DRadianceProperties from a dictionary.
112
+
113
+ Note that the dictionary must be a non-abridged version for this
114
+ classmethod to work.
115
+
116
+ Args:
117
+ data: A dictionary representation of Room2DRadianceProperties in the
118
+ format below.
119
+ host: A Room2D object that hosts these properties.
120
+
121
+ .. code-block:: python
122
+
123
+ {
124
+ "type": 'Room2DRadianceProperties',
125
+ "modifier_set": {}, # A ModifierSet dictionary
126
+ "grid_parameters": [] # A list of GridParameter dictionaries
127
+ }
128
+ """
129
+ assert data['type'] == 'Room2DRadianceProperties', \
130
+ 'Expected Room2DRadianceProperties. Got {}.'.format(data['type'])
131
+
132
+ new_prop = cls(host)
133
+ if 'modifier_set' in data and data['modifier_set'] is not None:
134
+ new_prop.modifier_set = ModifierSet.from_dict(data['modifier_set'])
135
+ if 'grid_parameters' in data and data['grid_parameters'] is not None:
136
+ grd_par = []
137
+ for gp in data['grid_parameters']:
138
+ try:
139
+ g_class = getattr(sg_par, gp['type'])
140
+ except AttributeError:
141
+ raise ValueError(
142
+ 'GridParameter "{}" is not recognized.'.format(gp['type']))
143
+ grd_par.append(g_class.from_dict(gp))
144
+ new_prop.grid_parameters = grd_par
145
+
146
+ return new_prop
147
+
148
+ def apply_properties_from_dict(self, abridged_data, modifier_sets):
149
+ """Apply properties from a Room2DRadiancePropertiesAbridged dictionary.
150
+
151
+ Args:
152
+ abridged_data: A Room2DRadiancePropertiesAbridged dictionary (typically
153
+ coming from a Model).
154
+ modifier_sets: A dictionary of ModifierSets with identifiers
155
+ of the sets as keys, which will be used to re-assign modifier_sets.
156
+ """
157
+ if 'modifier_set' in abridged_data and abridged_data['modifier_set'] is not None:
158
+ self.modifier_set = modifier_sets[abridged_data['modifier_set']]
159
+ if 'grid_parameters' in abridged_data and \
160
+ abridged_data['grid_parameters'] is not None:
161
+ grd_par = []
162
+ for gp in abridged_data['grid_parameters']:
163
+ try:
164
+ g_class = getattr(sg_par, gp['type'])
165
+ except AttributeError:
166
+ raise ValueError(
167
+ 'GridParameter "{}" is not recognized.'.format(gp['type']))
168
+ grd_par.append(g_class.from_dict(gp))
169
+ self.grid_parameters = grd_par
170
+
171
+ def to_dict(self, abridged=False):
172
+ """Return Room2D radiance properties as a dictionary.
173
+
174
+ Args:
175
+ abridged: Boolean for whether the full dictionary of the Room2D should
176
+ be written (False) or just the identifier of the the individual
177
+ properties (True). Default: False.
178
+ """
179
+ base = {'radiance': {}}
180
+ base['radiance']['type'] = 'Room2DRadianceProperties' if not \
181
+ abridged else 'Room2DRadiancePropertiesAbridged'
182
+
183
+ # write the ModifierSet into the dictionary
184
+ if self._modifier_set is not None:
185
+ base['radiance']['modifier_set'] = \
186
+ self._modifier_set.identifier if abridged else \
187
+ self._modifier_set.to_dict()
188
+
189
+ # write the GridParameters into the dictionary
190
+ if len(self._grid_parameters) != 0:
191
+ base['radiance']['grid_parameters'] = \
192
+ [gdp.to_dict() for gdp in self._grid_parameters]
193
+ return base
194
+
195
+ def to_honeybee(self, new_host):
196
+ """Get a honeybee version of this object.
197
+
198
+ Args:
199
+ new_host: A honeybee-core Room object that will host these properties.
200
+ """
201
+ mod_set = self.modifier_set # includes story and building-assigned sets
202
+ hb_mods = mod_set if mod_set is not generic_modifier_set_visible else None
203
+ hb_prop = RoomRadianceProperties(new_host, hb_mods)
204
+ return hb_prop
205
+
206
+ def from_honeybee(self, hb_properties):
207
+ """Transfer radiance attributes from a Honeybee Room to Dragonfly Room2D.
208
+
209
+ Args:
210
+ hb_properties: The RoomRadianceProperties of the honeybee Room that is being
211
+ translated to a Dragonfly Room2D.
212
+ """
213
+ self._modifier_set = hb_properties._modifier_set
214
+
215
+ def duplicate(self, new_host=None):
216
+ """Get a copy of this object.
217
+
218
+ Args:
219
+ new_host: A new Room2D object that hosts these properties.
220
+ If None, the properties will be duplicated with the same host.
221
+ """
222
+ _host = new_host or self._host
223
+ return Room2DRadianceProperties(
224
+ _host, self._modifier_set, self._grid_parameters[:])
225
+
226
+ def ToString(self):
227
+ return self.__repr__()
228
+
229
+ def __repr__(self):
230
+ return 'Room2D Radiance Properties: {}'.format(self.host.identifier)