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,9 @@
1
+ """dragonfly-radiance library."""
2
+ from honeybee.logutil import get_logger
3
+
4
+
5
+ # load all functions that extends dragonfly core library
6
+ import dragonfly_radiance._extend_dragonfly
7
+
8
+
9
+ logger = get_logger(__name__, filename='dragonfly-radiance.log')
@@ -0,0 +1,4 @@
1
+ from dragonfly_radiance.cli import radiance
2
+
3
+ if __name__ == '__main__':
4
+ radiance()
@@ -0,0 +1,56 @@
1
+ # coding=utf-8
2
+ from dragonfly.properties import ModelProperties, BuildingProperties, StoryProperties, \
3
+ Room2DProperties, ContextShadeProperties
4
+
5
+ from .properties.model import ModelRadianceProperties
6
+ from .properties.building import BuildingRadianceProperties
7
+ from .properties.story import StoryRadianceProperties
8
+ from .properties.room2d import Room2DRadianceProperties
9
+ from .properties.context import ContextShadeRadianceProperties
10
+
11
+
12
+ # set a hidden radiance attribute on each core geometry Property class to None
13
+ # define methods to produce radiance property instances on each Property instance
14
+ ModelProperties._radiance = None
15
+ BuildingProperties._radiance = None
16
+ StoryProperties._radiance = None
17
+ Room2DProperties._radiance = None
18
+ ContextShadeProperties._radiance = None
19
+
20
+
21
+ def model_radiance_properties(self):
22
+ if self._radiance is None:
23
+ self._radiance = ModelRadianceProperties(self.host)
24
+ return self._radiance
25
+
26
+
27
+ def building_radiance_properties(self):
28
+ if self._radiance is None:
29
+ self._radiance = BuildingRadianceProperties(self.host)
30
+ return self._radiance
31
+
32
+
33
+ def story_radiance_properties(self):
34
+ if self._radiance is None:
35
+ self._radiance = StoryRadianceProperties(self.host)
36
+ return self._radiance
37
+
38
+
39
+ def room2d_radiance_properties(self):
40
+ if self._radiance is None:
41
+ self._radiance = Room2DRadianceProperties(self.host)
42
+ return self._radiance
43
+
44
+
45
+ def context_radiance_properties(self):
46
+ if self._radiance is None:
47
+ self._radiance = ContextShadeRadianceProperties(self.host)
48
+ return self._radiance
49
+
50
+
51
+ # add radiance property methods to the Properties classes
52
+ ModelProperties.radiance = property(model_radiance_properties)
53
+ BuildingProperties.radiance = property(building_radiance_properties)
54
+ StoryProperties.radiance = property(story_radiance_properties)
55
+ Room2DProperties.radiance = property(room2d_radiance_properties)
56
+ ContextShadeProperties.radiance = property(context_radiance_properties)
@@ -0,0 +1,18 @@
1
+ """dragonfly-radiance commands which will be added to the dragonfly CLI."""
2
+ import click
3
+
4
+ from dragonfly.cli import main
5
+ from .translate import translate
6
+
7
+
8
+ # command group for all radiance extension commands.
9
+ @click.group(help='dragonfly radiance commands.')
10
+ def radiance():
11
+ pass
12
+
13
+
14
+ # add sub-commands for radiance
15
+ radiance.add_command(translate)
16
+
17
+ # add radiance sub-commands to dragonfly CLI
18
+ main.add_command(radiance)
@@ -0,0 +1,334 @@
1
+ """dragonfly radiance translation commands."""
2
+ import click
3
+ import sys
4
+ import os
5
+ import logging
6
+ import zipfile
7
+
8
+ from ladybug.futil import unzip_file
9
+ from ladybug.commandutil import process_content_to_output
10
+ from dragonfly.model import Model
11
+
12
+
13
+ _logger = logging.getLogger(__name__)
14
+
15
+
16
+ @click.group(help='Commands for translating Dragonfly files to/from Radiance.')
17
+ def translate():
18
+ pass
19
+
20
+
21
+ @translate.command('model-to-rad-folder')
22
+ @click.argument('model-file', type=click.Path(
23
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
24
+ @click.option(
25
+ '--multiplier/--full-geometry', ' /-fg', help='Flag to note if the '
26
+ 'multipliers on each Building story will be passed along to the '
27
+ 'generated Honeybee Room objects or if full geometry objects should be '
28
+ 'written for each story in the building.', default=True, show_default=True
29
+ )
30
+ @click.option(
31
+ '--plenum/--no-plenum', '-p/-np', help='Flag to indicate whether '
32
+ 'ceiling/floor plenum depths assigned to Room2Ds should generate '
33
+ 'distinct 3D Rooms in the translation.', default=True, show_default=True
34
+ )
35
+ @click.option(
36
+ '--no-ceil-adjacency/--ceil-adjacency', ' /-a', help='Flag to indicate '
37
+ 'whether adjacencies should be solved between interior stories when '
38
+ 'Room2Ds perfectly match one another in their floor plate. This ensures '
39
+ 'that Surface boundary conditions are used instead of Adiabatic ones. '
40
+ 'Note that this input has no effect when the object-per-model is Story.',
41
+ default=True, show_default=True
42
+ )
43
+ @click.option(
44
+ '--folder', help='Folder into which the model Radiance '
45
+ 'folders will be written. If None, the files will be output in the '
46
+ 'same location as the model_file.', default=None, show_default=True
47
+ )
48
+ @click.option(
49
+ '--grid', '-g', multiple=True, help='List of grids to be included in folder. By '
50
+ 'default all the sensor grids will be exported. You can also use wildcards here. '
51
+ 'For instance first_floor_* will select all the sensor grids that has an identifier '
52
+ 'that starts with first_floor. To filter based on group_identifier use /. For '
53
+ 'example daylight/* will select all the grids that belong to daylight group.')
54
+ @click.option(
55
+ '--view', '-v', multiple=True, help='List of views to be included in folder. By '
56
+ 'default all the views will be exported. You can also use wildcards to filter '
57
+ 'multiple views. For instance first_floor_* will select all the views that has an '
58
+ 'identifier that starts with first_floor. To filter based on group_identifier use '
59
+ '/. For example daylight/* will select all the views that belong to daylight group.')
60
+ @click.option(
61
+ '--full-match/--no-full-match', help='Flag to note whether the grids and'
62
+ 'views should be filtered by their identifiers as full matches. Setting '
63
+ 'this to True indicates that wildcard symbols will not be used in the '
64
+ 'filtering of grids and views.', default=False, show_default=True)
65
+ @click.option(
66
+ '--config-file', '-c', help='An optional config file path to modify the '
67
+ 'default folder names. If None, folder.cfg in honeybee-radiance-folder '
68
+ 'will be used.', default=None, show_default=True)
69
+ @click.option(
70
+ '--minimal/--maximal', '-min/-max', help='Flag to note whether the radiance strings '
71
+ 'should be written in a minimal format (with spaces instead of line '
72
+ 'breaks).', default=False, show_default=True)
73
+ @click.option(
74
+ '--no-grid-check/--grid-check', ' /-gc', help='Flag to note whether the '
75
+ 'model should be checked for the presence of sensor grids. If the check '
76
+ 'is set and the model has no grids, an explicit error will be raised.',
77
+ default=True, show_default=True)
78
+ @click.option(
79
+ '--no-view-check/--view-check', ' /-vc', help='Flag to note whether the '
80
+ 'model should be checked for the presence of views. If the check '
81
+ 'is set and the model has no views, an explicit error will be raised.',
82
+ default=True, show_default=True)
83
+ @click.option(
84
+ '--create-grids', '-cg', default=False, show_default=True, is_flag=True,
85
+ help='Flag to note whether sensor grids should be created if none exists. '
86
+ 'This will only create sensor grids for rooms if there are no sensor grids '
87
+ 'in the model.'
88
+ )
89
+ @click.option(
90
+ '--log-file', help='Optional log file to output the path of the radiance '
91
+ 'folder generated from the model. By default this will be printed '
92
+ 'to stdout', type=click.File('w'), default='-')
93
+ def model_to_rad_folder_cli(
94
+ model_file, multiplier, plenum, no_ceil_adjacency,
95
+ folder, view, grid, full_match, config_file, minimal,
96
+ no_grid_check, no_view_check, create_grids, log_file
97
+ ):
98
+ """Translate a Model file into a Radiance Folder.
99
+
100
+ \b
101
+ Args:
102
+ model_file: Full path to a Model JSON file (DFJSON) or a Model
103
+ pkl (DFpkl) file. This can also be a zipped version of a Radiance
104
+ folder, in which case this command will simply unzip the file
105
+ into the --folder and no other operations will be performed on it.
106
+ """
107
+ try:
108
+ full_geometry = not multiplier
109
+ no_plenum = not plenum
110
+ ceil_adjacency = not no_ceil_adjacency
111
+ grid_check = not no_grid_check
112
+ view_check = not no_view_check
113
+ model_to_rad_folder(
114
+ model_file, full_geometry, no_plenum, ceil_adjacency,
115
+ folder, view, grid, full_match, config_file,
116
+ minimal, grid_check, view_check, create_grids, log_file)
117
+ except Exception as e:
118
+ _logger.exception('Model translation failed.\n{}'.format(e))
119
+ sys.exit(1)
120
+ else:
121
+ sys.exit(0)
122
+
123
+
124
+ def model_to_rad_folder(
125
+ model_file, full_geometry=False, no_plenum=False, ceil_adjacency=False,
126
+ folder=None, view=None, grid=None, full_match=False, config_file=None,
127
+ minimal=False, grid_check=False, view_check=False, create_grids=False, log_file=None,
128
+ multiplier=True, plenum=True, no_ceil_adjacency=True,
129
+ no_full_match=True, maximal=True, no_grid_check=False, no_view_check=False,
130
+ ):
131
+ """Translate a Model file into a Radiance Folder.
132
+
133
+ Args:
134
+ model_file: Full path to a Model JSON file (DFJSON) or a Model
135
+ pkl (DFpkl) file. This can also be a zipped version of a Radiance
136
+ folder, in which case this command will simply unzip the file
137
+ into the --folder and no other operations will be performed on it.
138
+ folder: Folder into which the model Radiance folders will be written.
139
+ If None, the files will be output in the same location as the model_file.
140
+ view: List of grids to be included in folder. By default all the sensor
141
+ grids will be exported. You can also use wildcards here. For instance
142
+ first_floor_* will select all the sensor grids that has an identifier
143
+ that starts with first_floor. To filter based on group_identifier
144
+ use /. For example daylight/* will select all the grids that belong
145
+ to daylight group. (Default: None).
146
+ grid: List of views to be included in folder. By default all the views
147
+ will be exported. You can also use wildcards to filter multiple views.
148
+ For instance first_floor_* will select all the views that has an
149
+ identifier that starts with first_floor. To filter based on
150
+ group_identifier use /. For example daylight/* will select all the
151
+ views that belong to daylight group. (Default: None).
152
+ full_match: Boolean to note whether the grids and views should be
153
+ filtered by their identifiers as full matches. Setting this to
154
+ True indicates that wildcard symbols will not be used in the
155
+ filtering of grids and views. (Default: False).
156
+ config_file: An optional config file path to modify the default folder
157
+ names. If None, folder.cfg in honeybee-radiance-folder will be used.
158
+ minimal: Boolean to note whether the radiance strings should be written
159
+ in a minimal format (with spaces instead of line breaks). (Default: False).
160
+ grid_check: Boolean to note whether the model should be checked for the
161
+ presence of sensor grids. If the check is set and the model has no
162
+ grids, an explicit error will be raised. (Default: False).
163
+ view_check: Boolean to note whether the model should be checked for the
164
+ presence of views. If the check is set and the model has no views,
165
+ an explicit error will be raised. (Default: False).
166
+ log_file: Optional log file to output the path of the radiance folder
167
+ generated from the model. If None, it will be returned from this method.
168
+ """
169
+ # set the default folder if it's not specified
170
+ if folder is None:
171
+ folder = os.path.dirname(os.path.abspath(model_file))
172
+
173
+ # first check to see if the model_file is a zipped radiance folder
174
+ if zipfile.is_zipfile(model_file):
175
+ unzip_file(model_file, folder)
176
+ if log_file is None:
177
+ return folder
178
+ else:
179
+ log_file.write(folder)
180
+ else:
181
+ # re-serialize the Dragonfly Model
182
+ model = Model.from_file(model_file)
183
+
184
+ # convert Dragonfly Model to Honeybee
185
+ multiplier = not full_geometry
186
+ hb_models = model.to_honeybee(
187
+ object_per_model='District', use_multiplier=multiplier,
188
+ exclude_plenums=no_plenum, solve_ceiling_adjacencies=ceil_adjacency)
189
+ model = hb_models[0]
190
+
191
+ if create_grids:
192
+ if not model.properties.radiance.has_sensor_grids:
193
+ sensor_grids = []
194
+
195
+ unit_conversion = {
196
+ 'Meters': 1,
197
+ 'Millimeters': 0.001,
198
+ 'Centimeters': 0.01,
199
+ 'Feet': 0.3048,
200
+ 'Inches': 0.0254
201
+ }
202
+
203
+ if model.units in ['Meters', 'Millimeters', 'Centimeters']:
204
+ grid_size = 0.5 / unit_conversion[model.units]
205
+ offset = 0.76 / unit_conversion[model.units]
206
+ wall_offset = 0.3 / unit_conversion[model.units]
207
+ else: # assume IP units
208
+ grid_size = 2 * 0.3048 / unit_conversion[model.units]
209
+ offset = 2.5 * 0.3048 / unit_conversion[model.units]
210
+ wall_offset = 1 * 0.3048 / unit_conversion[model.units]
211
+
212
+ for room in model.rooms:
213
+ sensor_grids.append(room.properties.radiance.generate_sensor_grid(
214
+ grid_size, offset=offset, wall_offset=wall_offset))
215
+ model.properties.radiance.sensor_grids = sensor_grids
216
+
217
+ if grid_check and len(model.properties.radiance.sensor_grids) == 0:
218
+ raise ValueError('Model contains no sensor grids. These are required.')
219
+ if view_check and len(model.properties.radiance.views) == 0:
220
+ raise ValueError('Model contains no views These are required.')
221
+
222
+ # translate the model to a radiance folder
223
+ rad_fold = model.to.rad_folder(
224
+ model, folder, config_file, minimal, views=view, grids=grid,
225
+ full_match=full_match
226
+ )
227
+
228
+ if log_file is None:
229
+ return rad_fold
230
+ else:
231
+ log_file.write(rad_fold)
232
+
233
+
234
+ @translate.command('model-to-rad')
235
+ @click.argument('model-file', type=click.Path(
236
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
237
+ @click.option('--multiplier/--full-geometry', ' /-fg', help='Flag to note if the '
238
+ 'multipliers on each Building story will be passed along to the '
239
+ 'generated Honeybee Room objects or if full geometry objects should be '
240
+ 'written for each story in the building.', default=True, show_default=True)
241
+ @click.option('--plenum/--no-plenum', '-p/-np', help='Flag to indicate whether '
242
+ 'ceiling/floor plenum depths assigned to Room2Ds should generate '
243
+ 'distinct 3D Rooms in the translation.', default=True, show_default=True)
244
+ @click.option('--no-ceil-adjacency/--ceil-adjacency', ' /-a', help='Flag to indicate '
245
+ 'whether adjacencies should be solved between interior stories when '
246
+ 'Room2Ds perfectly match one another in their floor plate. This ensures '
247
+ 'that Surface boundary conditions are used instead of Adiabatic ones. '
248
+ 'Note that this input has no effect when the object-per-model is Story.',
249
+ default=True, show_default=True)
250
+ @click.option('--blk', help='Boolean to note whether the "blacked out" version '
251
+ 'of the geometry should be output, which is useful for direct studies '
252
+ 'and isolation studies of individual apertures.',
253
+ default=False, show_default=True)
254
+ @click.option('--minimal/--maximal', help='Flag to note whether the radiance strings '
255
+ 'should be written in a minimal format (with spaces instead of line '
256
+ 'breaks).', default=False, show_default=True)
257
+ @click.option('--output-file', '-f', help='Optional Rad file to output the Rad string '
258
+ 'of the translation. By default this will be printed out to stdout',
259
+ type=click.File('w'), default='-', show_default=True)
260
+ def model_to_rad_cli(model_file, multiplier, plenum, no_ceil_adjacency,
261
+ blk, minimal, output_file):
262
+ """Translate a Dragonfly Model file to a Radiance string.
263
+
264
+ The resulting string will include all geometry and all modifiers.
265
+
266
+ \b
267
+ Args:
268
+ model_file: Full path to a Dragonfly Model JSON or Pkl file.
269
+ """
270
+ try:
271
+ full_geometry = not multiplier
272
+ no_plenum = not plenum
273
+ ceil_adjacency = not no_ceil_adjacency
274
+ model_to_rad(model_file, full_geometry, no_plenum, ceil_adjacency,
275
+ blk, minimal, output_file)
276
+ except Exception as e:
277
+ _logger.exception('Model translation failed.\n{}\n'.format(e))
278
+ sys.exit(1)
279
+ else:
280
+ sys.exit(0)
281
+
282
+
283
+ def model_to_rad(
284
+ model_file, full_geometry=False, no_plenum=False, ceil_adjacency=False,
285
+ blk=False, minimal=False, output_file=None,
286
+ multiplier=True, plenum=True, no_ceil_adjacency=True, maximal=True
287
+ ):
288
+ """Translate a Model file to a Radiance string.
289
+
290
+ The resulting strings will include all geometry (Rooms, Faces, Shades, Apertures,
291
+ Doors) and all modifiers. However, it does not include any states for dynamic
292
+ geometry and will only write the default state for each dynamic object. To
293
+ correctly account for dynamic objects, model-to-rad-folder should be used.
294
+
295
+ Args:
296
+ model_file: Full path to a Model JSON file (DFJSON) or a Model pkl (DFpkl) file.
297
+ full_geometry: Boolean to note if the multipliers on each Building story
298
+ will be passed along to the generated Honeybee Room objects or if
299
+ full geometry objects should be written for each story in the
300
+ building. (Default: False).
301
+ no_plenum: Boolean to indicate whether ceiling/floor plenum depths
302
+ assigned to Room2Ds should generate distinct 3D Rooms in the
303
+ translation. (Default: False).
304
+ ceil_adjacency: Boolean to indicate whether adjacencies should be solved
305
+ between interior stories when Room2Ds perfectly match one another
306
+ in their floor plate. This ensures that Surface boundary conditions
307
+ are used instead of Adiabatic ones. Note that this input has no
308
+ effect when the object-per-model is Story. (Default: False).
309
+ blk: Boolean to note whether the "blacked out" version of the geometry
310
+ should be output, which is useful for direct studies and isolation
311
+ studies of individual apertures.
312
+ minimal: Boolean to note whether the radiance strings should be written
313
+ in a minimal format (with spaces instead of line breaks).
314
+ output_file: Optional RAD file to output the RAD string of the translation.
315
+ If None, the string will be returned from this method. (Default: None).
316
+ """
317
+ # re-serialize the Dragonfly Model
318
+ model = Model.from_file(model_file)
319
+
320
+ # convert Dragonfly Model to Honeybee
321
+ multiplier = not full_geometry
322
+ hb_models = model.to_honeybee(
323
+ object_per_model='District', use_multiplier=multiplier,
324
+ exclude_plenums=no_plenum, solve_ceiling_adjacencies=ceil_adjacency)
325
+ hb_model = hb_models[0]
326
+
327
+ # create the strings for modifiers and geometry
328
+ model_str, modifier_str = hb_model.to.rad(hb_model, blk, minimal)
329
+ rad_str_list = ['# ======== MODEL MODIFIERS ========', modifier_str,
330
+ '# ======== MODEL GEOMETRY ========', model_str]
331
+ rad_str = '\n\n'.join(rad_str_list)
332
+
333
+ # write out the rad string
334
+ return process_content_to_output(rad_str, output_file)