Skip to content

Commit

Permalink
style(*): Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-chauhan committed Mar 5, 2021
1 parent 5b8af8a commit 4a1ec22
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 43 deletions.
26 changes: 14 additions & 12 deletions honeybee_3dm/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
' this more than once if the face is too small for the unit tolerance selected.'


def import_objects_with_config(rhino3dm_file, layer, tolerance, *,
config=None, modifiers_dict=None):
def import_objects_with_config(
rhino3dm_file, layer, tolerance, *, config=None, modifiers_dict=None):
"""Import Rhino planar geometry as Honeybee faces.
This function looks up a rhino3dm file, converts the objects
Expand All @@ -37,11 +37,13 @@ def import_objects_with_config(rhino3dm_file, layer, tolerance, *,
Returns:
A tuple of following lists;
Honeybee Face objects,
Honeybee Shade objects,
Honeybee Aperture objects,
Honeybee Door objects,
Honeybee grids
- Honeybee Face objects,
- Honeybee Shade objects,
- Honeybee Aperture objects,
- Honeybee Door objects,
- Honeybee grids.
A list wil be empty if no objects are imported from rhino file.
"""
Expand All @@ -51,7 +53,8 @@ def import_objects_with_config(rhino3dm_file, layer, tolerance, *,
# If Grids are requested for a layer
if grid_controls(config, layer.Name):

hb_grids = import_grids(rhino3dm_file, layer, tolerance,
hb_grids = import_grids(
rhino3dm_file, layer, tolerance,
grid_controls=grid_controls(config, layer.Name),
child_layer=child_layer_control(config, layer.Name))

Expand Down Expand Up @@ -92,19 +95,18 @@ def import_objects_with_config(rhino3dm_file, layer, tolerance, *,
# If face_type settting is employed
if 'honeybee_face_type' in config['layers'][layer.Name]:
hb_faces.append(face3d_to_hb_face_with_face_type(config, face_obj,
name, layer.Name))
name, layer.Name))

# If only radiance material settting is employed
elif 'honeybee_face_type' not in config['layers'][layer.Name] and\
'honeybee_face_object' not in config['layers'][layer.Name] and\
'radiance_material' in config['layers'][layer.Name]:
hb_faces.append(face3d_to_hb_face_with_rad(config, face_obj, name,
layer.Name))
layer.Name))

# If face_object settting is employed
elif 'honeybee_face_object' in config['layers'][layer.Name]:
hb_objects = face3d_to_hb_object(config, face_obj, name,
layer.Name)
hb_objects = face3d_to_hb_object(config, face_obj, name, layer.Name)
hb_apertures.extend(hb_objects[0])
hb_doors.extend(hb_objects[1])
hb_shades.extend(hb_objects[2])
Expand Down
4 changes: 2 additions & 2 deletions honeybee_3dm/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from .layer import objects_on_layer, objects_on_parent_child


def import_grids(rhino3dm_file, layer, tolerance, *, grid_controls=None,
child_layer=False):
def import_grids(
rhino3dm_file, layer, tolerance, *, grid_controls=None, child_layer=False):
"""Creates Honeybee grids from a rhino3dm file.
This function assumes all the grid objects are under a layer named ``grid``.
Expand Down
38 changes: 27 additions & 11 deletions honeybee_3dm/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ def get_unit_system(file_3dm):


def child_layer_control(config, layer_name):
"""Checks if child layers are requested for a layer in the config file."""
"""Checks if child layers are requested for a layer in the config file.
Args:
config: A dictionary of the config settings.
layer_name: A text string of the layer name
Returns:
A bool.
"""

if 'include_child_layers' in config['layers'][layer_name] and \
config['layers'][layer_name]['include_child_layers']:
config['layers'][layer_name]['include_child_layers']:
return True
else:
return False
Expand All @@ -53,8 +61,12 @@ def grid_controls(config, layer_name):
grid_controls: A list of grid controls from the config file
Returns:
A tuple of grid controls (grid_size, grid_offset) if valid
grid settings are found in the config file or None
A tuple of grid controls
- grid_size,
- grid_offset.
if valid grid settings are found in the config file or None
"""

if 'grid_settings' in config['layers'][layer_name] and \
Expand All @@ -81,8 +93,8 @@ def check_parent_in_config(file_3dm, config, layer_name, parent_layer_name):
"""

if parent_layer_name in config['layers'] and\
'include_child_layers' in config['layers'][parent_layer_name] and\
config['layers'][parent_layer_name]['include_child_layers']:
'include_child_layers' in config['layers'][parent_layer_name] and\
config['layers'][parent_layer_name]['include_child_layers']:
return True
else:
return False
Expand Down Expand Up @@ -170,16 +182,20 @@ def face3d_to_hb_object(config, face_obj, name, layer_name):
layer_name: A text string of the rhino layer name.
Returns:
A tuple of lists. Each list contains Honeybee Aperture objects,
Honeybee Shade objects, and Honeybee Door objects. List will
be empty if no objects are found for that Honeybee object.
A tuple of lists;
- Honeybee Aperture objects,
- Honeybee Shade objects,
- Honeybee Door objects.
List will be empty if no objects are found for that Honeybee object.
"""

hb_apertures, hb_doors, hb_shades = ([], [], [])

obj_name = name or clean_and_id_string(layer_name)
args = [clean_string(obj_name), face_obj]

