honeybee-energy 1.116.64__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 honeybee-energy might be problematic. Click here for more details.

Files changed (162) hide show
  1. honeybee_energy/__init__.py +24 -0
  2. honeybee_energy/__main__.py +4 -0
  3. honeybee_energy/_extend_honeybee.py +145 -0
  4. honeybee_energy/altnumber.py +21 -0
  5. honeybee_energy/baseline/__init__.py +2 -0
  6. honeybee_energy/baseline/create.py +608 -0
  7. honeybee_energy/baseline/data/__init__.py +1 -0
  8. honeybee_energy/baseline/data/constructions.csv +64 -0
  9. honeybee_energy/baseline/data/fen_ratios.csv +15 -0
  10. honeybee_energy/baseline/data/lpd_building.csv +21 -0
  11. honeybee_energy/baseline/data/pci_2016.csv +22 -0
  12. honeybee_energy/baseline/data/pci_2019.csv +22 -0
  13. honeybee_energy/baseline/data/pci_2022.csv +22 -0
  14. honeybee_energy/baseline/data/shw.csv +21 -0
  15. honeybee_energy/baseline/pci.py +512 -0
  16. honeybee_energy/baseline/result.py +371 -0
  17. honeybee_energy/boundarycondition.py +128 -0
  18. honeybee_energy/cli/__init__.py +69 -0
  19. honeybee_energy/cli/baseline.py +475 -0
  20. honeybee_energy/cli/edit.py +327 -0
  21. honeybee_energy/cli/lib.py +1154 -0
  22. honeybee_energy/cli/result.py +810 -0
  23. honeybee_energy/cli/setconfig.py +124 -0
  24. honeybee_energy/cli/settings.py +569 -0
  25. honeybee_energy/cli/simulate.py +380 -0
  26. honeybee_energy/cli/translate.py +1601 -0
  27. honeybee_energy/cli/validate.py +224 -0
  28. honeybee_energy/config.json +11 -0
  29. honeybee_energy/config.py +842 -0
  30. honeybee_energy/construction/__init__.py +1 -0
  31. honeybee_energy/construction/_base.py +374 -0
  32. honeybee_energy/construction/air.py +325 -0
  33. honeybee_energy/construction/dictutil.py +89 -0
  34. honeybee_energy/construction/dynamic.py +607 -0
  35. honeybee_energy/construction/opaque.py +460 -0
  36. honeybee_energy/construction/shade.py +319 -0
  37. honeybee_energy/construction/window.py +1096 -0
  38. honeybee_energy/construction/windowshade.py +847 -0
  39. honeybee_energy/constructionset.py +1655 -0
  40. honeybee_energy/dictutil.py +56 -0
  41. honeybee_energy/generator/__init__.py +5 -0
  42. honeybee_energy/generator/loadcenter.py +204 -0
  43. honeybee_energy/generator/pv.py +535 -0
  44. honeybee_energy/hvac/__init__.py +21 -0
  45. honeybee_energy/hvac/_base.py +124 -0
  46. honeybee_energy/hvac/_template.py +270 -0
  47. honeybee_energy/hvac/allair/__init__.py +22 -0
  48. honeybee_energy/hvac/allair/_base.py +349 -0
  49. honeybee_energy/hvac/allair/furnace.py +168 -0
  50. honeybee_energy/hvac/allair/psz.py +131 -0
  51. honeybee_energy/hvac/allair/ptac.py +163 -0
  52. honeybee_energy/hvac/allair/pvav.py +109 -0
  53. honeybee_energy/hvac/allair/vav.py +128 -0
  54. honeybee_energy/hvac/detailed.py +337 -0
  55. honeybee_energy/hvac/doas/__init__.py +28 -0
  56. honeybee_energy/hvac/doas/_base.py +345 -0
  57. honeybee_energy/hvac/doas/fcu.py +127 -0
  58. honeybee_energy/hvac/doas/radiant.py +329 -0
  59. honeybee_energy/hvac/doas/vrf.py +81 -0
  60. honeybee_energy/hvac/doas/wshp.py +91 -0
  61. honeybee_energy/hvac/heatcool/__init__.py +23 -0
  62. honeybee_energy/hvac/heatcool/_base.py +177 -0
  63. honeybee_energy/hvac/heatcool/baseboard.py +61 -0
  64. honeybee_energy/hvac/heatcool/evapcool.py +72 -0
  65. honeybee_energy/hvac/heatcool/fcu.py +92 -0
  66. honeybee_energy/hvac/heatcool/gasunit.py +53 -0
  67. honeybee_energy/hvac/heatcool/radiant.py +269 -0
  68. honeybee_energy/hvac/heatcool/residential.py +77 -0
  69. honeybee_energy/hvac/heatcool/vrf.py +54 -0
  70. honeybee_energy/hvac/heatcool/windowac.py +70 -0
  71. honeybee_energy/hvac/heatcool/wshp.py +62 -0
  72. honeybee_energy/hvac/idealair.py +699 -0
  73. honeybee_energy/internalmass.py +310 -0
  74. honeybee_energy/lib/__init__.py +1 -0
  75. honeybee_energy/lib/_loadconstructions.py +194 -0
  76. honeybee_energy/lib/_loadconstructionsets.py +117 -0
  77. honeybee_energy/lib/_loadmaterials.py +83 -0
  78. honeybee_energy/lib/_loadprogramtypes.py +125 -0
  79. honeybee_energy/lib/_loadschedules.py +87 -0
  80. honeybee_energy/lib/_loadtypelimits.py +64 -0
  81. honeybee_energy/lib/constructions.py +207 -0
  82. honeybee_energy/lib/constructionsets.py +95 -0
  83. honeybee_energy/lib/materials.py +67 -0
  84. honeybee_energy/lib/programtypes.py +125 -0
  85. honeybee_energy/lib/schedules.py +61 -0
  86. honeybee_energy/lib/scheduletypelimits.py +31 -0
  87. honeybee_energy/load/__init__.py +1 -0
  88. honeybee_energy/load/_base.py +190 -0
  89. honeybee_energy/load/daylight.py +397 -0
  90. honeybee_energy/load/dictutil.py +47 -0
  91. honeybee_energy/load/equipment.py +771 -0
  92. honeybee_energy/load/hotwater.py +543 -0
  93. honeybee_energy/load/infiltration.py +460 -0
  94. honeybee_energy/load/lighting.py +480 -0
  95. honeybee_energy/load/people.py +497 -0
  96. honeybee_energy/load/process.py +472 -0
  97. honeybee_energy/load/setpoint.py +816 -0
  98. honeybee_energy/load/ventilation.py +502 -0
  99. honeybee_energy/material/__init__.py +1 -0
  100. honeybee_energy/material/_base.py +166 -0
  101. honeybee_energy/material/dictutil.py +59 -0
  102. honeybee_energy/material/frame.py +367 -0
  103. honeybee_energy/material/gas.py +1087 -0
  104. honeybee_energy/material/glazing.py +854 -0
  105. honeybee_energy/material/opaque.py +1351 -0
  106. honeybee_energy/material/shade.py +1360 -0
  107. honeybee_energy/measure.py +472 -0
  108. honeybee_energy/programtype.py +723 -0
  109. honeybee_energy/properties/__init__.py +1 -0
  110. honeybee_energy/properties/aperture.py +333 -0
  111. honeybee_energy/properties/door.py +342 -0
  112. honeybee_energy/properties/extension.py +244 -0
  113. honeybee_energy/properties/face.py +274 -0
  114. honeybee_energy/properties/model.py +2621 -0
  115. honeybee_energy/properties/room.py +1747 -0
  116. honeybee_energy/properties/shade.py +314 -0
  117. honeybee_energy/properties/shademesh.py +262 -0
  118. honeybee_energy/reader.py +48 -0
  119. honeybee_energy/result/__init__.py +1 -0
  120. honeybee_energy/result/colorobj.py +648 -0
  121. honeybee_energy/result/emissions.py +290 -0
  122. honeybee_energy/result/err.py +101 -0
  123. honeybee_energy/result/eui.py +100 -0
  124. honeybee_energy/result/generation.py +160 -0
  125. honeybee_energy/result/loadbalance.py +890 -0
  126. honeybee_energy/result/match.py +202 -0
  127. honeybee_energy/result/osw.py +90 -0
  128. honeybee_energy/result/rdd.py +59 -0
  129. honeybee_energy/result/zsz.py +190 -0
  130. honeybee_energy/run.py +1573 -0
  131. honeybee_energy/schedule/__init__.py +1 -0
  132. honeybee_energy/schedule/day.py +626 -0
  133. honeybee_energy/schedule/dictutil.py +59 -0
  134. honeybee_energy/schedule/fixedinterval.py +1012 -0
  135. honeybee_energy/schedule/rule.py +619 -0
  136. honeybee_energy/schedule/ruleset.py +1867 -0
  137. honeybee_energy/schedule/typelimit.py +310 -0
  138. honeybee_energy/shw.py +315 -0
  139. honeybee_energy/simulation/__init__.py +1 -0
  140. honeybee_energy/simulation/control.py +214 -0
  141. honeybee_energy/simulation/daylightsaving.py +185 -0
  142. honeybee_energy/simulation/dictutil.py +51 -0
  143. honeybee_energy/simulation/output.py +646 -0
  144. honeybee_energy/simulation/parameter.py +606 -0
  145. honeybee_energy/simulation/runperiod.py +443 -0
  146. honeybee_energy/simulation/shadowcalculation.py +295 -0
  147. honeybee_energy/simulation/sizing.py +546 -0
  148. honeybee_energy/ventcool/__init__.py +5 -0
  149. honeybee_energy/ventcool/_crack_data.py +91 -0
  150. honeybee_energy/ventcool/afn.py +289 -0
  151. honeybee_energy/ventcool/control.py +269 -0
  152. honeybee_energy/ventcool/crack.py +126 -0
  153. honeybee_energy/ventcool/fan.py +493 -0
  154. honeybee_energy/ventcool/opening.py +365 -0
  155. honeybee_energy/ventcool/simulation.py +314 -0
  156. honeybee_energy/writer.py +1084 -0
  157. honeybee_energy-1.116.64.dist-info/METADATA +113 -0
  158. honeybee_energy-1.116.64.dist-info/RECORD +162 -0
  159. honeybee_energy-1.116.64.dist-info/WHEEL +5 -0
  160. honeybee_energy-1.116.64.dist-info/entry_points.txt +2 -0
  161. honeybee_energy-1.116.64.dist-info/licenses/LICENSE +661 -0
  162. honeybee_energy-1.116.64.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1601 @@
