honeybee-core 1.64.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. honeybee/__init__.py +23 -0
  2. honeybee/__main__.py +4 -0
  3. honeybee/_base.py +331 -0
  4. honeybee/_basewithshade.py +310 -0
  5. honeybee/_lockable.py +99 -0
  6. honeybee/altnumber.py +47 -0
  7. honeybee/aperture.py +997 -0
  8. honeybee/boundarycondition.py +358 -0
  9. honeybee/checkdup.py +173 -0
  10. honeybee/cli/__init__.py +118 -0
  11. honeybee/cli/compare.py +132 -0
  12. honeybee/cli/create.py +265 -0
  13. honeybee/cli/edit.py +559 -0
  14. honeybee/cli/lib.py +103 -0
  15. honeybee/cli/setconfig.py +43 -0
  16. honeybee/cli/validate.py +224 -0
  17. honeybee/colorobj.py +363 -0
  18. honeybee/config.json +5 -0
  19. honeybee/config.py +347 -0
  20. honeybee/dictutil.py +54 -0
  21. honeybee/door.py +746 -0
  22. honeybee/extensionutil.py +208 -0
  23. honeybee/face.py +2360 -0
  24. honeybee/facetype.py +153 -0
  25. honeybee/logutil.py +79 -0
  26. honeybee/model.py +4272 -0
  27. honeybee/orientation.py +132 -0
  28. honeybee/properties.py +845 -0
  29. honeybee/room.py +3485 -0
  30. honeybee/search.py +107 -0
  31. honeybee/shade.py +514 -0
  32. honeybee/shademesh.py +362 -0
  33. honeybee/typing.py +498 -0
  34. honeybee/units.py +88 -0
  35. honeybee/writer/__init__.py +7 -0
  36. honeybee/writer/aperture.py +6 -0
  37. honeybee/writer/door.py +6 -0
  38. honeybee/writer/face.py +6 -0
  39. honeybee/writer/model.py +6 -0
  40. honeybee/writer/room.py +6 -0
  41. honeybee/writer/shade.py +6 -0
  42. honeybee/writer/shademesh.py +6 -0
  43. honeybee_core-1.64.12.dist-info/METADATA +94 -0
  44. honeybee_core-1.64.12.dist-info/RECORD +48 -0
  45. honeybee_core-1.64.12.dist-info/WHEEL +5 -0
  46. honeybee_core-1.64.12.dist-info/entry_points.txt +2 -0
  47. honeybee_core-1.64.12.dist-info/licenses/LICENSE +661 -0
  48. honeybee_core-1.64.12.dist-info/top_level.txt +1 -0