def hb_object(config, layer_name, hb_obj):
if 'radiance_material' in config['layers'][layer_name]:
radiance_modifiers = mat_to_dict(config['sources']['radiance_material'])
Expand All @@ -204,4 +220,4 @@ def hb_object(config, layer_name, hb_obj):
hb_shade.display_name = args[0]
hb_shades.append(hb_object(config, layer_name, hb_shade))

return hb_apertures, hb_doors, hb_shades
return hb_apertures, hb_doors, hb_shades
9 changes: 5 additions & 4 deletions honeybee_3dm/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def filter_objects_by_layer_index(file_3dm, layer_index):
"""

return [obj for obj in file_3dm.Objects for index in layer_index
if obj.Attributes.LayerIndex == index and obj.Attributes.Visible]
if obj.Attributes.LayerIndex == index and obj.Attributes.Visible]


def objects_on_parent_child(file_3dm, layer_name):
Expand All @@ -66,8 +66,8 @@ def objects_on_parent_child(file_3dm, layer_name):
# Get a list of parent and child layers for the layer_name
parent_child = parent_child_layers(file_3dm, layer_name)

layer_index = [layer.Index for layer in file_3dm.Layers
if layer.Name in parent_child]
layer_index = [
layer.Index for layer in file_3dm.Layers if layer.Name in parent_child]
if not layer_index:
raise ValueError(f'Find no layer named "{layer_name}"')

Expand Down Expand Up @@ -106,7 +106,8 @@ def visible_layers(file_3dm):

for layer in file_3dm.Layers:
layer_parent = layer.FullPath.split('::')
visibility_check = [False if not layer_name_to_layer[layer_name].Visible
visibility_check = [
False if not layer_name_to_layer[layer_name].Visible
else True for layer_name in layer_parent]
if visibility_check.count(False) == 0:
visible_layers.append(layer)
Expand Down
14 changes: 7 additions & 7 deletions honeybee_3dm/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def to_string(str_lst):
"""Get a string from a list of strings.
"""Get a joined string from a list of strings.
Args:
str_lst: A list of strings
Expand All @@ -13,8 +13,8 @@ def to_string(str_lst):
A string.
"""
mat_string = ''
for str in str_lst:
mat_string += str
for string in str_lst:
mat_string += string
return mat_string


Expand All @@ -26,9 +26,9 @@ def mat_to_dict(path):
Args:
path: A text string for the path to the .mat file
Returns:
A dictionary with radiance identifier : modifier structure
A dictionary with radiance identifier to radiance modifier mapping.
"""
try:
with open(path) as fh:
Expand All @@ -44,12 +44,12 @@ def mat_to_dict(path):
# Read all the materials from the .mat file
materials = [lines[index:(index+4)] for index, line in enumerate(lines)
if 'void' in line]

# Convert text string of materials into Radiance modifiers
modifiers = [material_dict[material[0].split(' ')[1]].from_string(
to_string(material)) for material in materials]

# Create a dictionary with identifier : modifier structure
modifiers_dict = {modifier.identifier: modifier for modifier in modifiers}

return modifiers_dict
1 change: 0 additions & 1 deletion honeybee_3dm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import rhino3dm

from honeybee.model import Model
from honeybee.typing import clean_string

from .face import import_objects, import_objects_with_config
from .helper import get_unit_system, check_parent_in_config
Expand Down
12 changes: 6 additions & 6 deletions honeybee_3dm/togeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def brep_to_meshed_face3d(brep, tolerance):
A Ladybug Face3D object.
"""


for i in range(len(brep.Faces)):
mesh = brep.Faces[i].GetMesh(rhino3dm.MeshType.Any)
faces = mesh_to_face3d(mesh)
Expand Down Expand Up @@ -229,15 +228,16 @@ def brep_to_face3d(brep, tolerance, obj):
elif len(polylines) > 1:
# while creating polylines from lines if lines are remaining,
# mesh the geometry
check_polylines = [isinstance(polyline, Polyline3D)
for polyline in polylines]
check_polylines = [
isinstance(polyline, Polyline3D) for polyline in polylines]

if not all(check_polylines):
faces = brep_to_mesh_to_face3d(brep)
return faces

# sort polylines based on area
polyline_areas = [Face3D(polyline.vertices).area for polyline in polylines
polyline_areas = [
Face3D(polyline.vertices).area for polyline in polylines
if isinstance(polyline, Polyline3D)]

polyline_area_dict = dict(zip(polylines, polyline_areas))
Expand Down Expand Up @@ -343,7 +343,7 @@ def to_face3d(obj, tolerance, *, raise_exception=False):
default is False.
Returns:
A list of Ladybug Face3D.
A list of Ladybug Face3D objects.
"""
rh_geo = obj.Geometry

Expand All @@ -358,7 +358,7 @@ def to_face3d(obj, tolerance, *, raise_exception=False):

# If it's an extrusion
elif isinstance(rh_geo, rhino3dm.Extrusion):
lb_face = extrusion_to_face3d(rh_geo, tolerance)
lb_face = extrusion_to_face3d(rh_geo, tolerance)

# If it's a mesh
elif isinstance(rh_geo, rhino3dm.Mesh):
Expand Down

0 comments on commit 4a1ec22

Please sign in to comment.