1
+ """honeybee energy translation commands."""
2
+ import click
3
+ import sys
4
+ import os
5
+ import logging
6
+ import json
7
+ import tempfile
8
+
9
+ from ladybug.commandutil import process_content_to_output
10
+ from ladybug.analysisperiod import AnalysisPeriod
11
+ from ladybug.epw import EPW
12
+ from ladybug.stat import STAT
13
+ from ladybug.futil import preparedir
14
+ from honeybee.model import Model
15
+ from honeybee.typing import clean_rad_string
16
+ from honeybee.config import folders as hb_folders
17
+
18
+ from honeybee_energy.simulation.parameter import SimulationParameter
19
+ from honeybee_energy.construction.dictutil import dict_to_construction
20
+ from honeybee_energy.construction.opaque import OpaqueConstruction
21
+ from honeybee_energy.construction.window import WindowConstruction
22
+ from honeybee_energy.schedule.dictutil import dict_to_schedule
23
+ from honeybee_energy.schedule.ruleset import ScheduleRuleset
24
+ from honeybee_energy.run import to_openstudio_sim_folder, run_osw, from_osm_osw, \
25
+ _parse_os_cli_failure, HB_OS_MSG
26
+ from honeybee_energy.writer import energyplus_idf_version, _preprocess_model_for_trace
27
+ from honeybee_energy.config import folders
28
+
29
+ _logger = logging.getLogger(__name__)
30
+
31
+
32
+ @click.group(help='Commands for translating Honeybee Models files.')
33
+ def translate():
34
+ pass
35
+
36
+
37
+ @translate.command('model-to-sim-folder')
38
+ @click.argument('model-file', type=click.Path(
39
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
40
+ @click.argument('epw-file', type=click.Path(
41
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
42
+ @click.option('--sim-par-json', '-sp', help='Full path to a honeybee energy '
43
+ 'SimulationParameter JSON that describes all of the settings for '
44
+ 'the simulation. This will be ignored if the input model-file is '
45
+ 'an OSM or IDF.', default=None, show_default=True,
46
+ type=click.Path(exists=False, file_okay=True, dir_okay=False,
47
+ resolve_path=True))
48
+ @click.option('--measures', '-m', help='Full path to a folder containing an OSW JSON '
49
+ 'be used as the base for the execution of the OpenStudio CLI. While this '
50
+ 'OSW can contain paths to measures that exist anywhere on the machine, '
51
+ 'the best practice is to copy the measures into this measures '
52
+ 'folder and use relative paths within the OSW. '
53
+ 'This makes it easier to move the inputs for this command from one '
54
+ 'machine to another.', default=None, show_default=True,
55
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
56
+ @click.option('--additional-string', '-as', help='An additional IDF text string to get '
57
+ 'appended to the IDF before simulation. The input should include '
58
+ 'complete EnergyPlus objects as a single string following the IDF '
59
+ 'format. This input can be used to include small EnergyPlus objects that '
60
+ 'are not currently supported by honeybee.', default=None, type=str)
61
+ @click.option('--additional-idf', '-ai', help='An IDF file with text to be '
62
+ 'appended before simulation. This input can be used to include '
63
+ 'large EnergyPlus objects that are not currently supported by honeybee.',
64
+ default=None, show_default=True,
65
+ type=click.Path(exists=False, file_okay=True, dir_okay=False,
66
+ resolve_path=True))
67
+ @click.option('--folder', '-f', help='Folder on this computer, into which the IDF '
68
+ 'and result files will be written. If None, the files will be output '
69
+ 'to the honeybee default simulation folder and placed in a project '
70
+ 'folder with the same name as the model-file.',
71
+ default=None, show_default=True,
72
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
73
+ @click.option('--log-file', '-log', help='Optional log file to output the paths of the '
74
+ 'generated files (osw, osm, idf) if successfully'
75
+ ' created. By default the list will be printed out to stdout',
76
+ type=click.File('w'), default='-', show_default=True)
77
+ def model_to_sim_folder(
78
+ model_file, epw_file, sim_par_json, measures, additional_string, additional_idf,
79
+ folder, log_file
80
+ ):
81
+ """Simulate a Model in EnergyPlus.
82
+
83
+ \b
84
+ Args:
85
+ model_file: Full path to a Model file as a HBJSON or HBPkl.
86
+ epw_file: Full path to an .epw file.
87
+ """
88
+ try:
89
+ # get a ddy variable that might get used later
90
+ epw_folder, epw_file_name = os.path.split(epw_file)
91
+ ddy_file = os.path.join(epw_folder, epw_file_name.replace('.epw', '.ddy'))
92
+ stat_file = os.path.join(epw_folder, epw_file_name.replace('.epw', '.stat'))
93
+
94
+ # sense what type of file has been input
95
+ proj_name = os.path.basename(model_file).lower()
96
+
97
+ # set the default folder to the default if it's not specified
98
+ if folder is None:
99
+ for ext in ('.hbjson', '.json', '.hbpkl', '.pkl'):
100
+ proj_name = proj_name.replace(ext, '')
101
+ folder = os.path.join(folders.default_simulation_folder, proj_name)
102
+ folder = os.path.join(folder, 'openstudio')
103
+ preparedir(folder, remove_content=False)
104
+
105
+ # process the simulation parameters and write new ones if necessary
106
+ def ddy_from_epw(epw_file, sim_par):
107
+ """Produce a DDY from an EPW file."""
108
+ epw_obj = EPW(epw_file)
109
+ des_days = [epw_obj.approximate_design_day('WinterDesignDay'),
110
+ epw_obj.approximate_design_day('SummerDesignDay')]
111
+ sim_par.sizing_parameter.design_days = des_days
112
+
113
+ if sim_par_json is None or not os.path.isfile(sim_par_json):
114
+ sim_par = SimulationParameter()
115
+ sim_par.output.add_zone_energy_use()
116
+ sim_par.output.add_hvac_energy_use()
117
+ sim_par.output.add_electricity_generation()
118
+ sim_par.output.reporting_frequency = 'Monthly'
119
+ else:
120
+ with open(sim_par_json) as json_file:
121
+ data = json.load(json_file)
122
+ sim_par = SimulationParameter.from_dict(data)
123
+ if len(sim_par.sizing_parameter.design_days) == 0 and \
124
+ os.path.isfile(ddy_file):
125
+ try:
126
+ sim_par.sizing_parameter.add_from_ddy_996_004(ddy_file)
127
+ except AssertionError: # no design days within the DDY file
128
+ ddy_from_epw(epw_file, sim_par)
129
+ elif len(sim_par.sizing_parameter.design_days) == 0:
130
+ ddy_from_epw(epw_file, sim_par)
131
+ if sim_par.sizing_parameter.climate_zone is None and \
132
+ os.path.isfile(stat_file):
133
+ stat_obj = STAT(stat_file)
134
+ sim_par.sizing_parameter.climate_zone = stat_obj.ashrae_climate_zone
135
+
136
+ # process the measures input if it is specified
137
+ base_osw = None
138
+ if measures is not None and measures != '' and os.path.isdir(measures):
139
+ for f_name in os.listdir(measures):
140
+ if f_name.lower().endswith('.osw'):
141
+ base_osw = os.path.join(measures, f_name)
142
+ # write the path of the measures folder into the OSW
143
+ with open(base_osw) as json_file:
144
+ osw_dict = json.load(json_file)
145
+ osw_dict['measure_paths'] = [os.path.abspath(measures)]
146
+ with open(base_osw, 'w') as fp:
147
+ json.dump(osw_dict, fp)
148
+ break
149
+
150
+ # Write the osw file to translate the model to osm
151
+ strings_to_inject = additional_string if additional_string is not None else ''
152
+ if additional_idf is not None and os.path.isfile(additional_idf):
153
+ with open(additional_idf, "r") as add_idf_file:
154
+ strings_to_inject = strings_to_inject + '\n' + add_idf_file.read()
155
+
156
+ # run the Model re-serialization and convert to OSM, OSW, and IDF
157
+ osm, osw, idf = None, None, None
158
+ model = Model.from_file(model_file)
159
+ osm, osw, idf = to_openstudio_sim_folder(
160
+ model, folder, epw_file=epw_file, sim_par=sim_par, enforce_rooms=True,
161
+ base_osw=base_osw, strings_to_inject=strings_to_inject,
162
+ print_progress=True)
163
+ gen_files = [osm]
164
+ if osw is not None:
165
+ gen_files.append(osw)
166
+ if idf is not None:
167
+ gen_files.append(idf)
168
+
169
+ log_file.write(json.dumps(gen_files, indent=4))
170
+ except Exception as e:
171
+ _logger.exception('Model simulation failed.\n{}'.format(e))
172
+ sys.exit(1)
173
+ else:
174
+ sys.exit(0)
175
+
176
+
177
+ @translate.command('model-to-osm')
178
+ @click.argument('model-file', type=click.Path(
179
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
180
+ @click.option('--sim-par-json', '-sp', help='Full path to a honeybee energy '
181
+ 'SimulationParameter JSON that describes all of the settings for '
182
+ 'the simulation. If None default parameters will be generated.',
183
+ default=None, show_default=True,
184
+ type=click.Path(exists=True, file_okay=True, dir_okay=False,
185
+ resolve_path=True))
186
+ @click.option('--epw-file', '-epw', help='Full path to an EPW file to be associated '
187
+ 'with the exported OSM. This is typically not necessary but may be '
188
+ 'used when a sim-par-json is specified that requests a HVAC sizing '
189
+ 'calculation to be run as part of the translation process but no design '
190
+ 'days are inside this simulation parameter.',
191
+ default=None, show_default=True,
192
+ type=click.Path(exists=True, file_okay=True, dir_okay=False,
193
+ resolve_path=True))
194
+ @click.option('--folder', '-f', help='Deprecated input that is no longer used.',
195
+ default=None, show_default=True,
196
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
197
+ @click.option('--osm-file', '-osm', help='Optional path where the OSM will be copied '
198
+ 'after it is translated in the folder. If None, the file will not '
199
+ 'be copied.', type=str, default=None, show_default=True)
200
+ @click.option('--idf-file', '-idf', help='Optional path where the IDF will be copied '
201
+ 'after it is translated in the folder. If None, the file will not '
202
+ 'be copied.', type=str, default=None, show_default=True)
203
+ @click.option('--geometry-ids/--geometry-names', ' /-gn', help='Flag to note whether a '
204
+ 'cleaned version of all geometry display names should be used instead '
205
+ 'of identifiers when translating the Model to OSM and IDF. '
206
+ 'Using this flag will affect all Rooms, Faces, Apertures, '
207
+ 'Doors, and Shades. It will generally result in more read-able names '
208
+ 'in the OSM and IDF but this means that it will not be easy to map '
209
+ 'the EnergyPlus results back to the original Honeybee Model. Cases '
210
+ 'of duplicate IDs resulting from non-unique names will be resolved '
211
+ 'by adding integers to the ends of the new IDs that are derived from '
212
+ 'the name.', default=True, show_default=True)
213
+ @click.option('--resource-ids/--resource-names', ' /-rn', help='Flag to note whether a '
214
+ 'cleaned version of all resource display names should be used instead '
215
+ 'of identifiers when translating the Model to OSM and IDF. '
216
+ 'Using this flag will affect all Materials, Constructions, '
217
+ 'ConstructionSets, Schedules, Loads, and ProgramTypes. It will generally '
218
+ 'result in more read-able names for the resources in the OSM and IDF. '
219
+ 'Cases of duplicate IDs resulting from non-unique names will be resolved '
220
+ 'by adding integers to the ends of the new IDs that are derived from '
221
+ 'the name.', default=True, show_default=True)
222
+ @click.option('--log-file', '-log', help='Optional log file to output the paths to the '
223
+ 'generated OSM and IDF files if they were successfully created. '
224
+ 'By default this will be printed out to stdout.',
225
+ type=click.File('w'), default='-', show_default=True)
226
+ def model_to_osm_cli(
227
+ model_file, sim_par_json, epw_file, folder, osm_file, idf_file,
228
+ geometry_ids, resource_ids, log_file):
229
+ """Translate a Honeybee Model file into an OpenStudio Model and corresponding IDF.
230
+
231
+ \b
232
+ Args:
233
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
234
+ """
235
+ try:
236
+ geo_names = not geometry_ids
237
+ res_names = not resource_ids
238
+ model_to_osm(
239
+ model_file, sim_par_json, epw_file, folder, osm_file, idf_file,
240
+ geo_names, res_names, log_file)
241
+ except Exception as e:
242
+ _logger.exception('Model translation failed.\n{}'.format(e))
243
+ sys.exit(1)
244
+ else:
245
+ sys.exit(0)
246
+
247
+
248
+ def model_to_osm(
249
+ model_file, sim_par_json=None, epw_file=None, folder=None,
250
+ osm_file=None, idf_file=None, geometry_names=False, resource_names=False,
251
+ log_file=None, geometry_ids=True, resource_ids=True
252
+ ):
253
+ """Translate a Honeybee Model file into an OpenStudio Model and corresponding IDF.
254
+
255
+ Args:
256
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
257
+ sim_par_json: Full path to a honeybee energy SimulationParameter JSON that
258
+ describes all of the settings for the simulation. If None, default
259
+ parameters will be generated.
260
+ epw_file: Full path to an EPW file to be associated with the exported OSM.
261
+ This is typically not necessary but may be used when a sim-par-json is
262
+ specified that requests a HVAC sizing calculation to be run as part
263
+ of the translation process but no design days are inside this
264
+ simulation parameter.
265
+ folder: Deprecated input that is no longer used.
266
+ osm_file: Optional path where the OSM will be output.
267
+ idf_file: Optional path where the IDF will be output.
268
+ geometry_names: Boolean to note whether a cleaned version of all geometry
269
+ display names should be used instead of identifiers when translating
270
+ the Model to OSM and IDF. Using this flag will affect all Rooms, Faces,
271
+ Apertures, Doors, and Shades. It will generally result in more read-able
272
+ names in the OSM and IDF but this means that it will not be easy to map
273
+ the EnergyPlus results back to the original Honeybee Model. Cases
274
+ of duplicate IDs resulting from non-unique names will be resolved
275
+ by adding integers to the ends of the new IDs that are derived from
276
+ the name. (Default: False).
277
+ resource_names: Boolean to note whether a cleaned version of all resource
278
+ display names should be used instead of identifiers when translating
279
+ the Model to OSM and IDF. Using this flag will affect all Materials,
280
+ Constructions, ConstructionSets, Schedules, Loads, and ProgramTypes.
281
+ It will generally result in more read-able names for the resources
282
+ in the OSM and IDF. Cases of duplicate IDs resulting from non-unique
283
+ names will be resolved by adding integers to the ends of the new IDs
284
+ that are derived from the name. (Default: False).
285
+ log_file: Optional log file to output the paths to the generated OSM and]
286
+ IDF files if they were successfully created. By default this string
287
+ will be returned from this method.
288
+ """
289
+ # check that honeybee-openstudio is installed
290
+ try:
291
+ from honeybee_openstudio.openstudio import openstudio, OSModel
292
+ from honeybee_openstudio.simulation import simulation_parameter_to_openstudio, \
293
+ assign_epw_to_model
294
+ from honeybee_openstudio.writer import model_to_openstudio
295
+ except ImportError as e: # honeybee-openstudio is not installed
296
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
297
+ if folder is not None:
298
+ print('--folder is deprecated and no longer used.')
299
+
300
+ # initialize the OpenStudio model that will hold everything
301
+ os_model = OSModel()
302
+ # generate default simulation parameters
303
+ if sim_par_json is None:
304
+ sim_par = SimulationParameter()
305
+ sim_par.output.add_zone_energy_use()
306
+ sim_par.output.add_hvac_energy_use()
307
+ sim_par.output.add_electricity_generation()
308
+ sim_par.output.reporting_frequency = 'Monthly'
309
+ else:
310
+ with open(sim_par_json) as json_file:
311
+ data = json.load(json_file)
312
+ sim_par = SimulationParameter.from_dict(data)
313
+
314
+ # use any specified EPW files to assign design days and the climate zone
315
+ def ddy_from_epw(epw_file, sim_par):
316
+ """Produce a DDY from an EPW file."""
317
+ epw_obj = EPW(epw_file)
318
+ des_days = [epw_obj.approximate_design_day('WinterDesignDay'),
319
+ epw_obj.approximate_design_day('SummerDesignDay')]
320
+ sim_par.sizing_parameter.design_days = des_days
321
+
322
+ if epw_file is not None:
323
+ epw_folder, epw_file_name = os.path.split(epw_file)
324
+ ddy_file = os.path.join(epw_folder, epw_file_name.replace('.epw', '.ddy'))
325
+ stat_file = os.path.join(epw_folder, epw_file_name.replace('.epw', '.stat'))
326
+ if len(sim_par.sizing_parameter.design_days) == 0 and \
327
+ os.path.isfile(ddy_file):
328
+ try:
329
+ sim_par.sizing_parameter.add_from_ddy_996_004(ddy_file)
330
+ except AssertionError: # no design days within the DDY file
331
+ ddy_from_epw(epw_file, sim_par)
332
+ elif len(sim_par.sizing_parameter.design_days) == 0:
333
+ ddy_from_epw(epw_file, sim_par)
334
+ if sim_par.sizing_parameter.climate_zone is None and os.path.isfile(stat_file):
335
+ stat_obj = STAT(stat_file)
336
+ sim_par.sizing_parameter.climate_zone = stat_obj.ashrae_climate_zone
337
+ set_cz = True if sim_par.sizing_parameter.climate_zone is None else False
338
+ assign_epw_to_model(epw_file, os_model, set_cz)
339
+
340
+ # translate the simulation parameter and model to an OpenStudio Model
341
+ simulation_parameter_to_openstudio(sim_par, os_model)
342
+ model = Model.from_file(model_file)
343
+ os_model = model_to_openstudio(
344
+ model, os_model, use_geometry_names=geometry_names,
345
+ use_resource_names=resource_names, print_progress=True)
346
+ gen_files = []
347
+
348
+ # write the OpenStudio Model if specified
349
+ if osm_file is not None:
350
+ osm = os.path.abspath(osm_file)
351
+ os_model.save(osm, overwrite=True)
352
+ gen_files.append(osm)
353
+
354
+ # write the IDF if specified
355
+ if idf_file is not None:
356
+ idf = os.path.abspath(idf_file)
357
+ idf_translator = openstudio.energyplus.ForwardTranslator()
358
+ workspace = idf_translator.translateModel(os_model)
359
+ workspace.save(idf, overwrite=True)
360
+ gen_files.append(idf)
361
+
362
+ return process_content_to_output(json.dumps(gen_files, indent=4), log_file)
363
+
364
+
365
+ @translate.command('model-to-idf')
366
+ @click.argument('model-file', type=click.Path(
367
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
368
+ @click.option('--sim-par-json', '-sp', help='Full path to a honeybee energy '
369
+ 'SimulationParameter JSON that describes all of the settings for the '
370
+ 'simulation. If None default parameters will be generated.',
371
+ default=None, show_default=True,
372
+ type=click.Path(exists=True, file_okay=True, dir_okay=False,
373
+ resolve_path=True))
374
+ @click.option('--additional-str', '-a', help='Text string for additional lines that '
375
+ 'should be added to the IDF.', type=str, default='', show_default=True)
376
+ @click.option('--compact-schedules/--csv-schedules', ' /-c', help='Flag to note '
377
+ 'whether any ScheduleFixedIntervals in the model should be included '
378
+ 'in the IDF string as a Schedule:Compact or they should be written as '
379
+ 'CSV Schedule:File and placed in a directory next to the output-file.',
380
+ default=True, show_default=True)
381
+ @click.option('--hvac-to-ideal-air/--hvac-check', ' /-h', help='Flag to note '
382
+ 'whether any detailed HVAC system templates should be converted to '
383
+ 'an equivalent IdealAirSystem upon export. If hvac-check is used'
384
+ 'and the Model contains detailed systems, a ValueError will '
385
+ 'be raised.', default=True, show_default=True)
386
+ @click.option('--geometry-ids/--geometry-names', ' /-gn', help='Flag to note whether a '
387
+ 'cleaned version of all geometry display names should be used instead '
388
+ 'of identifiers when translating the Model to IDF. Using this flag will '
389
+ 'affect all Rooms, Faces, Apertures, Doors, and Shades. It will '
390
+ 'generally result in more read-able names in the IDF but this means that '
391
+ 'it will not be easy to map the EnergyPlus results back to the original '
392
+ 'Honeybee Model. Cases of duplicate IDs resulting from non-unique names '
393
+ 'will be resolved by adding integers to the ends of the new IDs that are '
394
+ 'derived from the name.', default=True, show_default=True)
395
+ @click.option('--resource-ids/--resource-names', ' /-rn', help='Flag to note whether a '
396
+ 'cleaned version of all resource display names should be used instead '
397
+ 'of identifiers when translating the Model to IDF. Using this flag will '
398
+ 'affect all Materials, Constructions, ConstructionSets, Schedules, '
399
+ 'Loads, and ProgramTypes. It will generally result in more read-able '
400
+ 'names for the resources in the IDF. Cases of duplicate IDs resulting '
401
+ 'from non-unique names will be resolved by adding integers to the ends '
402
+ 'of the new IDs that are derived from the name.',
403
+ default=True, show_default=True)
404
+ @click.option('--output-file', '-f', help='Optional IDF file to output the IDF string '
405
+ 'of the translation. By default this will be printed out to stdout',
406
+ type=click.File('w'), default='-', show_default=True)
407
+ def model_to_idf_cli(model_file, sim_par_json, additional_str, compact_schedules,
408
+ hvac_to_ideal_air, geometry_ids, resource_ids, output_file):
409
+ """Translate a Model (HBJSON) file to a simplified IDF using direct-to-idf methods.
410
+
411
+ The direct-to-idf methods are faster than those that translate the model
412
+ to OSM but certain features like detailed HVAC systems and the Airflow Network
413
+ are not supported.
414
+
415
+ Args:
416
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
417
+ """
418
+ try:
419
+ csv_schedules = not compact_schedules
420
+ hvac_check = not hvac_to_ideal_air
421
+ geo_names = not geometry_ids
422
+ res_names = not resource_ids
423
+ model_to_idf(
424
+ model_file, sim_par_json, additional_str, csv_schedules,
425
+ hvac_check, geo_names, res_names, output_file)
426
+ except Exception as e:
427
+ _logger.exception('Model translation failed.\n{}'.format(e))
428
+ sys.exit(1)
429
+ else:
430
+ sys.exit(0)
431
+
432
+
433
+ def model_to_idf(
434
+ model_file, sim_par_json=None, additional_str='', csv_schedules=False,
435
+ hvac_check=False, geometry_names=False, resource_names=False, output_file=None,
436
+ compact_schedules=True, hvac_to_ideal_air=True, geometry_ids=True, resource_ids=True
437
+ ):
438
+ """Translate a Honeybee Model file to a simplified IDF using direct-to-idf methods.
439
+
440
+ The direct-to-idf methods are faster than those that translate the model
441
+ to OSM but certain features like detailed HVAC systems and the Airflow Network
442
+ are not supported.
443
+
444
+ Args:
445
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
446
+ sim_par_json: Full path to a honeybee energy SimulationParameter JSON that
447
+ describes all of the settings for the simulation. If None, default
448
+ parameters will be generated.
449
+ additional_str: Text string for additional lines that should be added
450
+ to the IDF.
451
+ csv_schedules: Boolean to note whether any ScheduleFixedIntervals in the
452
+ model should be included in the IDF string as a Schedule:Compact or
453
+ they should be written as CSV Schedule:File and placed in a directory
454
+ next to the output_file. (Default: False).
455
+ hvac_check: Boolean to note whether any detailed HVAC system templates
456
+ should be converted to an equivalent IdealAirSystem upon export.
457
+ If hvac-check is used and the Model contains detailed systems, a
458
+ ValueError will be raised. (Default: False).
459
+ geometry_names: Boolean to note whether a cleaned version of all geometry
460
+ display names should be used instead of identifiers when translating
461
+ the Model to OSM and IDF. Using this flag will affect all Rooms, Faces,
462
+ Apertures, Doors, and Shades. It will generally result in more read-able
463
+ names in the OSM and IDF but this means that it will not be easy to map
464
+ the EnergyPlus results back to the original Honeybee Model. Cases
465
+ of duplicate IDs resulting from non-unique names will be resolved
466
+ by adding integers to the ends of the new IDs that are derived from
467
+ the name. (Default: False).
468
+ resource_names: Boolean to note whether a cleaned version of all resource
469
+ display names should be used instead of identifiers when translating
470
+ the Model to OSM and IDF. Using this flag will affect all Materials,
471
+ Constructions, ConstructionSets, Schedules, Loads, and ProgramTypes.
472
+ It will generally result in more read-able names for the resources
473
+ in the OSM and IDF. Cases of duplicate IDs resulting from non-unique
474
+ names will be resolved by adding integers to the ends of the new IDs
475
+ that are derived from the name. (Default: False).
476
+ output_file: Optional IDF file to output the IDF string of the translation.
477
+ By default this string will be returned from this method.
478
+ """
479
+ # load simulation parameters or generate default ones
480
+ if sim_par_json is not None:
481
+ with open(sim_par_json) as json_file:
482
+ data = json.load(json_file)
483
+ sim_par = SimulationParameter.from_dict(data)
484
+ else:
485
+ sim_par = SimulationParameter()
486
+ sim_par.output.add_zone_energy_use()
487
+ sim_par.output.add_hvac_energy_use()
488
+ sim_par.output.add_electricity_generation()
489
+ sim_par.output.reporting_frequency = 'Monthly'
490
+
491
+ # re-serialize the Model to Python
492
+ model = Model.from_file(model_file)
493
+
494
+ # reset the IDs to be derived from the display_names if requested
495
+ if geometry_names:
496
+ id_map = model.reset_ids()
497
+ model.properties.energy.sync_detailed_hvac_ids(id_map['rooms'])
498
+ if resource_names:
499
+ model.properties.energy.reset_resource_ids()
500
+
501
+ # set the schedule directory in case it is needed
502
+ sch_directory = None
503
+ if csv_schedules:
504
+ sch_path = os.path.abspath(model_file) \
505
+ if output_file is not None and 'stdout' in str(output_file) \
506
+ else os.path.abspath(str(output_file))
507
+ sch_directory = os.path.join(os.path.split(sch_path)[0], 'schedules')
508
+
509
+ # create the strings for simulation parameters and model
510
+ ver_str = energyplus_idf_version() if folders.energyplus_version \
511
+ is not None else ''
512
+ sim_par_str = sim_par.to_idf()
513
+ hvac_to_ideal = not hvac_check
514
+ model_str = model.to.idf(
515
+ model, schedule_directory=sch_directory,
516
+ use_ideal_air_equivalent=hvac_to_ideal)
517
+ idf_str = '\n\n'.join([ver_str, sim_par_str, model_str, additional_str])
518
+
519
+ # write out the IDF file
520
+ return process_content_to_output(idf_str, output_file)
521
+
522
+
523
+ @translate.command('model-to-gbxml')
524
+ @click.argument('model-file', type=click.Path(
525
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
526
+ @click.option('--osw-folder', '-osw',
527
+ help='Deprecated input that is no longer used.', default=None,
528
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
529
+ @click.option('--default-subfaces/--triangulate-subfaces', ' /-t',
530
+ help='Flag to note whether sub-faces (including Apertures and Doors) '
531
+ 'should be triangulated if they have more than 4 sides (True) or whether '
532
+ 'they should be left as they are (False). This triangulation is '
533
+ 'necessary when exporting directly to EnergyPlus since it cannot accept '
534
+ 'sub-faces with more than 4 vertices.', default=True, show_default=True)
535
+ @click.option('--triangulate-non-planar/--permit-non-planar', ' /-np',
536
+ help='Flag to note whether any non-planar orphaned geometry in the '
537
+ 'model should be triangulated upon export. This can be helpful because '
538
+ 'OpenStudio simply raises an error when it encounters non-planar '
539
+ 'geometry, which would hinder the ability to save gbXML files that are '
540
+ 'to be corrected in other software.', default=True, show_default=True)
541
+ @click.option('--minimal/--full-geometry', ' /-fg', help='Flag to note whether space '
542
+ 'boundaries and shell geometry should be included in the exported '
543
+ 'gbXML vs. just the minimal required non-manifold geometry.',
544
+ default=True, show_default=True)
545
+ @click.option('--interior-face-type', '-ift', help='Text string for the type to be '
546
+ 'used for all interior floor faces. If unspecified, the interior types '
547
+ 'will be left as they are. Choose from: InteriorFloor, Ceiling.',
548
+ type=str, default='', show_default=True)
549
+ @click.option('--ground-face-type', '-gft', help='Text string for the type to be '
550
+ 'used for all ground-contact floor faces. If unspecified, the ground '
551
+ 'types will be left as they are. Choose from: UndergroundSlab, '
552
+ 'SlabOnGrade, RaisedFloor.', type=str, default='', show_default=True)
553
+ @click.option('--output-file', '-f', help='Optional gbXML file to output the string '
554
+ 'of the translation. By default it printed out to stdout',
555
+ type=click.File('w'), default='-', show_default=True)
556
+ def model_to_gbxml_cli(
557
+ model_file, osw_folder, default_subfaces, triangulate_non_planar, minimal,
558
+ interior_face_type, ground_face_type, output_file):
559
+ """Translate a Honeybee Model (HBJSON) to a gbXML file.
560
+
561
+ \b
562
+ Args:
563
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
564
+ """
565
+ try:
566
+ triangulate_subfaces = not default_subfaces
567
+ permit_non_planar = not triangulate_non_planar
568
+ full_geometry = not minimal
569
+ model_to_gbxml(
570
+ model_file, osw_folder, triangulate_subfaces, permit_non_planar,
571
+ full_geometry, interior_face_type, ground_face_type, output_file)
572
+ except Exception as e:
573
+ _logger.exception('Model translation failed.\n{}'.format(e))
574
+ sys.exit(1)
575
+ else:
576
+ sys.exit(0)
577
+
578
+
579
+ def model_to_gbxml(
580
+ model_file, osw_folder=None, triangulate_subfaces=False,
581
+ permit_non_planar=False, full_geometry=False,
582
+ interior_face_type='', ground_face_type='', output_file=None,
583
+ default_subfaces=True, triangulate_non_planar=True, minimal=True
584
+ ):
585
+ """Translate a Honeybee Model file to a gbXML file.
586
+
587
+ Args:
588
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
589
+ osw_folder: Deprecated input that is no longer used.
590
+ triangulate_subfaces: Boolean to note whether sub-faces (including
591
+ Apertures and Doors) should be triangulated if they have more
592
+ than 4 sides (True) or whether they should be left as they are (False).
593
+ This triangulation is necessary when exporting directly to EnergyPlus
594
+ since it cannot accept sub-faces with more than 4 vertices. (Default: False).
595
+ permit_non_planar: Boolean to note whether any non-planar orphaned geometry
596
+ in the model should be triangulated upon export. This can be helpful
597
+ because OpenStudio simply raises an error when it encounters non-planar
598
+ geometry, which would hinder the ability to save gbXML files that are
599
+ to be corrected in other software. (Default: False).
600
+ full_geometry: Boolean to note whether space boundaries and shell geometry
601
+ should be included in the exported gbXML vs. just the minimal required
602
+ non-manifold geometry. (Default: False).
603
+ interior_face_type: Text string for the type to be used for all interior
604
+ floor faces. If unspecified, the interior types will be left as they are.
605
+ Choose from: InteriorFloor, Ceiling.
606
+ ground_face_type: Text string for the type to be used for all ground-contact
607
+ floor faces. If unspecified, the ground types will be left as they are.
608
+ Choose from: UndergroundSlab, SlabOnGrade, RaisedFloor.
609
+ output_file: Optional gbXML file to output the string of the translation.
610
+ By default it will be returned from this method.
611
+ """
612
+ # check that honeybee-openstudio is installed
613
+ try:
614
+ from honeybee_openstudio.writer import model_to_gbxml
615
+ except ImportError as e: # honeybee-openstudio is not installed
616
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
617
+ if osw_folder is not None:
618
+ print('--osw-folder is deprecated and no longer used.')
619
+
620
+ # load the model and translate it to a gbXML string
621
+ triangulate_non_planar = not permit_non_planar
622
+ model = Model.from_file(model_file)
623
+ gbxml_str = model_to_gbxml(
624
+ model, triangulate_non_planar_orphaned=triangulate_non_planar,
625
+ triangulate_subfaces=triangulate_subfaces, full_geometry=full_geometry,
626
+ interior_face_type=interior_face_type, ground_face_type=ground_face_type
627
+ )
628
+
629
+ # write out the gbXML file
630
+ return process_content_to_output(gbxml_str, output_file)
631
+
632
+
633
+ @translate.command('model-to-trace-gbxml')
634
+ @click.argument('model-file', type=click.Path(
635
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
636
+ @click.option('--single-window/--detailed-windows', ' /-dw', help='Flag to note '
637
+ 'whether all windows within walls should be converted to a single '
638
+ 'window with an area that matches the original geometry.',
639
+ default=True, show_default=True)
640
+ @click.option('--rect-sub-distance', '-r', help='A number for the resolution at which '
641
+ 'non-rectangular Apertures will be subdivided into smaller rectangular '
642
+ 'units. This is required as TRACE 3D plus cannot model non-rectangular '
643
+ 'geometries. This can include the units of the distance (eg. 0.5ft) or, '
644
+ 'if no units are provided, the value will be interpreted in the '
645
+ 'honeybee model units.',
646
+ type=str, default='0.15m', show_default=True)
647
+ @click.option('--frame-merge-distance', '-m', help='A number for the maximum distance '
648
+ 'between non-rectangular Apertures at which point the Apertures will be '
649
+ 'merged into a single rectangular geometry. This is often helpful when '
650
+ 'there are several triangular Apertures that together make a rectangle '
651
+ 'when they are merged across their frames. This can include the units '
652
+ 'of the distance (eg. 0.5ft) or, if no units are provided, the value '
653
+ 'will be interpreted in the honeybee model units',
654
+ type=str, default='0.2m', show_default=True)
655
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
656
+ default=None,
657
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
658
+ @click.option('--output-file', '-f', help='Optional gbXML file to output the string '
659
+ 'of the translation. By default it printed out to stdout.',
660
+ type=click.File('w'), default='-', show_default=True)
661
+ def model_to_trace_gbxml_cli(
662
+ model_file, single_window, rect_sub_distance, frame_merge_distance,
663
+ osw_folder, output_file):
664
+ """Translate a Honeybee Model (HBJSON) to a gbXML file.
665
+
666
+ \b
667
+ Args:
668
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
669
+ """
670
+ try:
671
+ detailed_windows = not single_window
672
+ model_to_trace_gbxml(model_file, detailed_windows, rect_sub_distance,
673
+ frame_merge_distance, osw_folder, output_file)
674
+ except Exception as e:
675
+ _logger.exception('Model translation failed.\n{}'.format(e))
676
+ sys.exit(1)
677
+ else:
678
+ sys.exit(0)
679
+
680
+
681
+ def model_to_trace_gbxml(
682
+ model_file, detailed_windows=False, rect_sub_distance='0.15m',
683
+ frame_merge_distance='0.2m', osw_folder=None, output_file=None,
684
+ single_window=True
685
+ ):
686
+ """Translate a Honeybee Model to a gbXML file that is compatible with TRACE 3D Plus.
687
+
688
+ Args:
689
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
690
+ detailed_windows: A boolean for whether all windows within walls should be
691
+ left as they are (True) or converted to a single window with an area
692
+ that matches the original geometry (False). (Default: False).
693
+ rect_sub_distance: A number for the resolution at which non-rectangular
694
+ Apertures will be subdivided into smaller rectangular units. This is
695
+ required as TRACE 3D plus cannot model non-rectangular geometries.
696
+ This can include the units of the distance (eg. 0.5ft) or, if no units
697
+ are provided, the value will be interpreted in the honeybee model
698
+ units. (Default: 0.15m).
699
+ frame_merge_distance: A number for the maximum distance between non-rectangular
700
+ Apertures at which point the Apertures will be merged into a single
701
+ rectangular geometry. This is often helpful when there are several
702
+ triangular Apertures that together make a rectangle when they are
703
+ merged across their frames. This can include the units of the
704
+ distance (eg. 0.5ft) or, if no units are provided, the value will
705
+ be interpreted in the honeybee model units. (Default: 0.2m).
706
+ osw_folder: Deprecated input that is no longer used.
707
+ output_file: Optional gbXML file to output the string of the translation.
708
+ By default it will be returned from this method.
709
+ """
710
+ # check that honeybee-openstudio is installed
711
+ try:
712
+ from honeybee_openstudio.writer import model_to_gbxml
713
+ except ImportError as e: # honeybee-openstudio is not installed
714
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
715
+ if osw_folder is not None:
716
+ print('--osw-folder is deprecated and no longer used.')
717
+
718
+ # load the model and translate it to a gbXML string
719
+ single_window = not detailed_windows
720
+ model = Model.from_file(model_file)
721
+ model = _preprocess_model_for_trace(
722
+ model, single_window=single_window, rect_sub_distance=rect_sub_distance,
723
+ frame_merge_distance=frame_merge_distance)
724
+ gbxml_str = model_to_gbxml(model)
725
+
726
+ # write out the gbXML file
727
+ return process_content_to_output(gbxml_str, output_file)
728
+
729
+
730
+ @translate.command('model-to-sdd')
731
+ @click.argument('model-file', type=click.Path(
732
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
733
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
734
+ default=None,
735
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
736
+ @click.option('--output-file', '-f', help='Optional SDD file to output the string '
737
+ 'of the translation. By default it printed out to stdout.', default='-',
738
+ type=click.Path(file_okay=True, dir_okay=False, resolve_path=True))
739
+ def model_to_sdd_cli(model_file, osw_folder, output_file):
740
+ """Translate a Honeybee Model file to a SDD file.
741
+
742
+ \b
743
+ Args:
744
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
745
+ """
746
+ try:
747
+ model_to_sdd(model_file, osw_folder, output_file)
748
+ except Exception as e:
749
+ _logger.exception('Model translation failed.\n{}'.format(e))
750
+ sys.exit(1)
751
+ else:
752
+ sys.exit(0)
753
+
754
+
755
+ def model_to_sdd(model_file, osw_folder=None, output_file=None):
756
+ """Translate a Honeybee Model file to a SDD file.
757
+
758
+ Args:
759
+ model_file: Full path to a Honeybee Model file (HBJSON or HBpkl).
760
+ osw_folder: Deprecated input that is no longer used.
761
+ output_file: Optional SDD file to output the string of the translation.
762
+ By default it will be returned from this method.
763
+ """
764
+ # check that honeybee-openstudio is installed
765
+ try:
766
+ from honeybee_openstudio.openstudio import openstudio
767
+ from honeybee_openstudio.writer import model_to_openstudio
768
+ except ImportError as e: # honeybee-openstudio is not installed
769
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
770
+ if osw_folder is not None:
771
+ print('--folder is deprecated and no longer used.')
772
+
773
+ # translate the model to an OpenStudio Model
774
+ model = Model.from_file(model_file)
775
+ os_model = model_to_openstudio(model, use_simple_window_constructions=True)
776
+
777
+ # write the SDD
778
+ out_path = None
779
+ if output_file is None or output_file.endswith('-'):
780
+ out_directory = tempfile.gettempdir()
781
+ f_name = os.path.basename(model_file).lower()
782
+ f_name = f_name.replace('.hbjson', '.xml').replace('.json', '.xml')
783
+ out_path = os.path.join(out_directory, f_name)
784
+ sdd = os.path.abspath(output_file) if out_path is None else out_path
785
+ sdd_translator = openstudio.sdd.SddForwardTranslator()
786
+ sdd_translator.modelToSDD(os_model, sdd)
787
+
788
+ # return the file contents if requested
789
+ if out_path is not None:
790
+ with open(sdd, 'r') as sdf:
791
+ file_contents = sdf.read()
792
+ if output_file is None:
793
+ return file_contents
794
+ else:
795
+ print(file_contents)
796
+
797
+
798
+ @translate.command('model-from-osm')
799
+ @click.argument('osm-file', type=click.Path(
800
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
801
+ @click.option('--keep-properties/--reset-properties', ' /-r', help='Flag to note '
802
+ 'whether all energy properties should be reset to defaults upon import, '
803
+ 'meaning that only the geometry and boundary conditions are imported '
804
+ 'from the file.', default=True, show_default=True)
805
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
806
+ default=None,
807
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
808
+ @click.option('--output-file', '-f', help='Optional HBJSON file to output the string '
809
+ 'of the translation. By default it printed out to stdout.',
810
+ type=click.File('w'), default='-', show_default=True)
811
+ def model_from_osm_cli(osm_file, keep_properties, osw_folder, output_file):
812
+ """Translate a OpenStudio Model (OSM) to a Honeybee Model (HBJSON).
813
+
814
+ \b
815
+ Args:
816
+ osm_file: Path to a OpenStudio Model (OSM) file.
817
+ """
818
+ try:
819
+ reset_properties = not keep_properties
820
+ model_from_osm(osm_file, reset_properties, osw_folder, output_file)
821
+ except Exception as e:
822
+ _logger.exception('Model translation failed.\n{}'.format(e))
823
+ sys.exit(1)
824
+ else:
825
+ sys.exit(0)
826
+
827
+
828
+ def model_from_osm(osm_file, reset_properties=False, osw_folder=None, output_file=None,
829
+ keep_properties=True):
830
+ """Translate a OpenStudio Model (OSM) to a Honeybee Model (HBJSON).
831
+
832
+ Args:
833
+ osm_file: Path to a OpenStudio Model (OSM) file.
834
+ reset_properties: Boolean to note whether all energy properties should be
835
+ reset to defaults upon import, meaning that only the geometry and boundary
836
+ conditions are imported from the Openstudio Model. (Default: False).
837
+ osw_folder: Deprecated input that is no longer used.
838
+ output_file: Optional HBJSON file to output the string of the translation.
839
+ If None, it will be returned from this method. (Default: None).
840
+ """
841
+ # check that honeybee-openstudio is installed
842
+ try:
843
+ from honeybee_openstudio.reader import model_from_osm_file
844
+ except ImportError as e: # honeybee-openstudio is not installed
845
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
846
+ if osw_folder is not None:
847
+ print('--folder is deprecated and no longer used.')
848
+ # translate everything to a honeybee Model
849
+ model = model_from_osm_file(osm_file, reset_properties)
850
+ # write out the file
851
+ return process_content_to_output(json.dumps(model.to_dict()), output_file)
852
+
853
+
854
+ @translate.command('model-from-idf')
855
+ @click.argument('idf-file', type=click.Path(
856
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
857
+ @click.option('--keep-properties/--reset-properties', ' /-r', help='Flag to note '
858
+ 'whether all energy properties should be reset to defaults upon import, '
859
+ 'meaning that only the geometry and boundary conditions are imported '
860
+ 'from the file.', default=True, show_default=True)
861
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
862
+ default=None,
863
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
864
+ @click.option('--output-file', '-f', help='Optional HBJSON file to output the string '
865
+ 'of the translation. By default it printed out to stdout',
866
+ type=click.File('w'), default='-', show_default=True)
867
+ def model_from_idf_cli(idf_file, keep_properties, osw_folder, output_file):
868
+ """Translate an EnergyPlus Model (IDF) to a Honeybee Model (HBJSON).
869
+
870
+ \b
871
+ Args:
872
+ idf_file: Path to an EnergyPlus Model (IDF) file.
873
+ """
874
+ try:
875
+ reset_properties = not keep_properties
876
+ model_from_idf(idf_file, reset_properties, osw_folder, output_file)
877
+ except Exception as e:
878
+ _logger.exception('Model translation failed.\n{}'.format(e))
879
+ sys.exit(1)
880
+ else:
881
+ sys.exit(0)
882
+
883
+
884
+ def model_from_idf(idf_file, reset_properties=False, osw_folder=None, output_file=None,
885
+ keep_properties=True):
886
+ """Translate an EnergyPlus Model (IDF) to a Honeybee Model (HBJSON).
887
+
888
+ Args:
889
+ idf_file: Path to an EnergyPlus Model (IDF) file.
890
+ reset_properties: Boolean to note whether all energy properties should be
891
+ reset to defaults upon import, meaning that only the geometry and boundary
892
+ conditions are imported from the EnergyPlus Model. (Default: False).
893
+ osw_folder: Deprecated input that is no longer used.
894
+ output_file: Optional HBJSON file to output the string of the translation.
895
+ If None, it will be returned from this method. (Default: None).
896
+ """
897
+ # check that honeybee-openstudio is installed
898
+ try:
899
+ from honeybee_openstudio.reader import model_from_idf_file
900
+ except ImportError as e: # honeybee-openstudio is not installed
901
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
902
+ if osw_folder is not None:
903
+ print('--folder is deprecated and no longer used.')
904
+ # translate everything to a honeybee Model
905
+ model = model_from_idf_file(idf_file, reset_properties)
906
+ # write out the file
907
+ return process_content_to_output(json.dumps(model.to_dict()), output_file)
908
+
909
+
910
+ @translate.command('model-from-gbxml')
911
+ @click.argument('gbxml-file', type=click.Path(
912
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
913
+ @click.option('--keep-properties/--reset-properties', ' /-r', help='Flag to note '
914
+ 'whether all energy properties should be reset to defaults upon import, '
915
+ 'meaning that only the geometry and boundary conditions are imported '
916
+ 'from the file.', default=True, show_default=True)
917
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
918
+ default=None,
919
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
920
+ @click.option('--output-file', '-f', help='Optional HBJSON file to output the string '
921
+ 'of the translation. By default it printed out to stdout',
922
+ type=click.File('w'), default='-', show_default=True)
923
+ def model_from_gbxml_cli(gbxml_file, keep_properties, osw_folder, output_file):
924
+ """Translate a gbXML to a Honeybee Model (HBJSON).
925
+
926
+ \b
927
+ Args:
928
+ gbxml_file: Path to a gbXML file.
929
+ """
930
+ try:
931
+ reset_properties = not keep_properties
932
+ model_from_gbxml(gbxml_file, reset_properties, osw_folder, output_file)
933
+ except Exception as e:
934
+ _logger.exception('Model translation failed.\n{}'.format(e))
935
+ sys.exit(1)
936
+ else:
937
+ sys.exit(0)
938
+
939
+
940
+ def model_from_gbxml(gbxml_file, reset_properties=False, osw_folder=None,
941
+ output_file=None, keep_properties=True):
942
+ """Translate a gbXML to a Honeybee Model (HBJSON).
943
+
944
+ Args:
945
+ gbxml_file: Path to a gbXML file.
946
+ reset_properties: Boolean to note whether all energy properties should be
947
+ reset to defaults upon import, meaning that only the geometry and boundary
948
+ conditions are imported from the gbXML Model. (Default: False).
949
+ osw_folder: Deprecated input that is no longer used.
950
+ output_file: Optional HBJSON file to output the string of the translation.
951
+ If None, it will be returned from this method. (Default: None).
952
+ """
953
+ # check that honeybee-openstudio is installed
954
+ try:
955
+ from honeybee_openstudio.reader import model_from_gbxml_file
956
+ except ImportError as e: # honeybee-openstudio is not installed
957
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
958
+ if osw_folder is not None:
959
+ print('--folder is deprecated and no longer used.')
960
+ # translate everything to a honeybee Model
961
+ model = model_from_gbxml_file(gbxml_file, reset_properties)
962
+ # write out the file
963
+ return process_content_to_output(json.dumps(model.to_dict()), output_file)
964
+
965
+
966
+ @translate.command('constructions-to-idf')
967
+ @click.argument('construction-json', type=click.Path(
968
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
969
+ @click.option('--output-file', '-f', help='Optional IDF file to output the IDF string '
970
+ 'of the translation. By default this will be printed out to stdout',
971
+ type=click.File('w'), default='-', show_default=True)
972
+ def construction_to_idf(construction_json, output_file):
973
+ """Translate a Construction JSON file to an IDF using direct-to-idf translators.
974
+
975
+ \b
976
+ Args:
977
+ construction_json: Full path to a Construction JSON file. This file should
978
+ either be an array of non-abridged Constructions or a dictionary where
979
+ the values are non-abridged Constructions.
980
+ """
981
+ try:
982
+ # re-serialize the Constructions to Python
983
+ with open(construction_json) as json_file:
984
+ data = json.load(json_file)
985
+ constr_list = data.values() if isinstance(data, dict) else data
986
+ constr_objs = [dict_to_construction(constr) for constr in constr_list]
987
+ mat_objs = set()
988
+ for constr in constr_objs:
989
+ try:
990
+ for mat in constr.materials:
991
+ mat_objs.add(mat)
992
+ if constr.has_frame:
993
+ mat_objs.add(constr.frame)
994
+ if constr.has_shade:
995
+ if constr.is_switchable_glazing:
996
+ mat_objs.add(constr.switched_glass_material)
997
+ except AttributeError: # not a construction with materials
998
+ pass
999
+
1000
+ # create the IDF strings
1001
+ idf_str_list = []
1002
+ idf_str_list.append('!- ============== MATERIALS ==============\n')
1003
+ idf_str_list.extend([mat.to_idf() for mat in mat_objs])
1004
+ idf_str_list.append('!- ============ CONSTRUCTIONS ============\n')
1005
+ idf_str_list.extend([constr.to_idf() for constr in constr_objs])
1006
+ idf_str = '\n\n'.join(idf_str_list)
1007
+
1008
+ # write out the IDF file
1009
+ output_file.write(idf_str)
1010
+ except Exception as e:
1011
+ _logger.exception('Construction translation failed.\n{}'.format(e))
1012
+ sys.exit(1)
1013
+ else:
1014
+ sys.exit(0)
1015
+
1016
+
1017
+ @translate.command('constructions-from-idf')
1018
+ @click.argument('construction-idf', type=click.Path(
1019
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1020
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1021
+ 'the output JSON file. Specifying an value here can produce more read-able'
1022
+ ' JSONs.', type=int, default=None, show_default=True)
1023
+ @click.option('--output-file', '-f', help='Optional JSON file to output the JSON '
1024
+ 'string of the translation. By default this will be printed out to stdout',
1025
+ type=click.File('w'), default='-', show_default=True)
1026
+ def construction_from_idf(construction_idf, indent, output_file):
1027
+ """Translate a Construction IDF file to a honeybee JSON as an array of constructions.
1028
+
1029
+ \b
1030
+ Args:
1031
+ construction_idf: Full path to a Construction IDF file. Only the constructions
1032
+ and materials in this file will be extracted.
1033
+ """
1034
+ try:
1035
+ # re-serialize the Constructions to Python
1036
+ opaque_constrs = OpaqueConstruction.extract_all_from_idf_file(construction_idf)
1037
+ win_constrs = WindowConstruction.extract_all_from_idf_file(construction_idf)
1038
+
1039
+ # create the honeybee dictionaries
1040
+ hb_obj_list = []
1041
+ for constr in opaque_constrs[0]:
1042
+ hb_obj_list.append(constr.to_dict())
1043
+ for constr in win_constrs[0]:
1044
+ hb_obj_list.append(constr.to_dict())
1045
+
1046
+ # write out the JSON file
1047
+ output_file.write(json.dumps(hb_obj_list, indent=indent))
1048
+ except Exception as e:
1049
+ _logger.exception('Construction translation failed.\n{}'.format(e))
1050
+ sys.exit(1)
1051
+ else:
1052
+ sys.exit(0)
1053
+
1054
+
1055
+ @translate.command('materials-from-osm')
1056
+ @click.argument('osm-file', type=click.Path(
1057
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1058
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1059
+ 'the output JSON file. Specifying an value here can produce more read-able'
1060
+ ' JSONs.', type=int, default=None, show_default=True)
1061
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
1062
+ default=None,
1063
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
1064
+ @click.option('--output-file', '-f', help='Optional JSON file to output the string '
1065
+ 'of the translation. By default it printed out to stdout',
1066
+ type=click.File('w'), default='-', show_default=True)
1067
+ def materials_from_osm(osm_file, indent, osw_folder, output_file):
1068
+ """Translate all Materials in an OpenStudio Model (OSM) to a Honeybee JSON.
1069
+
1070
+ The resulting JSON can be written into a user standards folder to add the
1071
+ materials to a users standards library.
1072
+
1073
+ \b
1074
+ Args:
1075
+ osm_file: Path to a OpenStudio Model (OSM) file.
1076
+ """
1077
+ try:
1078
+ try:
1079
+ from honeybee_openstudio.openstudio import openstudio
1080
+ from honeybee_openstudio.material import extract_all_materials
1081
+ except ImportError as e: # honeybee-openstudio is not installed
1082
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
1083
+ ver_translator = openstudio.osversion.VersionTranslator() # in case OSM is old
1084
+ os_model = ver_translator.loadModel(osm_file)
1085
+ if not os_model.is_initialized():
1086
+ errors = '\n'.join(str(err.logMessage()) for err in ver_translator.errors())
1087
+ raise ValueError('Failed to load model from OSM.\n{}'.format(errors))
1088
+ materials = extract_all_materials(os_model.get())
1089
+ out_dict = {mat.identifier: mat.to_dict() for mat in materials.values()}
1090
+ output_file.write(json.dumps(out_dict, indent=indent))
1091
+ except Exception as e:
1092
+ _logger.exception('Material translation failed.\n{}'.format(e))
1093
+ sys.exit(1)
1094
+ else:
1095
+ sys.exit(0)
1096
+
1097
+
1098
+ @translate.command('constructions-from-osm')
1099
+ @click.argument('osm-file', type=click.Path(
1100
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1101
+ @click.option('--full/--abridged', ' /-a', help='Flag to note whether the objects '
1102
+ 'should be translated as an abridged specification instead of a '
1103
+ 'specification that fully describes the object. This option should be '
1104
+ 'used when the materials-from-osm command will be used to separately '
1105
+ 'translate all of the materials from the OSM.',
1106
+ default=True, show_default=True)
1107
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1108
+ 'the output JSON file. Specifying an value here can produce more read-able'
1109
+ ' JSONs.', type=int, default=None, show_default=True)
1110
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
1111
+ default=None,
1112
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
1113
+ @click.option('--output-file', '-f', help='Optional JSON file to output the string '
1114
+ 'of the translation. By default it printed out to stdout',
1115
+ type=click.File('w'), default='-', show_default=True)
1116
+ def constructions_from_osm(osm_file, full, indent, osw_folder, output_file):
1117
+ """Translate all Constructions in an OpenStudio Model (OSM) to a Honeybee JSON.
1118
+
1119
+ The resulting JSON can be written into a user standards folder to add the
1120
+ constructions to a users standards library.
1121
+
1122
+ \b
1123
+ Args:
1124
+ osm_file: Path to a OpenStudio Model (OSM) file.
1125
+ """
1126
+ try:
1127
+ try:
1128
+ from honeybee_openstudio.openstudio import openstudio
1129
+ from honeybee_openstudio.construction import extract_all_constructions
1130
+ except ImportError as e: # honeybee-openstudio is not installed
1131
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
1132
+ ver_translator = openstudio.osversion.VersionTranslator() # in case OSM is old
1133
+ os_model = ver_translator.loadModel(osm_file)
1134
+ if not os_model.is_initialized():
1135
+ errors = '\n'.join(str(err.logMessage()) for err in ver_translator.errors())
1136
+ raise ValueError('Failed to load model from OSM.\n{}'.format(errors))
1137
+ constructions = extract_all_constructions(os_model.get())
1138
+ abridged = not full
1139
+ out_dict = {}
1140
+ for con in constructions.values():
1141
+ try:
1142
+ out_dict[con.identifier] = con.to_dict(abridged=abridged)
1143
+ except TypeError: # no abridged option
1144
+ out_dict[con.identifier] = con.to_dict()
1145
+ output_file.write(json.dumps(out_dict, indent=indent))
1146
+ except Exception as e:
1147
+ _logger.exception('Construction translation failed.\n{}'.format(e))
1148
+ sys.exit(1)
1149
+ else:
1150
+ sys.exit(0)
1151
+
1152
+
1153
+ @translate.command('construction-sets-from-osm')
1154
+ @click.argument('osm-file', type=click.Path(
1155
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1156
+ @click.option('--full/--abridged', ' /-a', help='Flag to note whether the objects '
1157
+ 'should be translated as an abridged specification instead of a '
1158
+ 'specification that fully describes the object. This option should be '
1159
+ 'used when the constructions-from-osm command will be used to separately '
1160
+ 'translate all of the constructions from the OSM.',
1161
+ default=True, show_default=True)
1162
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1163
+ 'the output JSON file. Specifying an value here can produce more read-able'
1164
+ ' JSONs.', type=int, default=None, show_default=True)
1165
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
1166
+ default=None,
1167
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
1168
+ @click.option('--output-file', '-f', help='Optional JSON file to output the string '
1169
+ 'of the translation. By default it printed out to stdout',
1170
+ type=click.File('w'), default='-', show_default=True)
1171
+ def construction_sets_from_osm(osm_file, full, indent, osw_folder, output_file):
1172
+ """Translate all ConstructionSets in an OpenStudio Model (OSM) to a Honeybee JSON.
1173
+
1174
+ The resulting JSON can be written into a user standards folder to add the
1175
+ constructions to a users standards library.
1176
+
1177
+ \b
1178
+ Args:
1179
+ osm_file: Path to a OpenStudio Model (OSM) file.
1180
+ """
1181
+ try:
1182
+ try:
1183
+ from honeybee_openstudio.openstudio import openstudio
1184
+ from honeybee_openstudio.construction import extract_all_constructions
1185
+ from honeybee_openstudio.constructionset import construction_set_from_openstudio
1186
+ except ImportError as e: # honeybee-openstudio is not installed
1187
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
1188
+ ver_translator = openstudio.osversion.VersionTranslator() # in case OSM is old
1189
+ os_model = ver_translator.loadModel(osm_file)
1190
+ if not os_model.is_initialized():
1191
+ errors = '\n'.join(str(err.logMessage()) for err in ver_translator.errors())
1192
+ raise ValueError('Failed to load model from OSM.\n{}'.format(errors))
1193
+ os_model = os_model.get()
1194
+ constructions = extract_all_constructions(os_model)
1195
+ abridged = not full
1196
+ out_dict = {}
1197
+ for os_cons_set in os_model.getDefaultConstructionSets():
1198
+ if os_cons_set.nameString() != 'Default Generic Construction Set':
1199
+ con_set = construction_set_from_openstudio(os_cons_set, constructions)
1200
+ out_dict[con_set.identifier] = con_set.to_dict(abridged=abridged)
1201
+ output_file.write(json.dumps(out_dict, indent=indent))
1202
+ except Exception as e:
1203
+ _logger.exception('ConstructionSet translation failed.\n{}'.format(e))
1204
+ sys.exit(1)
1205
+ else:
1206
+ sys.exit(0)
1207
+
1208
+
1209
+ @translate.command('schedules-to-idf')
1210
+ @click.argument('schedule-json', type=click.Path(
1211
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1212
+ @click.option('--output-file', '-f', help='Optional IDF file to output the IDF '
1213
+ 'string of the translation. By default this will be printed out to stdout',
1214
+ type=click.File('w'), default='-', show_default=True)
1215
+ def schedule_to_idf(schedule_json, output_file):
1216
+ """Translate a Schedule JSON file to an IDF using direct-to-idf translators.
1217
+
1218
+ \b
1219
+ Args:
1220
+ schedule_json: Full path to a Schedule JSON file. This file should
1221
+ either be an array of non-abridged Schedules or a dictionary where
1222
+ the values are non-abridged Schedules.
1223
+ """
1224
+ try:
1225
+ # re-serialize the Schedule to Python
1226
+ with open(schedule_json) as json_file:
1227
+ data = json.load(json_file)
1228
+ sch_list = data.values() if isinstance(data, dict) else data
1229
+ sch_objs = [dict_to_schedule(sch) for sch in sch_list]
1230
+ type_objs = set()
1231
+ for sch in sch_objs:
1232
+ type_objs.add(sch.schedule_type_limit)
1233
+
1234
+ # set the schedule directory in case it is needed
1235
+ sch_path = os.path.abspath(schedule_json) if 'stdout' in str(output_file) \
1236
+ else os.path.abspath(str(output_file))
1237
+ sch_directory = os.path.join(os.path.split(sch_path)[0], 'schedules')
1238
+
1239
+ # create the IDF strings
1240
+ sched_strs = []
1241
+ used_day_sched_ids = []
1242
+ for sched in sch_objs:
1243
+ try: # ScheduleRuleset
1244
+ year_schedule, week_schedules = sched.to_idf()
1245
+ if week_schedules is None: # ScheduleConstant
1246
+ sched_strs.append(year_schedule)
1247
+ else: # ScheduleYear
1248
+ # check that day schedules aren't referenced by other schedules
1249
+ day_scheds = []
1250
+ for day in sched.day_schedules:
1251
+ if day.identifier not in used_day_sched_ids:
1252
+ day_scheds.append(day.to_idf(sched.schedule_type_limit))
1253
+ used_day_sched_ids.append(day.identifier)
1254
+ sched_strs.extend([year_schedule] + week_schedules + day_scheds)
1255
+ except AttributeError: # ScheduleFixedInterval
1256
+ sched_strs.append(sched.to_idf(sch_directory))
1257
+ idf_str_list = []
1258
+ idf_str_list.append('!- ========= SCHEDULE TYPE LIMITS =========\n')
1259
+ idf_str_list.extend([type_limit.to_idf() for type_limit in type_objs])
1260
+ idf_str_list.append('!- ============== SCHEDULES ==============\n')
1261
+ idf_str_list.extend(sched_strs)
1262
+ idf_str = '\n\n'.join(idf_str_list)
1263
+
1264
+ # write out the IDF file
1265
+ output_file.write(idf_str)
1266
+ except Exception as e:
1267
+ _logger.exception('Schedule translation failed.\n{}'.format(e))
1268
+ sys.exit(1)
1269
+ else:
1270
+ sys.exit(0)
1271
+
1272
+
1273
+ @translate.command('schedules-from-idf')
1274
+ @click.argument('schedule-idf', type=click.Path(
1275
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1276
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1277
+ 'the output JSON file. Specifying an value here can produce more read-able'
1278
+ ' JSONs.', type=int, default=None, show_default=True)
1279
+ @click.option('--output-file', '-f', help='Optional JSON file to output the JSON '
1280
+ 'string of the translation. By default this will be printed out to stdout',
1281
+ type=click.File('w'), default='-', show_default=True)
1282
+ def schedule_from_idf(schedule_idf, indent, output_file):
1283
+ """Translate a schedule IDF file to a honeybee JSON as an array of schedules.
1284
+
1285
+ \b
1286
+ Args:
1287
+ schedule_idf: Full path to a Schedule IDF file. Only the schedules
1288
+ and schedule type limits in this file will be extracted.
1289
+ """
1290
+ try:
1291
+ # re-serialize the schedules to Python
1292
+ schedules = ScheduleRuleset.extract_all_from_idf_file(schedule_idf)
1293
+ # create the honeybee dictionaries
1294
+ hb_obj_list = [sch.to_dict() for sch in schedules]
1295
+ # write out the JSON file
1296
+ output_file.write(json.dumps(hb_obj_list, indent=indent))
1297
+ except Exception as e:
1298
+ _logger.exception('Schedule translation failed.\n{}'.format(e))
1299
+ sys.exit(1)
1300
+ else:
1301
+ sys.exit(0)
1302
+
1303
+
1304
+ @translate.command('schedule-type-limits-from-osm')
1305
+ @click.argument('osm-file', type=click.Path(
1306
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1307
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1308
+ 'the output JSON file. Specifying an value here can produce more read-able'
1309
+ ' JSONs.', type=int, default=None, show_default=True)
1310
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
1311
+ default=None,
1312
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
1313
+ @click.option('--output-file', '-f', help='Optional JSON file to output the string '
1314
+ 'of the translation. By default it printed out to stdout',
1315
+ type=click.File('w'), default='-', show_default=True)
1316
+ def schedule_type_limits_from_osm(osm_file, indent, osw_folder, output_file):
1317
+ """Translate all ScheduleTypeLimits in an OpenStudio Model (OSM) to a Honeybee JSON.
1318
+
1319
+ The resulting JSON can be written into a user standards folder to add the
1320
+ type limits to a users standards library.
1321
+
1322
+ \b
1323
+ Args:
1324
+ osm_file: Path to a OpenStudio Model (OSM) file.
1325
+ """
1326
+ try:
1327
+ try:
1328
+ from honeybee_openstudio.openstudio import openstudio
1329
+ from honeybee_openstudio.schedule import schedule_type_limits_from_openstudio
1330
+ except ImportError as e: # honeybee-openstudio is not installed
1331
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
1332
+ ver_translator = openstudio.osversion.VersionTranslator() # in case OSM is old
1333
+ os_model = ver_translator.loadModel(osm_file)
1334
+ if not os_model.is_initialized():
1335
+ errors = '\n'.join(str(err.logMessage()) for err in ver_translator.errors())
1336
+ raise ValueError('Failed to load model from OSM.\n{}'.format(errors))
1337
+ out_dict = {}
1338
+ for os_type_lim in os_model.get().getScheduleTypeLimitss():
1339
+ type_lim = schedule_type_limits_from_openstudio(os_type_lim)
1340
+ out_dict[type_lim.identifier] = type_lim.to_dict()
1341
+ output_file.write(json.dumps(out_dict, indent=indent))
1342
+ except Exception as e:
1343
+ _logger.exception('ScheduleTypeLimit translation failed.\n{}'.format(e))
1344
+ sys.exit(1)
1345
+ else:
1346
+ sys.exit(0)
1347
+
1348
+
1349
+ @translate.command('schedules-from-osm')
1350
+ @click.argument('osm-file', type=click.Path(
1351
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1352
+ @click.option('--full/--abridged', ' /-a', help='Flag to note whether the objects '
1353
+ 'should be translated as an abridged specification instead of a '
1354
+ 'specification that fully describes the object. This option should be '
1355
+ 'used when the schedule-type-limits-from-osm command will be used to '
1356
+ 'separately translate all of the type limits from the OSM.',
1357
+ default=True, show_default=True)
1358
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1359
+ 'the output JSON file. Specifying an value here can produce more read-able'
1360
+ ' JSONs.', type=int, default=None, show_default=True)
1361
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
1362
+ default=None,
1363
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
1364
+ @click.option('--output-file', '-f', help='Optional JSON file to output the string '
1365
+ 'of the translation. By default it printed out to stdout',
1366
+ type=click.File('w'), default='-', show_default=True)
1367
+ def schedules_from_osm(osm_file, full, indent, osw_folder, output_file):
1368
+ """Translate all Schedules in an OpenStudio Model (OSM) to a Honeybee JSON.
1369
+
1370
+ The resulting JSON can be written into a user standards folder to add the
1371
+ schedules to a users standards library.
1372
+
1373
+ \b
1374
+ Args:
1375
+ osm_file: Path to a OpenStudio Model (OSM) file.
1376
+ """
1377
+ try:
1378
+ try:
1379
+ from honeybee_openstudio.openstudio import openstudio
1380
+ from honeybee_openstudio.schedule import extract_all_schedules
1381
+ except ImportError as e: # honeybee-openstudio is not installed
1382
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
1383
+ ver_translator = openstudio.osversion.VersionTranslator() # in case OSM is old
1384
+ os_model = ver_translator.loadModel(osm_file)
1385
+ if not os_model.is_initialized():
1386
+ errors = '\n'.join(str(err.logMessage()) for err in ver_translator.errors())
1387
+ raise ValueError('Failed to load model from OSM.\n{}'.format(errors))
1388
+ schedules = extract_all_schedules(os_model.get())
1389
+ abridged = not full
1390
+ out_dict = {}
1391
+ for sch in schedules.values():
1392
+ out_dict[sch.identifier] = sch.to_dict(abridged=abridged)
1393
+ output_file.write(json.dumps(out_dict, indent=indent))
1394
+ except Exception as e:
1395
+ _logger.exception('Schedule translation failed.\n{}'.format(e))
1396
+ sys.exit(1)
1397
+ else:
1398
+ sys.exit(0)
1399
+
1400
+
1401
+ @translate.command('programs-from-osm')
1402
+ @click.argument('osm-file', type=click.Path(
1403
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1404
+ @click.option('--full/--abridged', ' /-a', help='Flag to note whether the objects '
1405
+ 'should be translated as an abridged specification instead of a '
1406
+ 'specification that fully describes the object. This option should be '
1407
+ 'used when the schedules-from-osm command will be used to separately '
1408
+ 'translate all of the schedules from the OSM.',
1409
+ default=True, show_default=True)
1410
+ @click.option('--indent', '-i', help='Optional integer to specify the indentation in '
1411
+ 'the output JSON file. Specifying an value here can produce more read-able'
1412
+ ' JSONs.', type=int, default=None, show_default=True)
1413
+ @click.option('--osw-folder', '-osw', help='Deprecated input that is no longer used.',
1414
+ default=None,
1415
+ type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
1416
+ @click.option('--output-file', '-f', help='Optional JSON file to output the string '
1417
+ 'of the translation. By default it printed out to stdout',
1418
+ type=click.File('w'), default='-', show_default=True)
1419
+ def programs_from_osm(osm_file, full, indent, osw_folder, output_file):
1420
+ """Translate all ProgramTypes in an OpenStudio Model (OSM) to a Honeybee JSON.
1421
+
1422
+ The resulting JSON can be written into a user standards folder to add the
1423
+ programs to a users standards library.
1424
+
1425
+ \b
1426
+ Args:
1427
+ osm_file: Path to a OpenStudio Model (OSM) file.
1428
+ """
1429
+ try:
1430
+ try:
1431
+ from honeybee_openstudio.openstudio import openstudio
1432
+ from honeybee_openstudio.schedule import extract_all_schedules
1433
+ from honeybee_openstudio.programtype import program_type_from_openstudio
1434
+ except ImportError as e: # honeybee-openstudio is not installed
1435
+ raise ImportError('{}\n{}'.format(HB_OS_MSG, e))
1436
+ ver_translator = openstudio.osversion.VersionTranslator() # in case OSM is old
1437
+ os_model = ver_translator.loadModel(osm_file)
1438
+ if not os_model.is_initialized():
1439
+ errors = '\n'.join(str(err.logMessage()) for err in ver_translator.errors())
1440
+ raise ValueError('Failed to load model from OSM.\n{}'.format(errors))
1441
+ os_model = os_model.get()
1442
+ schedules = extract_all_schedules(os_model)
1443
+ abridged = not full
1444
+ out_dict = {}
1445
+ for os_space_type in os_model.getSpaceTypes():
1446
+ program = program_type_from_openstudio(os_space_type, schedules)
1447
+ out_dict[program.identifier] = program.to_dict(abridged=abridged)
1448
+ output_file.write(json.dumps(out_dict, indent=indent))
1449
+ except Exception as e:
1450
+ _logger.exception('Program translation failed.\n{}'.format(e))
1451
+ sys.exit(1)
1452
+ else:
1453
+ sys.exit(0)
1454
+
1455
+
1456
+ @translate.command('model-occ-schedules')
1457
+ @click.argument('model-file', type=click.Path(
1458
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1459
+ @click.option('--threshold', '-t', help='A number between 0 and 1 for the threshold '
1460
+ 'at and above which a schedule value is considered occupied.',
1461
+ type=float, default=0.1, show_default=True)
1462
+ @click.option('--period', '-p', help='An AnalysisPeriod string to dictate '
1463
+ 'the start and end of the exported occupancy values '
1464
+ '(eg. "6/21 to 9/21 between 0 and 23 @1"). Note that the timestep '
1465
+ 'of the period will determine the timestep of output values. If '
1466
+ 'unspecified, the values will be annual.', default=None, type=str)
1467
+ @click.option('--output-file', '-f', help='Optional file to output the JSON of '
1468
+ 'occupancy values. By default this will be printed out to stdout',
1469
+ type=click.File('w'), default='-', show_default=True)
1470
+ def model_occ_schedules(model_file, threshold, period, output_file):
1471
+ """Translate a Model's occupancy schedules into a JSON of 0/1 values.
1472
+
1473
+ \b
1474
+ Args:
1475
+ model_file: Full path to a Model JSON or Pkl file.
1476
+ """
1477
+ try:
1478
+ # re-serialize the Model
1479
+ model = Model.from_file(model_file)
1480
+
1481
+ # loop through the rooms and collect all unique occupancy schedules
1482
+ scheds, room_occupancy = [], {}
1483
+ for room in model.rooms:
1484
+ people = room.properties.energy.people
1485
+ if people is not None:
1486
+ model.properties.energy._check_and_add_schedule(
1487
+ people.occupancy_schedule, scheds)
1488
+ room_occupancy[room.identifier] = people.occupancy_schedule.identifier
1489
+ else:
1490
+ room_occupancy[room.identifier] = None
1491
+
1492
+ # process the run period if it is supplied
1493
+ if period is not None and period != '' and period != 'None':
1494
+ a_per = AnalysisPeriod.from_string(period)
1495
+ else:
1496
+ a_per = AnalysisPeriod()
1497
+
1498
+ # convert occupancy schedules to lists of 0/1 values
1499
+ schedules = {}
1500
+ for sch in scheds:
1501
+ sch_data = sch.data_collection() if isinstance(sch, ScheduleRuleset) \
1502
+ else sch.data_collection
1503
+ if not a_per.is_annual:
1504
+ sch_data = sch_data.filter_by_analysis_period(a_per)
1505
+ values = []
1506
+ for val in sch_data.values:
1507
+ is_occ = 0 if val <= threshold else 1
1508
+ values.append(is_occ)
1509
+ schedules[sch.identifier] = values
1510
+
1511
+ # write out the JSON file
1512
+ occ_dict = {'schedules': schedules, 'room_occupancy': room_occupancy}
1513
+ output_file.write(json.dumps(occ_dict))
1514
+ except Exception as e:
1515
+ _logger.exception('Model translation failed.\n{}'.format(e))
1516
+ sys.exit(1)
1517
+ else:
1518
+ sys.exit(0)
1519
+
1520
+
1521
+ @translate.command('model-transmittance-schedules')
1522
+ @click.argument('model-file', type=click.Path(
1523
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True))
1524
+ @click.option('--period', '-p', help='An AnalysisPeriod string to dictate '
1525
+ 'the start and end of the exported occupancy values '
1526
+ '(eg. "6/21 to 9/21 between 0 and 23 @1"). Note that the timestep '
1527
+ 'of the period will determine the timestep of output values. If '
1528
+ 'unspecified, the values will be annual.', default=None, type=str)
1529
+ @click.option('--output-file', '-f', help='Optional file to output the JSON of '
1530
+ 'occupancy values. By default this will be printed out to stdout',
1531
+ type=click.File('w'), default='-', show_default=True)
1532
+ def model_trans_schedules(model_file, period, output_file):
1533
+ """Translate a Model's shade transmittance schedules into a JSON of fractional vals.
1534
+
1535
+ \b
1536
+ Args:
1537
+ model_file: Full path to a Model JSON or Pkl file.
1538
+ """
1539
+ try:
1540
+ # re-serialize the Model
1541
+ model = Model.from_file(model_file)
1542
+
1543
+ # loop through the rooms and collect all unique occupancy schedules
1544
+ scheds = []
1545
+ for shade in model.shades:
1546
+ t_sch = shade.properties.energy.transmittance_schedule
1547
+ if t_sch is not None:
1548
+ model.properties.energy._check_and_add_schedule(t_sch, scheds)
1549
+
1550
+ # process the run period if it is supplied
1551
+ if period is not None and period != '' and period != 'None':
1552
+ a_per = AnalysisPeriod.from_string(period)
1553
+ else:
1554
+ a_per = AnalysisPeriod()
1555
+
1556
+ # convert occupancy schedules to lists of 0/1 values
1557
+ schedules = {}
1558
+ for sch in scheds:
1559
+ sch_data = sch.data_collection() if isinstance(sch, ScheduleRuleset) \
1560
+ else sch.data_collection
1561
+ if not a_per.is_annual:
1562
+ sch_data = sch_data.filter_by_analysis_period(a_per)
1563
+ schedules[clean_rad_string(sch.identifier)] = sch_data.values
1564
+
1565
+ # write out the JSON file
1566
+ output_file.write(json.dumps(schedules))
1567
+ except Exception as e:
1568
+ _logger.exception('Model translation failed.\n{}'.format(e))
1569
+ sys.exit(1)
1570
+ else:
1571
+ sys.exit(0)
1572
+
1573
+
1574
+ def _run_translation_osw(osw, out_path):
1575
+ """Generic function used by all import methods that run OpenStudio CLI."""
1576
+ # run the measure to translate the model JSON to an openstudio measure
1577
+ _, idf = run_osw(osw, silent=True)
1578
+ if idf is not None and os.path.isfile(idf):
1579
+ if out_path is not None: # load the JSON string to stdout
1580
+ with open(out_path) as json_file:
1581
+ return json_file.read()
1582
+ else:
1583
+ _parse_os_cli_failure(os.path.dirname(osw))
1584
+
1585
+
1586
+ def _translate_osm_to_hbjson(osm_file, osw_folder):
1587
+ """Translate an OSM to a HBJSON for use in resource extraction commands."""
1588
+ # come up with a temporary path to write the HBJSON
1589
+ out_directory = os.path.join(
1590
+ hb_folders.default_simulation_folder, 'temp_translate')
1591
+ f_name = os.path.basename(osm_file).lower().replace('.osm', '.hbjson')
1592
+ out_path = os.path.join(out_directory, f_name)
1593
+ # run the OSW to translate the OSM to HBJSON
1594
+ osw = from_osm_osw(osm_file, out_path, osw_folder)
1595
+ # load the resulting HBJSON to a dictionary and return it
1596
+ _, idf = run_osw(osw, silent=True)
1597
+ if idf is not None and os.path.isfile(idf):
1598
+ with open(out_path) as json_file:
1599
+ return json.load(json_file)
1600
+ else:
1601
+ _parse_os_cli_failure(os.path.dirname(osw))