def to_radiance_visible(self): """Honeybee Radiance material with the visible transmittance.""" try: from honeybee_radiance.modifier.material import Glass from honeybee_radiance.modifier.material import Trans except ImportError as e: raise ImportError( 'honeybee_radiance library must be installed to use ' 'to_radiance_visible() method. {}'.format(e)) diffusing = False trans = 1 for mat in self.materials: if isinstance(mat, EnergyWindowMaterialSimpleGlazSys): trans *= mat.vt elif isinstance(mat, EnergyWindowMaterialGlazing): trans *= mat.visible_transmittance diffusing = True if mat.solar_diffusing is True else False if not diffusing: return Glass.from_single_transmittance( clean_rad_string(self.identifier), trans) else: try: ref = self.materials[-1].solar_reflectance_back except AttributeError: ref = self.materials[-1].solar_reflectance return Trans.from_single_reflectance(clean_rad_string( self.identifier), rgb_reflectance=ref, transmitted_diff=trans, transmitted_spec=0)
def test_clean_rad_string(): """Test the clean_rad_string method.""" correct_str = '0.5 in. Gypsum Wall' incorrect_str = '0.5 in., Gypsum Wall' long_str = 'This is an exceptionally long text string that should never be used ' \ 'for the name of anything in EnergyPlus but is actually ok for Radiance' assert clean_rad_string(correct_str) == '0.5in.GypsumWall' assert clean_rad_string(incorrect_str) == '0.5in.GypsumWall' clean_rad_string(long_str)
def _to_radiance(self, reflectance): try: from honeybee_radiance.modifier.material import Plastic from honeybee_radiance.modifier.material import Mirror except ImportError as e: raise ImportError( 'honeybee_radiance library must be installed to use ' 'to_radiance_* methods. {}'.format(e)) if not self.is_specular: return Plastic.from_single_reflectance( clean_rad_string(self.identifier), reflectance) else: return Mirror.from_single_reflectance( clean_rad_string(self.identifier), reflectance)
def to_radiance_visible(self, specularity=0.0): """Honeybee Radiance material from the visible reflectance of this material.""" try: from honeybee_radiance.modifier.material import Plastic except ImportError as e: raise ImportError('honeybee_radiance library must be installed to use ' 'to_radiance_solar() method. {}'.format(e)) return Plastic.from_single_reflectance( clean_rad_string(self.identifier), 1 - self.visible_absorptance, specularity, self.RADIANCEROUGHTYPES[self.roughness])
def process_inputs(inputs, folder): model_fold = os.path.join(folder, 'model') if os.path.isdir(model_fold): nukedir(model_fold, rmdir=True) # delete the folder if it already exists model = inputs['model'] model.to.rad_folder(model, folder) inputs['model'] = 'model' wea = inputs['wea'] f_name = '{}.wea'.format(clean_rad_string(wea.location.city)) wea.write(os.path.join(folder, f_name)) inputs['wea'] = f_name
try: # import the ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # check and duplicate the input objects group_aps = [] for ap in _apertures: assert isinstance(ap, (Aperture, Door)), 'Expected Aperture or Door ' \ 'for dynamic group. Got {}.'.format(type(ap)) group_aps.append(ap.duplicate()) # set the name of the dynamic group name = clean_and_id_rad_string( 'ApertureGroup') if _name_ is None else clean_rad_string(_name_) for ap in group_aps: ap.properties.radiance.dynamic_group_identifier = name # assign any states if they are connected if len(states_) != 0: # assign states (including shades) to the first aperture group_aps[0].properties.radiance.states = [ state.duplicate() for state in states_ ] # remove shades from following apertures to ensure they aren't double-counted states_wo_shades = [] for state in states_: new_state = state.duplicate() new_state.remove_shades()
try: # import the honeybee-radiance dependencies from honeybee_radiance.modifierset import ModifierSet from honeybee_radiance.lib.modifiersets import modifier_set_by_identifier except ImportError as e: raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # get the base modifier set name = clean_and_id_rad_string('ModifierSet') if _name_ is None else \ clean_rad_string(_name_) if base_mod_set_ is None: mod_set = ModifierSet(name) else: if isinstance(base_mod_set_, str): base_mod_set_ = modifier_set_by_identifier(base_mod_set_) mod_set = base_mod_set_.duplicate() mod_set.identifier = name if _name_ is not None: mod_set.display_name = _name_ # go through each input modifier subset and assign it to the set if len(_exterior_subset_) != 0: assert len( _exterior_subset_) == 3, 'Input _exterior_subset_ is not valid.' if _exterior_subset_[0] is not None:
lb_mesh = to_joined_gridded_mesh3d(floor_faces, _grid_size, _dist_floor_) # remove points outside of the room volume if requested if remove_out_: pattern = [ room.geometry.is_point_inside(pt) for pt in lb_mesh.face_centroids ] lb_mesh, vertex_pattern = lb_mesh.remove_faces(pattern) # extract positions and directions from the mesh base_points = [from_point3d(pt) for pt in lb_mesh.face_centroids] base_poss = [(pt.x, pt.y, pt.z) for pt in lb_mesh.face_centroids] base_dirs = [(vec.x, vec.y, vec.z) for vec in lb_mesh.face_normals] # create the sensor grid s_grid = SensorGrid.from_position_and_direction( room.identifier, base_poss, base_dirs) s_grid.display_name = clean_rad_string(room.display_name) s_grid.room_identifier = room.identifier s_grid.mesh = lb_mesh # append everything to the lists grid.append(s_grid) points.append(base_points) mesh.append(from_mesh3d(lb_mesh)) # convert the lists of points to data trees points = list_to_data_tree(points)
try: from honeybee_radiance.view import View except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) VIEW_TYPES = ('v', 'h', 'l', 'c', 'a') if all_required_inputs(ghenv.Component): # process the points/vectors into tuples _pos = (_position.X, _position.Y, _position.Z) _dir = (_direction.X, _direction.Y, _direction.Z) # set the default values name = clean_and_id_rad_string('View') if _name_ is None else _name_ _up_vec = (_up_vector_.X, _up_vector_.Y, _up_vector_.Z) if _up_vector_ \ is not None else (0, 0, 1) _type_ = 'v' if _view_type_ is None else VIEW_TYPES[_view_type_] _h_angle_ = 60 if _h_angle_ is None else _h_angle_ _v_angle_ = 60 if _v_angle_ is None else _v_angle_ view = View(clean_rad_string(name), _pos, _dir, _up_vec, _type_, _h_angle_, _v_angle_) if _name_ is not None: view.display_name = _name_
except ImportError as e: raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs from ladybug_rhino.togeometry import to_mesh3d, to_face3d except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # set the default name and process the points to tuples name = clean_and_id_rad_string('SensorGrid') if _name_ is None else _name_ pts = [(pt.X, pt.Y, pt.Z) for pt in _positions] # create the sensor grid object id = clean_rad_string(name) if '/' not in name else clean_rad_string( name.split('/')[0]) if len(_directions_) == 0: grid = SensorGrid.from_planar_positions(id, pts, (0, 0, 1)) else: vecs = [(vec.X, vec.Y, vec.Z) for vec in _directions_] grid = SensorGrid.from_position_and_direction(id, pts, vecs) # set the display name if _name_ is not None: grid.display_name = _name_ if '/' in name: grid.group_identifier = \ '/'.join(clean_rad_string(key) for key in name.split('/')[1:]) if mesh_ is not None: grid.mesh = to_mesh3d(mesh_)
def generate_sensor_grid(self, x_dim, y_dim=None, offset=1.0, remove_out=False, wall_offset=0): """Get a radiance SensorGrid generated from this Room's floors. The output grid will have this room referenced in its room_identifier property. It will also include a Mesh3D object with faces that align with the grid positions under the grid's mesh property. Note that the x_dim and y_dim refer to dimensions within the XY coordinate system of the floor faces's planes. So rotating the planes of the floor faces will result in rotated grid cells. Args: x_dim: The x dimension of the grid cells as a number. y_dim: The y dimension of the grid cells as a number. If None, the y dimension will be assumed to be the same as the x dimension. (Default: None). offset: A number for how far to offset the grid from the base face. (Default is 1.0, which will not offset the grid to be 1 unit above the floor). remove_out: Boolean to note whether an extra check should be run to remove sensor points that lie outside the Room volume. Note that this can add significantly to runtime and this check is not necessary in the case that all walls are vertical and all floors are horizontal (Default: False). wall_offset: A number for the distance at which sensors close to walls should be removed. Note that this option has no effect unless the value is more than half of the x_dim or y_dim. (Default: 0). Returns: A honeybee_radiance SensorGrid generated from the floors of the room. Will be None if the Room has no floors or the criteria for wall_offset and/or remove_out results in all sensors being removed. Usage: .. code-block:: python from honeybee.room import Room room = Room.from_box(3.0, 6.0, 3.2, 180) south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) sensor_grid = room.properties.radiance.generate_grid(0.5, 0.5, 1) """ # generate the mesh grid from the floor Faces floor_grid = self._base_sensor_mesh(x_dim, y_dim, offset, remove_out, wall_offset) if floor_grid is None: # no valid mesh could be generated return None # create the sensor grid from the mesh sensor_grid = SensorGrid.from_mesh3d( clean_rad_string(self.host.display_name), floor_grid) sensor_grid.room_identifier = self.host.identifier sensor_grid.display_name = self.host.display_name sensor_grid.base_geometry = \ tuple(face.geometry.move(face.normal.reverse() * offset) for face in self.host.faces if isinstance(face.type, Floor)) return sensor_grid
def generate_sensor_grid_radial(self, x_dim, y_dim=None, offset=1.0, remove_out=False, wall_offset=0, dir_count=8, start_vector=Vector3D(0, -1, 0), mesh_radius=None): """Get a SensorGrid of radial directions around positions from the floors. This type of sensor grid is particularly helpful for studies of multiple view directions, such as imageless glare studies. The output grid will have this room referenced in its room_identifier property. It will also include a Mesh3D of radial faces around each position under the grid's mesh property. Note that the x_dim and y_dim refer to dimensions within the XY coordinate system of the floor faces's planes. So rotating the planes of the floor faces will result in rotated grid cells. Args: x_dim: The x dimension of the grid cells as a number. y_dim: The y dimension of the grid cells as a number. If None, the y dimension will be assumed to be the same as the x dimension. (Default: None). offset: A number for how far to offset the grid from the base face. (Default: 1.0, which will not offset the grid to be 1 unit above the floor). remove_out: Boolean to note whether an extra check should be run to remove sensor points that lie outside the Room volume. Note that this can add significantly to runtime and this check is not necessary in the case that all walls are vertical and all floors are horizontal (Default: False). wall_offset: A number for the distance at which sensors close to walls should be removed. Note that this option has no effect unless the value is more than half of the x_dim or y_dim. (Default: 0). dir_count: A positive integer for the number of radial directions to be generated around each position. (Default: 8). start_vector: A Vector3D to set the start direction of the generated directions. This can be used to orient the resulting sensors to specific parts of the scene. It can also change the elevation of the resulting directions since this start vector will always be rotated in the XY plane to generate the resulting directions. (Default: (0, -1, 0)). mesh_radius: An optional number to override the radius of the meshes generated around each sensor. If None, it will be equal to 45% of the x_dim or y_dim (whichever is smaller). Set to zero to ensure no mesh is added to the resulting sensor grids. (Default: None). Returns: A honeybee_radiance SensorGrid generated from the floors of the room. Will be None if the Room has no floors or the criteria for wall_offset and/or remove_out results in all sensors being removed. """ # generate the mesh grid from the floor Faces floor_grid = self._base_sensor_mesh(x_dim, y_dim, offset, remove_out, wall_offset) if floor_grid is None: # no valid mesh could be generated return None # create the sensor grid from the mesh if mesh_radius is None: small_dim = x_dim if y_dim is None else min((x_dim, y_dim)) mesh_radius = small_dim * 0.45 sensor_grid = SensorGrid.from_mesh3d_radial( clean_rad_string(self.host.display_name), floor_grid, dir_count, start_vector, mesh_radius) sensor_grid.room_identifier = self.host.identifier sensor_grid.display_name = self.host.display_name sensor_grid.base_geometry = \ tuple(face.geometry.move(face.normal.reverse() * offset) for face in self.host.faces if isinstance(face.type, Floor)) return sensor_grid
ghenv.Component.AdditionalHelpFromDocStrings = '4' try: # import the core honeybee dependencies from honeybee.typing import clean_and_id_rad_string, clean_rad_string except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) try: from honeybee_radiance.view import View except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs from ladybug_rhino.viewport import viewport_by_name, viewport_properties except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) VIEW_TYPES = ('v', 'h', 'l', 'c', 'a') # set the default values _name_ = clean_and_id_rad_string('View') if _name_ is None else _name_ viewp = viewport_by_name(_viewport_) v_props = viewport_properties(viewp, _view_type_) view = View(clean_rad_string(_name_), v_props['position'], v_props['direction'], v_props['up_vector'], VIEW_TYPES[v_props['view_type']], v_props['h_angle'], v_props['v_angle']) view.display_name = _name_
else: # use Rhino's default meshing floor_faces = [from_face3d(face) for face in lb_floors] lb_mesh = to_joined_gridded_mesh3d(floor_faces, _grid_size, _dist_floor_) # remove points outside of the room volume if requested if remove_out_: pattern = [room.geometry.is_point_inside(pt) for pt in lb_mesh.face_centroids] lb_mesh, vertex_pattern = lb_mesh.remove_faces(pattern) # extract positions and directions from the mesh base_points = [from_point3d(pt) for pt in lb_mesh.face_centroids] base_poss = [(pt.x, pt.y, pt.z) for pt in lb_mesh.face_centroids] base_dirs = [(vec.x, vec.y, vec.z) for vec in lb_mesh.face_normals] # create the sensor grid s_grid = SensorGrid.from_position_and_direction( clean_rad_string(room.display_name), base_poss, base_dirs) s_grid.display_name = room.display_name s_grid.room_identifier = room.identifier s_grid.mesh = lb_mesh s_grid.base_geometry = tuple(f.move(f.normal * _dist_floor_) for f in lb_floors) # append everything to the lists grid.append(s_grid) points.append(base_points) mesh.append(from_mesh3d(lb_mesh)) # convert the lists of points to data trees points = list_to_data_tree(points)
try: # import the ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # check and duplicate the input objects group_shds = [] for shd in _shades: assert isinstance(shd, Shade), 'Expected Shade ' \ 'for dynamic shade group. Got {}.'.format(type(shd)) group_shds.append(shd.duplicate()) # set the name of the dynamic group name = clean_and_id_rad_string( 'ShadeGroup') if _name_ is None else clean_rad_string(_name_) for shd in group_shds: shd.properties.radiance.dynamic_group_identifier = name # assign any states if they are connected if len(states_) != 0: # convert the sub-face states to shade states shd_states = [ RadianceShadeState(st.modifier, st.shades) for st in states_ ] # assign states (including shades) to the first shade group_shds[0].properties.radiance.states = [ state.duplicate() for state in shd_states ] # remove shades from following shades to ensure they aren't double-counted