dragonfly-radiance 0.4.121__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,163 @@
1
+ # coding=utf-8
2
+ """Building Radiance Properties."""
3
+ from honeybee_radiance.modifierset import ModifierSet
4
+ from honeybee_radiance.lib.modifiersets import generic_modifier_set_visible
5
+
6
+ import dragonfly_radiance.gridpar as sg_par
7
+
8
+
9
+ class BuildingRadianceProperties(object):
10
+ """Radiance Properties for Dragonfly Building.
11
+
12
+ Args:
13
+ host: A dragonfly_core Building object that hosts these properties.
14
+ modifier_set: A honeybee ModifierSet object to specify all default modifiers
15
+ for the Story geometry. If None, it will be the honeybee default modifier
16
+ set, which is only representative of typical indoor conditions in
17
+ the visible spectrum. (Default: None).
18
+
19
+ Properties:
20
+ * host
21
+ * modifier_set
22
+ """
23
+ __slots__ = ('_host', '_modifier_set')
24
+
25
+ def __init__(self, host, modifier_set=None):
26
+ """Initialize Building radiance properties."""
27
+ self._host = host
28
+ self.modifier_set = modifier_set
29
+
30
+ @property
31
+ def host(self):
32
+ """Get the Building object hosting these properties."""
33
+ return self._host
34
+
35
+ @property
36
+ def modifier_set(self):
37
+ """Get or set the Building ModifierSet object.
38
+
39
+ If not set, it will be the Honeybee default generic ModifierSet.
40
+ """
41
+ if self._modifier_set is not None: # set by the user
42
+ return self._modifier_set
43
+ else:
44
+ return generic_modifier_set_visible
45
+
46
+ @modifier_set.setter
47
+ def modifier_set(self, value):
48
+ if value is not None:
49
+ assert isinstance(value, ModifierSet), \
50
+ 'Expected ModifierSet. Got {}'.format(type(value))
51
+ value.lock() # lock in case modifier set has multiple references
52
+ self._modifier_set = value
53
+
54
+ def add_grid_parameter(self, grid_par):
55
+ """Add a GridParameter to all of the children Room2Ds of this Building.
56
+
57
+ Args:
58
+ grid_par: A radiance GridParameter object to assign to all children Room2Ds.
59
+ """
60
+ for room_2d in self.host.unique_room_2ds:
61
+ room_2d.properties.radiance.add_grid_parameter(grid_par)
62
+
63
+ def make_plenums(self, room_ids):
64
+ """Turn Room2Ds on the host Building into plenums with no inside grid parameters.
65
+
66
+ Grid parameters for exterior facades will be kept. This is useful to
67
+ appropriately assign properties for closets, underfloor spaces, and
68
+ drop ceilings.
69
+
70
+ Args:
71
+ room_ids: A list of identifiers for Room2Ds on this Building to be
72
+ converted into plenums.
73
+ """
74
+ room_ids = set(room_ids)
75
+ for rm in self.host.unique_room_2ds:
76
+ if rm.identifier in room_ids:
77
+ rm.properties.radiance.make_plenum()
78
+
79
+ @classmethod
80
+ def from_dict(cls, data, host):
81
+ """Create BuildingRadianceProperties from a dictionary.
82
+
83
+ Note that the dictionary must be a non-abridged version for this
84
+ classmethod to work.
85
+
86
+ Args:
87
+ data: A dictionary representation of BuildingRadianceProperties.
88
+ host: A Building object that hosts these properties.
89
+ """
90
+ assert data['type'] == 'BuildingRadianceProperties', \
91
+ 'Expected BuildingRadianceProperties. Got {}.'.format(data['type'])
92
+
93
+ new_prop = cls(host)
94
+ if 'modifier_set' in data and data['modifier_set'] is not None:
95
+ new_prop.modifier_set = ModifierSet.from_dict(data['modifier_set'])
96
+
97
+ return new_prop
98
+
99
+ def apply_properties_from_dict(self, abridged_data, modifier_sets):
100
+ """Apply properties from a BuildingRadiancePropertiesAbridged dictionary.
101
+
102
+ Args:
103
+ abridged_data: A BuildingRadiancePropertiesAbridged dictionary (typically
104
+ coming from a Model).
105
+ modifier_sets: A dictionary of ModifierSets with identifiers
106
+ of the sets as keys, which will be used to re-assign modifier_sets.
107
+ """
108
+ if 'modifier_set' in abridged_data and \
109
+ abridged_data['modifier_set'] is not None:
110
+ self.modifier_set = modifier_sets[abridged_data['modifier_set']]
111
+
112
+ def apply_properties_from_geojson_dict(self, data):
113
+ """Apply properties from a geoJSON dictionary.
114
+
115
+ Args:
116
+ data: A dictionary representation of a geoJSON feature properties.
117
+ Specifically, this should be the "properties" key describing
118
+ a Polygon or MultiPolygon object.
119
+ """
120
+ # assign the construction set based on climate zone
121
+ if 'grid_parameters' in data and data['grid_parameters'] is not None:
122
+ for gp in data['grid_parameters']:
123
+ try:
124
+ g_class = getattr(sg_par, gp['type'])
125
+ except AttributeError:
126
+ raise ValueError(
127
+ 'GridParameter "{}" is not recognized.'.format(gp['type']))
128
+ self.add_grid_parameter(g_class.from_dict(gp))
129
+
130
+ def to_dict(self, abridged=False):
131
+ """Return Building Radiance properties as a dictionary.
132
+
133
+ Args:
134
+ abridged: Boolean for whether the full dictionary of the Building should
135
+ be written (False) or just the identifier of the the individual
136
+ properties (True). Default: False.
137
+ """
138
+ base = {'radiance': {}}
139
+ base['radiance']['type'] = 'BuildingRadianceProperties' if not \
140
+ abridged else 'BuildingRadiancePropertiesAbridged'
141
+
142
+ # write the ModifierSet into the dictionary
143
+ if self._modifier_set is not None:
144
+ base['radiance']['modifier_set'] = \
145
+ self._modifier_set.identifier if abridged else \
146
+ self._modifier_set.to_dict()
147
+
148
+ return base
149
+
150
+ def duplicate(self, new_host=None):
151
+ """Get a copy of this object.
152
+
153
+ new_host: A new Building object that hosts these properties.
154
+ If None, the properties will be duplicated with the same host.
155
+ """
156
+ _host = new_host or self._host
157
+ return BuildingRadianceProperties(_host, self._modifier_set)
158
+
159
+ def ToString(self):
160
+ return self.__repr__()
161
+
162
+ def __repr__(self):
163
+ return 'Building Radiance Properties: {}'.format(self.host.identifier)
@@ -0,0 +1,139 @@
1
+ # coding=utf-8
2
+ """Context Shade Radiance Properties."""
3
+ from honeybee.shade import Shade
4
+ from honeybee_radiance.modifier import Modifier
5
+ from honeybee_radiance.properties.shade import ShadeRadianceProperties
6
+ from honeybee_radiance.properties.shademesh import ShadeMeshRadianceProperties
7
+ from honeybee_radiance.mutil import dict_to_modifier # imports all modifiers classes
8
+ from honeybee_radiance.lib.modifiers import generic_context
9
+
10
+
11
+ class ContextShadeRadianceProperties(object):
12
+ """Radiance Properties for Dragonfly ContextShade.
13
+
14
+ Args:
15
+ host_shade: A dragonfly_core ContextShade object that hosts these properties.
16
+ modifier: An optional Modifier object to set the reflectance and specularity
17
+ of the ContextShade. The default is a completely diffuse modifier
18
+ with 0.2 reflectance.
19
+
20
+ Properties:
21
+ * host
22
+ * modifier
23
+ * is_modifier_set_by_user
24
+ """
25
+
26
+ __slots__ = ('_host', '_modifier')
27
+
28
+ def __init__(self, host_shade, modifier=None):
29
+ """Initialize ContextShade radiance properties."""
30
+ self._host = host_shade
31
+ self.modifier = modifier
32
+
33
+ @property
34
+ def host(self):
35
+ """Get the Shade object hosting these properties."""
36
+ return self._host
37
+
38
+ @property
39
+ def modifier(self):
40
+ """Get or set a Modifier for the context shade."""
41
+ if self._modifier: # set by user
42
+ return self._modifier
43
+ else:
44
+ return generic_context
45
+
46
+ @modifier.setter
47
+ def modifier(self, value):
48
+ if value is not None:
49
+ assert isinstance(value, Modifier), \
50
+ 'Expected Modifier. Got {}.'.format(type(value))
51
+ value.lock() # lock editing in case modifier has multiple references
52
+ self._modifier = value
53
+
54
+ @property
55
+ def is_modifier_set_by_user(self):
56
+ """Boolean noting if modifier is user-set."""
57
+ return self._modifier is not None
58
+
59
+ @classmethod
60
+ def from_dict(cls, data, host):
61
+ """Create ContextShadeRadianceProperties from a dictionary.
62
+
63
+ Note that the dictionary must be a non-abridged version for this
64
+ classmethod to work.
65
+
66
+ Args:
67
+ data: A dictionary representation of ContextShadeRadianceProperties.
68
+ host: A ContextShade object that hosts these properties.
69
+ """
70
+ assert data['type'] == 'ContextShadeRadianceProperties', \
71
+ 'Expected ContextShadeRadianceProperties. Got {}.'.format(data['type'])
72
+
73
+ new_prop = cls(host)
74
+ if 'modifier' in data and data['modifier'] is not None:
75
+ new_prop.modifier = dict_to_modifier(data['modifier'])
76
+ return new_prop
77
+
78
+ def apply_properties_from_dict(self, abridged_data, modifiers):
79
+ """Apply properties from a ContextShadeRadiancePropertiesAbridged dictionary.
80
+
81
+ Args:
82
+ abridged_data: A ContextShadeRadiancePropertiesAbridged dictionary (typically
83
+ coming from a Model).
84
+ modifiers: A dictionary of modifiers with modifiers identifiers
85
+ as keys, which will be used to re-assign modifiers.
86
+ """
87
+ if 'modifier' in abridged_data and abridged_data['modifier'] is not None:
88
+ self.modifier = modifiers[abridged_data['modifier']]
89
+
90
+ def to_dict(self, abridged=False):
91
+ """Return radiance properties as a dictionary.
92
+
93
+ Args:
94
+ abridged: Boolean to note whether the full dictionary describing the
95
+ object should be returned (False) or just an abridged version (True).
96
+ Default: False.
97
+ """
98
+ base = {'radiance': {}}
99
+ base['radiance']['type'] = 'ContextShadeRadianceProperties' if not \
100
+ abridged else 'ContextShadeRadiancePropertiesAbridged'
101
+ if self._modifier is not None:
102
+ base['radiance']['modifier'] = self._modifier.identifier if abridged \
103
+ else self._modifier.to_dict()
104
+ return base
105
+
106
+ def to_honeybee(self, new_host):
107
+ """Get a honeybee version of this object.
108
+
109
+ Args:
110
+ new_host: A honeybee-core Shade or ShadeMesh object that will host
111
+ these properties.
112
+ """
113
+ return ShadeRadianceProperties(new_host, self._modifier) \
114
+ if isinstance(new_host, Shade) else \
115
+ ShadeMeshRadianceProperties(new_host, self._modifier)
116
+
117
+ def from_honeybee(self, hb_properties):
118
+ """Transfer radiance attributes from a Honeybee Shade to Dragonfly ContextShade.
119
+
120
+ Args:
121
+ hb_properties: The ShadeRadianceProperties of the honeybee Shade
122
+ that is being translated to a Dragonfly ContextShade.
123
+ """
124
+ self._modifier = hb_properties._modifier
125
+
126
+ def duplicate(self, new_host=None):
127
+ """Get a copy of this object.
128
+
129
+ new_host: A new ContextShade object that hosts these properties.
130
+ If None, the properties will be duplicated with the same host.
131
+ """
132
+ _host = new_host or self._host
133
+ return ContextShadeRadianceProperties(_host, self._modifier)
134
+
135
+ def ToString(self):
136
+ return self.__repr__()
137
+
138
+ def __repr__(self):
139
+ return 'Context Shade Radiance Properties: {}'.format(self.host.identifier)