honeybee/config.py ADDED
@@ -0,0 +1,347 @@
1
+ """Honeybee configurations.
2
+
3
+ Import this into every module where access configurations are needed.
4
+
5
+ Usage:
6
+
7
+ .. code-block:: python
8
+
9
+ from honeybee.config import folders
10
+ print(folders.python_exe_path)
11
+ print(folders.default_simulation_folder)
12
+ folders.default_simulation_folder = "C:/my_sim_folder"
13
+ """
14
+ import ladybug.config as lb_config
15
+
16
+ import os
17
+ import platform
18
+ import sys
19
+ import subprocess
20
+ import json
21
+ import tempfile
22
+
23
+
24
+ class Folders(object):
25
+ """Honeybee folders.
26
+
27
+ Args:
28
+ config_file: The path to the config.json file from which folders are loaded.
29
+ If None, the config.json module included in this package will be used.
30
+ Default: None.
31
+ mute: If False, the paths to the various folders will be printed as they
32
+ are found. If True, no printing will occur upon initialization of this
33
+ class. Default: True.
34
+
35
+ Properties:
36
+ * default_simulation_folder
37
+ * honeybee_core_version
38
+ * honeybee_core_version_str
39
+ * honeybee_schema_version
40
+ * honeybee_schema_version_str
41
+ * python_package_path
42
+ * python_scripts_path
43
+ * python_exe_path
44
+ * python_version
45
+ * python_version_str
46
+ * default_standards_folder
47
+ * config_file
48
+ * mute
49
+ """
50
+
51
+ def __init__(self, config_file=None, mute=True):
52
+ # set the mute value
53
+ self.mute = bool(mute)
54
+
55
+ # load paths from the config JSON file
56
+ self.config_file = config_file
57
+
58
+ # set python version to only be retrieved if requested
59
+ self._python_version = None
60
+ self._python_version_str = None
61
+
62
+ # search for the version of honeybee-core and honeybee-schema
63
+ self._honeybee_core_version = self._find_honeybee_core_version()
64
+ self._honeybee_schema_version = self._find_honeybee_schema_version()
65
+
66
+ @property
67
+ def default_simulation_folder(self):
68
+ """Get or set the path to the default simulation folder."""
69
+ return self._default_simulation_folder
70
+
71
+ @default_simulation_folder.setter
72
+ def default_simulation_folder(self, path):
73
+ if not path: # check the default location for simulations
74
+ path = self._find_default_simulation_folder()
75
+
76
+ self._default_simulation_folder = path
77
+
78
+ if not self.mute and self._default_simulation_folder:
79
+ print('Path to the default simulation folder is set to: '
80
+ '{}'.format(self._default_simulation_folder))
81
+
82
+ @property
83
+ def honeybee_core_version(self):
84
+ """Get a tuple for the installed version of honeybee-core (eg. (1, 47, 26)).
85
+
86
+ This will be None if the version could not be sensed (it was not installed
87
+ via pip).
88
+ """
89
+ return self._honeybee_core_version
90
+
91
+ @property
92
+ def honeybee_core_version_str(self):
93
+ """Get a string for the installed version of honeybee-core (eg. "1.47.26").
94
+
95
+ This will be None if the version could not be sensed.
96
+ """
97
+ if self._honeybee_core_version is not None:
98
+ return '.'.join([str(item) for item in self._honeybee_core_version])
99
+ return None
100
+
101
+ @property
102
+ def honeybee_schema_version(self):
103
+ """Get a tuple for the installed version of honeybee-schema (eg. (1, 35, 0)).
104
+
105
+ This will be None if the version could not be sensed (it was not installed
106
+ via pip) or if no honeybee-schema installation was found next to the
107
+ honeybee-core installation.
108
+ """
109
+ return self._honeybee_schema_version
110
+
111
+ @property
112
+ def honeybee_schema_version_str(self):
113
+ """Get a string for the installed version of honeybee-schema (eg. "1.35.0").
114
+
115
+ This will be None if the version could not be sensed.
116
+ """
117
+ if self._honeybee_schema_version is not None:
118
+ return '.'.join([str(item) for item in self._honeybee_schema_version])
119
+ return None
120
+
121
+ @property
122
+ def python_package_path(self):
123
+ """Get the path to where this Python package is installed."""
124
+ # check the ladybug_tools folder for a Python installation
125
+ py_pack = None
126
+ lb_install = lb_config.folders.ladybug_tools_folder
127
+ if os.path.isdir(lb_install):
128
+ if os.name == 'nt':
129
+ py_pack = os.path.join(lb_install, 'python', 'Lib', 'site-packages')
130
+ elif platform.system() == 'Darwin': # on mac, python version is in path
131
+ py_pack = os.path.join(
132
+ lb_install, 'python', 'lib', 'python3.7', 'site-packages')
133
+ if py_pack is not None and os.path.isdir(py_pack):
134
+ return py_pack
135
+ return os.path.split(os.path.dirname(__file__))[0] # we're on some other cPython
136
+
137
+ @property
138
+ def python_scripts_path(self):
139
+ """Get the path to where Python CLI executable files are installed.
140
+
141
+ This can be used to call command line interface (CLI) executable files
142
+ directly (instead of using their usual entry points).
143
+ """
144
+ # check the ladybug_tools folder for a Python installation
145
+ lb_install = lb_config.folders.ladybug_tools_folder
146
+ if os.path.isdir(lb_install):
147
+ py_scripts = os.path.join(lb_install, 'python', 'Scripts') \
148
+ if os.name == 'nt' else \
149
+ os.path.join(lb_install, 'python', 'bin')
150
+ if os.path.isdir(py_scripts):
151
+ return py_scripts
152
+ sys_dir = os.path.dirname(sys.executable) # assume we are on some other cPython
153
+ return os.path.join(sys_dir, 'Scripts') if os.name == 'nt' else sys_dir
154
+
155
+ @property
156
+ def python_exe_path(self):
157
+ """Get the path to the Python executable to be used for Ladybug Tools CLI calls.
158
+
159
+ If a version of Python is found within the ladybug_tools installation folder,
160
+ this will be the path to that version of Python. Otherwise, it will be
161
+ assumed that this is package is installed in cPython outside of the ladybug_tools
162
+ folder and the sys.executable will be returned.
163
+ """
164
+ # check the ladybug_tools folder for a Python installation
165
+ lb_install = lb_config.folders.ladybug_tools_folder
166
+ if os.path.isdir(lb_install):
167
+ py_exe_file = os.path.join(lb_install, 'python', 'python.exe') \
168
+ if os.name == 'nt' else \
169
+ os.path.join(lb_install, 'python', 'bin', 'python3')
170
+ if os.path.isfile(py_exe_file):
171
+ return py_exe_file
172
+ return sys.executable # assume we are on some other cPython
173
+
174
+ @property
175
+ def python_version(self):
176
+ """Get a tuple for the version of python (eg. (3, 8, 2)).
177
+
178
+ This will be None if the version could not be sensed or if no Python
179
+ installation was found.
180
+ """
181
+ if self._python_version_str is None and self.python_exe_path:
182
+ self._python_version_from_cli()
183
+ return self._python_version
184
+
185
+ @property
186
+ def python_version_str(self):
187
+ """Get text for the full version of python (eg."3.8.2").
188
+
189
+ This will be None if the version could not be sensed or if no Python
190
+ installation was found.
191
+ """
192
+ if self._python_version_str is None and self.python_exe_path:
193
+ self._python_version_from_cli()
194
+ return self._python_version_str
195
+
196
+ @property
197
+ def default_standards_folder(self):
198
+ """Get or set the path to the default standards library used by extensions.
199
+ """
200
+ return self._default_standards_folder
201
+
202
+ @default_standards_folder.setter
203
+ def default_standards_folder(self, path):
204
+ if not path: # check the default locations of the template library
205
+ path = self._find_default_standards_folder()
206
+
207
+ # set the default_standards_folder
208
+ self._default_standards_folder = path
209
+ if path and not self.mute:
210
+ print('Path to the default_standards_folder is set to: '
211
+ '{}'.format(self._default_standards_folder))
212
+
213
+ @property
214
+ def config_file(self):
215
+ """Get or set the path to the config.json file from which folders are loaded.
216
+
217
+ Setting this to None will result in using the config.json module included
218
+ in this package.
219
+ """
220
+ return self._config_file
221
+
222
+ @config_file.setter
223
+ def config_file(self, cfg):
224
+ if cfg is None:
225
+ cfg = os.path.join(os.path.dirname(__file__), 'config.json')
226
+ self._load_from_file(cfg)
227
+ self._config_file = cfg
228
+
229
+ def _load_from_file(self, file_path):
230
+ """Set all of the the properties of this object from a config JSON file.
231
+
232
+ Args:
233
+ file_path: Path to a JSON file containing the file paths. A sample of this
234
+ JSON is the config.json file within this package.
235
+ """
236
+ # check the default file path
237
+ assert os.path.isfile(file_path), \
238
+ ValueError('No file found at {}'.format(file_path))
239
+
240
+ # set the default paths to be all blank
241
+ default_path = {
242
+ "default_simulation_folder": r'',
243
+ "default_standards_folder": r''
244
+ }
245
+
246
+ with open(file_path, 'r') as cfg:
247
+ try:
248
+ paths = json.load(cfg)
249
+ except Exception as e:
250
+ print('Failed to load paths from {}.\nThey will be set to defaults '
251
+ 'instead\n{}'.format(file_path, e))
252
+ else:
253
+ for key, p in paths.items():
254
+ if not key.startswith('__') and p.strip():
255
+ default_path[key] = p.strip()
256
+
257
+ # set paths for the default_simulation_folder
258
+ self.default_simulation_folder = default_path["default_simulation_folder"]
259
+ self.default_standards_folder = default_path["default_standards_folder"]
260
+
261
+ def _python_version_from_cli(self):
262
+ """Set this object's Python version by making a call to a Python command."""
263
+ cmds = [self.python_exe_path, '--version']
264
+ use_shell = True if os.name == 'nt' else False
265
+ process = subprocess.Popen(cmds, stdout=subprocess.PIPE, shell=use_shell)
266
+ stdout = process.communicate()
267
+ base_str = str(stdout[0]).replace("b'", '').replace(r"\r\n'", '')
268
+ self._python_version_str = base_str.split(' ')[-1]
269
+ try:
270
+ self._python_version = \
271
+ tuple(int(i) for i in self._python_version_str.split('.'))
272
+ except Exception:
273
+ pass # failed to parse the version into values
274
+
275
+ @staticmethod
276
+ def _find_default_simulation_folder():
277
+ """Find the the default simulation folder in its usual location.
278
+
279
+ An attempt will be made to create the directory if it does not already exist.
280
+ """
281
+ home_folder = os.getenv('HOME') or os.path.expanduser('~')
282
+ if not os.access(home_folder, os.W_OK):
283
+ home_folder = tempfile.gettempdir()
284
+ sim_folder = os.path.join(home_folder, 'simulation')
285
+ if not os.path.isdir(sim_folder):
286
+ try:
287
+ os.makedirs(sim_folder)
288
+ except OSError as e:
289
+ if e.errno != 17: # avoid race conditions between multiple tasks
290
+ raise OSError('Failed to create default simulation '
291
+ 'folder: %s\n%s' % (sim_folder, e))
292
+ return sim_folder
293
+
294
+ @staticmethod
295
+ def _find_default_standards_folder():
296
+ """Find the user standards library in its default location.
297
+
298
+ The %AppData%/ladybug_tools/standards folder will be checked first, which
299
+ can contain libraries that are not overwritten with the update of the
300
+ honeybee_energy package. If this is not found, the ladybug_tools/resources/
301
+ standards/honeybee_standards folder will be checked next. If no such folder
302
+ is found, this None will be returned.
303
+ """
304
+ # first check if there's a user-defined folder in AppData
305
+ app_folder = os.getenv('APPDATA')
306
+ if app_folder is not None:
307
+ lib_folder = os.path.join(app_folder, 'ladybug_tools', 'standards')
308
+ if os.path.isdir(lib_folder):
309
+ return lib_folder
310
+
311
+ # then check the ladybug_tools installation folder were permanent lib is
312
+ lb_install = lb_config.folders.ladybug_tools_folder
313
+ if os.path.isdir(lb_install):
314
+ lib_folder = os.path.join(
315
+ lb_install, 'resources', 'standards', 'honeybee_standards')
316
+ if os.path.isdir(lib_folder):
317
+ return lib_folder
318
+
319
+ # default to None if nothing was found
320
+ return None
321
+
322
+ def _find_honeybee_core_version(self):
323
+ """Get a tuple of 3 integers for the version of honeybee_core if installed."""
324
+ return self._find_package_version('honeybee_core')
325
+
326
+ def _find_honeybee_schema_version(self):
327
+ """Get a tuple of 3 integers for the version of honeybee_schema if installed."""
328
+ return self._find_package_version('honeybee_schema')
329
+
330
+ def _find_package_version(self, package_name):
331
+ """Get a tuple of 3 integers for the version of a package."""
332
+ hb_info_folder = None
333
+ for item in os.listdir(self.python_package_path):
334
+ if item.startswith(package_name + '-') and item.endswith('.dist-info'):
335
+ if os.path.isdir(os.path.join(self.python_package_path, item)):
336
+ hb_info_folder = item
337
+ break
338
+ if hb_info_folder is not None:
339
+ hb_info_folder = hb_info_folder.replace('.dist-info', '')
340
+ ver = ''.join(s for s in hb_info_folder if (s.isdigit() or s == '.'))
341
+ if ver: # version was found in the file path name
342
+ return tuple(int(d) for d in ver.split('.'))
343
+ return None
344
+
345
+
346
+ """Object possesing all key folders within the configuration."""
347
+ folders = Folders()
honeybee/dictutil.py ADDED
@@ -0,0 +1,54 @@
1
+ # coding=utf-8
2
+ """Utilities to convert any dictionary to Python objects.
3
+
4
+ Note that importing this module will import almost all modules within the
5
+ library in order to be able to re-serialize almost any dictionary produced
6
+ from the library.
7
+ """
8
+ from honeybee.model import Model
9
+ from honeybee.room import Room
10
+ from honeybee.face import Face
11
+ from honeybee.aperture import Aperture
12
+ from honeybee.door import Door
13
+ from honeybee.shade import Shade
14
+ import honeybee.boundarycondition as hbc
15
+
16
+
17
+ def dict_to_object(honeybee_dict, raise_exception=True):
18
+ """Re-serialize a dictionary of almost any object within honeybee.
19
+
20
+ This includes any Model, Room, Face, Aperture, Door, Shade, or boundary
21
+ condition object.
22
+
23
+ Args:
24
+ honeybee_dict: A dictionary of any Honeybee object. Note
25
+ that this should be a non-abridged dictionary to be valid.
26
+ raise_exception: Boolean to note whether an exception should be raised
27
+ if the object is not identified as a part of honeybee.
28
+ Default: True.
29
+
30
+ Returns:
31
+ A Python object derived from the input honeybee_dict.
32
+ """
33
+ try: # get the type key from the dictionary
34
+ obj_type = honeybee_dict['type']
35
+ except KeyError:
36
+ raise ValueError('Honeybee dictionary lacks required "type" key.')
37
+
38
+ if obj_type == 'Model':
39
+ return Model.from_dict(honeybee_dict)
40
+ elif obj_type == 'Room':
41
+ return Room.from_dict(honeybee_dict)
42
+ elif obj_type == 'Face':
43
+ return Face.from_dict(honeybee_dict)
44
+ elif obj_type == 'Aperture':
45
+ return Aperture.from_dict(honeybee_dict)
46
+ elif obj_type == 'Door':
47
+ return Door.from_dict(honeybee_dict)
48
+ elif obj_type == 'Shade':
49
+ return Shade.from_dict(honeybee_dict)
50
+ elif hasattr(hbc, obj_type):
51
+ bc_class = getattr(hbc, obj_type)
52
+ return bc_class.from_dict(honeybee_dict)
53
+ elif raise_exception:
54
+ raise ValueError('{} is not a recognized honeybee object'.format(obj_type))