honeybee-radiance-postprocess 0.4.416__py2.py3-none-any.whl → 0.4.418__py2.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.
@@ -1,6 +1,5 @@
1
1
  """Modules for post-processing simulation outputs."""
2
2
  import click
3
- import logging
4
3
 
5
4
  from honeybee.cli import main
6
5
  from .grid import grid
@@ -8,9 +7,7 @@ from .mtxop import mtxop
8
7
  from .postprocess import post_process
9
8
  from .schedule import schedule
10
9
  from .translate import translate
11
-
12
-
13
- _logger = logging.getLogger(__name__)
10
+ from .viewfactor import view_factor
14
11
 
15
12
 
16
13
  # command group for all postprocess extension commands.
@@ -26,6 +23,7 @@ postprocess.add_command(mtxop)
26
23
  postprocess.add_command(post_process, name='post-process')
27
24
  postprocess.add_command(schedule)
28
25
  postprocess.add_command(translate)
26
+ postprocess.add_command(view_factor)
29
27
 
30
28
  # add postprocess sub-commands to honeybee CLI
31
29
  main.add_command(postprocess)
@@ -62,10 +62,21 @@ def abnt_nbr_15575(
62
62
  a requirement that the sensor grids have Meshes.
63
63
  """
64
64
  def find_surrounding_points(x, y, x_coords, y_coords):
65
- x1 = np.max(x_coords[x_coords <= x]) if np.any(x_coords <= x) else x_coords[0]
66
- x2 = np.min(x_coords[x_coords > x]) if np.any(x_coords > x) else x_coords[-1]
67
- y1 = np.max(y_coords[y_coords <= y]) if np.any(y_coords <= y) else y_coords[0]
68
- y2 = np.min(y_coords[y_coords > y]) if np.any(y_coords > y) else y_coords[-1]
65
+ """Find the four nearest points and return the minimum and maximum
66
+ x and y values."""
67
+ # calculate Euclidean distances
68
+ distances = np.sqrt((x_coords - x)**2 + (y_coords - y)**2)
69
+ # get the four nearest points
70
+ if len(distances) < 4:
71
+ # if the grid for some reason has less than four sensors
72
+ nearest_indices = np.argsort(distances)[:len(distances)]
73
+ else:
74
+ nearest_indices = np.argsort(distances)[:4]
75
+ x_values = x_coords[nearest_indices]
76
+ y_values = y_coords[nearest_indices]
77
+ x1, x2 = min(x_values), max(x_values)
78
+ y1, y2 = min(y_values), max(y_values)
79
+
69
80
  return x1, x2, y1, y2
70
81
 
71
82
  def get_value(x, y, x_coords, y_coords, values):
@@ -73,7 +84,7 @@ def abnt_nbr_15575(
73
84
  index = np.where((np.abs(x_coords - x) <= tolerance) & (np.abs(y_coords - y) <= tolerance))
74
85
  return values[index][0]
75
86
 
76
- def perform_interpolation(x, y, x_coords, y_coords, pit_values):
87
+ def perform_interpolation(x, y, x_coords, y_caoords, pit_values):
77
88
  x1, x2, y1, y2 = find_surrounding_points(x, y, x_coords, y_coords)
78
89
 
79
90
  # extract the illuminance values at the surrounding points
@@ -153,7 +164,6 @@ def abnt_nbr_15575(
153
164
 
154
165
  x_coords = sensor_points[:, 0]
155
166
  y_coords = sensor_points[:, 1]
156
-
157
167
  room = hb_model.rooms_by_identifier([sensor_grid.room_identifier])[0]
158
168
 
159
169
  pof_sensor_grid = \
@@ -0,0 +1,150 @@
1
+ """Commands to compute view factors to geometry."""
2
+ import click
3
+ import os
4
+ import sys
5
+ import logging
6
+ import math
7
+ import numpy as np
8
+
9
+ from honeybee_radiance.config import folders
10
+
11
+ from honeybee_radiance_command.rcontrib import Rcontrib, RcontribOptions
12
+ from honeybee_radiance_command._command_util import run_command
13
+
14
+ from ladybug.futil import preparedir
15
+
16
+ from honeybee_radiance_postprocess.reader import binary_to_array
17
+
18
+ _logger = logging.getLogger(__name__)
19
+
20
+
21
+ @click.group(help='Commands to compute view factors to geometry.')
22
+ def view_factor():
23
+ pass
24
+
25
+
26
+ @view_factor.command('contrib')
27
+ @click.argument(
28
+ 'octree', type=click.Path(exists=True, file_okay=True, resolve_path=True)
29
+ )
30
+ @click.argument(
31
+ 'sensor-grid', type=click.Path(exists=True, file_okay=True, resolve_path=True)
32
+ )
33
+ @click.argument(
34
+ 'modifiers', type=click.Path(exists=True, file_okay=True, resolve_path=True)
35
+ )
36
+ @click.option(
37
+ '--ray-count', type=click.INT, default=6, show_default=True,
38
+ help='The number of rays to be equally distributed over a sphere to compute '
39
+ 'the view factor for each of the input sensors.'
40
+ )
41
+ @click.option(
42
+ '--rad-params', show_default=True, help='Radiance parameters.'
43
+ )
44
+ @click.option(
45
+ '--rad-params-locked', show_default=True, help='Protected Radiance parameters. '
46
+ 'These values will overwrite user input rad parameters.'
47
+ )
48
+ @click.option(
49
+ '--folder', default='.', help='Output folder into which the modifier and '
50
+ 'octree files will be written.'
51
+ )
52
+ @click.option(
53
+ '--name', default='view_factor', help='File name of the view factor file.'
54
+ )
55
+ def rcontrib_command_with_view_postprocess(
56
+ octree, sensor_grid, modifiers, ray_count, rad_params, rad_params_locked,
57
+ folder, name
58
+ ):
59
+ """Run rcontrib to get spherical view factors from a sensor grid.
60
+
61
+ This command is similar to the one in honeybee-radiance, but the
62
+ post-processing is using NumPy.
63
+
64
+ \b
65
+ Args:
66
+ octree: Path to octree file.
67
+ sensor-grid: Path to sensor grid file.
68
+ modifiers: Path to modifiers file.
69
+ """
70
+ try:
71
+ # create the directory if it's not there
72
+ if not os.path.isdir(folder):
73
+ preparedir(folder)
74
+
75
+ # generate the ray vectors to be used in the view factor calculation
76
+ if ray_count == 6:
77
+ rays = ((1, 0, 0), (0, 1, 0), (0, 0, 1), (-1, 0, 0), (0, -1, 0), (0, 0, -1))
78
+ else:
79
+ rays = _fibonacci_spiral(ray_count)
80
+ ray_str = [' {} {} {}\n'.format(*ray) for ray in rays]
81
+
82
+ # create a new .pts file with the view vectors
83
+ ray_file = os.path.abspath(os.path.join(folder, '{}.pts'.format(name)))
84
+ total_rays = 0
85
+ with open(sensor_grid) as sg_file:
86
+ with open(ray_file, 'w') as r_file:
87
+ for line in sg_file:
88
+ for ray in ray_str:
89
+ try:
90
+ r_file.write(' '.join(line.split()[:3]) + ray)
91
+ total_rays += 1
92
+ except Exception:
93
+ pass # we are at the end of the file
94
+
95
+ # set up the Rcontrib options
96
+ options = RcontribOptions()
97
+ if rad_params: # parse input radiance parameters
98
+ options.update_from_string(rad_params.strip())
99
+ if rad_params_locked: # overwrite input values with protected ones
100
+ options.update_from_string(rad_params_locked.strip())
101
+ # overwrite specific options that would otherwise break the command
102
+ options.M = modifiers
103
+ options.update_from_string('-I -V- -y {}'.format(total_rays))
104
+
105
+ # create the rcontrib command and run it
106
+ mtx_file = os.path.abspath(os.path.join(folder, '{}.mtx'.format(name)))
107
+ rcontrib = Rcontrib(options=options, octree=octree, sensors=ray_file)
108
+ cmd = rcontrib.to_radiance().replace('\\', '/')
109
+ cmd = '{} | rmtxop -ff - -c .333 .333 .334 > "{}"'.format(cmd, mtx_file.replace('\\', '/'))
110
+ run_command(cmd, env=folders.env)
111
+
112
+ # load the resulting matrix and process the results into view factors
113
+ array = binary_to_array(mtx_file)
114
+ view_fac_mtx = []
115
+ for i in range(0, len(array), ray_count):
116
+ sens_chunk = array[i:i+ray_count]
117
+ s_facs = np.sum(sens_chunk, axis=0) / (math.pi * ray_count)
118
+ view_fac_mtx.append(s_facs)
119
+
120
+ np.save(os.path.join(folder, '{}'.format(name)), view_fac_mtx)
121
+
122
+ except Exception:
123
+ _logger.exception('Failed to compute view factor contributions.')
124
+ sys.exit(1)
125
+ else:
126
+ sys.exit(0)
127
+
128
+
129
+ def _fibonacci_spiral(point_count=24):
130
+ """Get points distributed uniformly across a unit spherical surface.
131
+
132
+ Args:
133
+ point_count: Integer for the number of points to be distributed.
134
+
135
+ Returns:
136
+ List of tuple, each with 3 values representing the XYZ coordinates of
137
+ the points that were generated.
138
+ """
139
+ points = []
140
+ phi = math.pi * (3. - math.sqrt(5.))
141
+
142
+ for i in range(point_count):
143
+ y = 1 - (i / float(point_count - 1)) * 2
144
+ radius = math.sqrt(1 - y * y)
145
+ theta = phi * i
146
+ x = math.cos(theta) * radius
147
+ z = math.sin(theta) * radius
148
+ points.append((x, y, z))
149
+
150
+ return points
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: honeybee-radiance-postprocess
3
- Version: 0.4.416
3
+ Version: 0.4.418
4
4
  Summary: Postprocessing of Radiance results and matrices
5
5
  Home-page: https://github.com/ladybug-tools/honeybee-radiance-postprocess
6
6
  Author: Ladybug Tools
@@ -14,8 +14,8 @@ honeybee_radiance_postprocess/reader.py,sha256=6myKzfGC1pO8zPixg1kKrKjPihHabTKUh
14
14
  honeybee_radiance_postprocess/type_hints.py,sha256=4R0kZgacQrqzoh8Tq7f8MVzUDzynV-C_jlh80UV6GPE,1122
15
15
  honeybee_radiance_postprocess/util.py,sha256=-J5k1dhvyYJkb42jvTS_xxtokfGbmcucVPXdMWU1jUk,5098
16
16
  honeybee_radiance_postprocess/vis_metadata.py,sha256=7ywIgdiuNKcctxifhpy7-Q2oaSX2ngQBeA0Kh7q1Gg0,1780
17
- honeybee_radiance_postprocess/cli/__init__.py,sha256=4RkpR91GPXWatDE4I_27ce-N4FwolQoO6WO7H24DMXE,777
18
- honeybee_radiance_postprocess/cli/abnt.py,sha256=kenlfNCRDJTMBCtTraFHwYcI3eSwtt22t_cJzw_IWp8,12462
17
+ honeybee_radiance_postprocess/cli/__init__.py,sha256=PVfwkuPFl4TnvQt8ovVm01JK0Alon81BaY-0tshAXyg,795
18
+ honeybee_radiance_postprocess/cli/abnt.py,sha256=IEJdGi4fkLD75C833CVpk5WimMm7PVMGYV3QBNgVOGE,12785
19
19
  honeybee_radiance_postprocess/cli/grid.py,sha256=6peLEAPVe-iw05_wdRpFruZLqO8myvC-_QT5W1q5sk8,10677
20
20
  honeybee_radiance_postprocess/cli/leed.py,sha256=QBR6AMJJWuZ0TevyMi2tXCWMLdS-ZSqtVTZDgqxwa7M,3112
21
21
  honeybee_radiance_postprocess/cli/mtxop.py,sha256=UZJnjNpPjDmShy1-Mxos4H2vTUqk_yP3ZyaC1_LLFeI,5015
@@ -24,13 +24,14 @@ honeybee_radiance_postprocess/cli/schedule.py,sha256=6uIy98Co4zm-ZRcELo4Lfx_aN3l
24
24
  honeybee_radiance_postprocess/cli/translate.py,sha256=18zkcGeRZALJ5Z82NEB3XZ-iEX2cHyneobGWV-IXWE0,6789
25
25
  honeybee_radiance_postprocess/cli/two_phase.py,sha256=xA6ayPv26DM5fuMkLhBMYGklf_j5ymowmncwJGXRgo8,7034
26
26
  honeybee_radiance_postprocess/cli/util.py,sha256=Be9cGmYhcV2W37ma6SgQPCWCpWLLLlroxRYN_l58kY0,4077
27
+ honeybee_radiance_postprocess/cli/viewfactor.py,sha256=kU36YRzLya5PReYREjTfw3zOcWKHYZjVlVclyuR7Cqk,5245
27
28
  honeybee_radiance_postprocess/results/__init__.py,sha256=1agBQbfT4Tf8KqSZzlfKYX8MeZryY4jJ1KB4HWqaDDk,182
28
29
  honeybee_radiance_postprocess/results/annual_daylight.py,sha256=ohysFt4OWlWUn_IvM6pjmiQcRTq_x5b998Iv0pw8AEQ,34964
29
30
  honeybee_radiance_postprocess/results/annual_irradiance.py,sha256=5zwrr4MNeHUebbSRpSBbscPOZUs2AHmYCQfIIbdYImY,8298
30
31
  honeybee_radiance_postprocess/results/results.py,sha256=GwyjIYljaCShx1b6NlYUBcU_gHhckmLcCMNrQ6HVDdE,53507
31
- honeybee_radiance_postprocess-0.4.416.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
32
- honeybee_radiance_postprocess-0.4.416.dist-info/METADATA,sha256=SwBB3ghQY0fMC5Z5QVeIkfuxzI8v2hKvmGPa1s2u2BI,2245
33
- honeybee_radiance_postprocess-0.4.416.dist-info/WHEEL,sha256=unfA4MOaH0icIyIA5oH6E2sn2Hq5zKtLlHsWapZGwes,110
34
- honeybee_radiance_postprocess-0.4.416.dist-info/entry_points.txt,sha256=gFtVPx6UItXt27GfEZZO00eOZChJJEL6JwGSAB_O3rs,96
35
- honeybee_radiance_postprocess-0.4.416.dist-info/top_level.txt,sha256=4-sFbzy7ewP2EDqJV3jeFlAFx7SuxtoBBELWaKAnLdA,30
36
- honeybee_radiance_postprocess-0.4.416.dist-info/RECORD,,
32
+ honeybee_radiance_postprocess-0.4.418.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
33
+ honeybee_radiance_postprocess-0.4.418.dist-info/METADATA,sha256=EaZPDjNDUhsc3qgyqLJI1oLDJd010yi0yY0x3egJcdg,2245
34
+ honeybee_radiance_postprocess-0.4.418.dist-info/WHEEL,sha256=unfA4MOaH0icIyIA5oH6E2sn2Hq5zKtLlHsWapZGwes,110
35
+ honeybee_radiance_postprocess-0.4.418.dist-info/entry_points.txt,sha256=gFtVPx6UItXt27GfEZZO00eOZChJJEL6JwGSAB_O3rs,96
36
+ honeybee_radiance_postprocess-0.4.418.dist-info/top_level.txt,sha256=4-sFbzy7ewP2EDqJV3jeFlAFx7SuxtoBBELWaKAnLdA,30
37
+ honeybee_radiance_postprocess-0.4.418.dist-info/RECORD,,