Skip to content

Commit

Permalink
fix(geometry): Remove need to change _offset_dist_ for study components
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Oct 5, 2024
1 parent 8714343 commit ff79506
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 18 deletions.
Binary file modified ladybug_grasshopper/icon/LB View Percent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ladybug_grasshopper/icon/LB Visibility Percent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ladybug_grasshopper/json/LB_Direct_Sun_Hours.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.2",
"version": "1.8.3",
"nickname": "DirectSunHours",
"outputs": [
[
Expand Down Expand Up @@ -120,7 +120,7 @@
}
],
"subcategory": "3 :: Analyze Geometry",
"code": "\ntry:\n from ladybug.color import Colorset\n from ladybug.graphic import GraphicContainer\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters\n from ladybug_{{cad}}.togeometry import to_joined_gridded_mesh3d, to_vector3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.intersect import join_geometry_to_mesh, intersect_mesh_rays\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, hide_output, \\\n show_output, objectify_output, recommended_processor_count\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # set the default offset distance and _cpu_count_\n if _offset_dist_ is None:\n _offset_dist_ = 0.1 / conversion_to_meters() \\\n if geo_block_ or geo_block_ is None else 0\n workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()\n\n # create the gridded mesh from the geometry\n study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)\n points = [from_point3d(pt.move(vec * _offset_dist_)) for pt, vec in\n zip(study_mesh.face_centroids, study_mesh.face_normals)]\n hide_output(ghenv.Component, 1)\n\n # mesh the geometry and context\n shade_mesh = join_geometry_to_mesh(_geometry + context_) \\\n if geo_block_ or geo_block_ is None else join_geometry_to_mesh(context_)\n\n # get the study points and reverse the sun vectors (for backward ray-tracting)\n rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]\n normals = [from_vector3d(vec) for vec in study_mesh.face_normals] \\\n if geo_block_ or geo_block_ is None else None\n\n # intersect the rays with the mesh\n int_matrix, angles = intersect_mesh_rays(\n shade_mesh, points, rev_vec, normals, cpu_count=workers)\n\n # compute the results\n int_mtx = objectify_output('Sun Intersection Matrix', int_matrix)\n if _timestep_ and _timestep_ != 1: # divide by the timestep before output\n results = [sum(int_list) / _timestep_ for int_list in int_matrix]\n else: # no division required\n results = [sum(int_list) for int_list in int_matrix]\n\n # create the mesh and legend outputs\n graphic = GraphicContainer(results, study_mesh.min, study_mesh.max, legend_par_)\n graphic.legend_parameters.title = 'hours'\n if legend_par_ is None or legend_par_.are_colors_default:\n graphic.legend_parameters.colors = Colorset.ecotect()\n title = text_objects('Direct Sun Hours', graphic.lower_title_location,\n graphic.legend_parameters.text_height * 1.5,\n graphic.legend_parameters.font)\n\n # create all of the visual outputs\n study_mesh.colors = graphic.value_colors\n mesh = from_mesh3d(study_mesh)\n legend = legend_objects(graphic.legend)\n",
"code": "\ntry:\n from ladybug.color import Colorset\n from ladybug.graphic import GraphicContainer\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters\n from ladybug_{{cad}}.togeometry import to_joined_gridded_mesh3d, to_vector3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.intersect import join_geometry_to_mesh, intersect_mesh_rays\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, hide_output, \\\n show_output, objectify_output, recommended_processor_count\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # set the default offset distance and _cpu_count_\n if _offset_dist_ is None:\n _offset_dist_ = 0.1 / conversion_to_meters() \\\n if geo_block_ or geo_block_ is None else 0\n workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()\n\n # create the gridded mesh from the geometry\n study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)\n points = [from_point3d(pt.move(vec * _offset_dist_)) for pt, vec in\n zip(study_mesh.face_centroids, study_mesh.face_normals)]\n hide_output(ghenv.Component, 1)\n\n # mesh the geometry and context\n shade_mesh = join_geometry_to_mesh([from_mesh3d(study_mesh)] + context_) \\\n if geo_block_ or geo_block_ is None else join_geometry_to_mesh(context_)\n\n # get the study points and reverse the sun vectors (for backward ray-tracting)\n rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]\n normals = [from_vector3d(vec) for vec in study_mesh.face_normals] \\\n if geo_block_ or geo_block_ is None else None\n\n # intersect the rays with the mesh\n int_matrix, angles = intersect_mesh_rays(\n shade_mesh, points, rev_vec, normals, cpu_count=workers)\n\n # compute the results\n int_mtx = objectify_output('Sun Intersection Matrix', int_matrix)\n if _timestep_ and _timestep_ != 1: # divide by the timestep before output\n results = [sum(int_list) / _timestep_ for int_list in int_matrix]\n else: # no division required\n results = [sum(int_list) for int_list in int_matrix]\n\n # create the mesh and legend outputs\n graphic = GraphicContainer(results, study_mesh.min, study_mesh.max, legend_par_)\n graphic.legend_parameters.title = 'hours'\n if legend_par_ is None or legend_par_.are_colors_default:\n graphic.legend_parameters.colors = Colorset.ecotect()\n title = text_objects('Direct Sun Hours', graphic.lower_title_location,\n graphic.legend_parameters.text_height * 1.5,\n graphic.legend_parameters.font)\n\n # create all of the visual outputs\n study_mesh.colors = graphic.value_colors\n mesh = from_mesh3d(study_mesh)\n legend = legend_objects(graphic.legend)\n",
"category": "Ladybug",
"name": "LB Direct Sun Hours",
"description": "Calculate the number of hours of direct sunlight received by geometry using sun\nvectors obtained from the \"LB SunPath\" component.\n_\nSuch direct sun calculations can be used for shadow studies of outdoor enviroments\nor can be used to estimate glare potential from direct sun on the indoors.\n_\nNote that this component uses the CAD environment's ray intersection methods,\nwhich can be fast for geometries with low complexity but does not scale well\nfor complex geometries or many test points. For such complex studies,\nhoneybee-radiance should be used.\n-"
Expand Down
4 changes: 2 additions & 2 deletions ladybug_grasshopper/json/LB_Incident_Radiation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "IncidentRadiation",
"outputs": [
[
Expand Down Expand Up @@ -120,7 +120,7 @@
}
],
"subcategory": "3 :: Analyze Geometry",
"code": "\nimport math\ntry: # python 2\n from itertools import izip as zip\nexcept ImportError: # python 3\n pass\n\ntry:\n from ladybug.viewsphere import view_sphere\n from ladybug.graphic import GraphicContainer\n from ladybug.legend import LegendParameters\n from ladybug.color import Colorset\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters\n from ladybug_{{cad}}.togeometry import to_joined_gridded_mesh3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.intersect import join_geometry_to_mesh, intersect_mesh_rays\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, hide_output, \\\n show_output, objectify_output, de_objectify_output, recommended_processor_count\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # set the default offset distance and _cpu_count\n _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \\\n else 0.1 / conversion_to_meters()\n workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()\n\n # create the gridded mesh from the geometry\n study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)\n points = [from_point3d(pt.move(vec * _offset_dist_)) for pt, vec in\n zip(study_mesh.face_centroids, study_mesh.face_normals)]\n hide_output(ghenv.Component, 1)\n\n # mesh the geometry and context\n shade_mesh = join_geometry_to_mesh(_geometry + context_)\n\n # deconstruct the matrix and get the sky dome vectors\n mtx = de_objectify_output(_sky_mtx)\n total_sky_rad = [dir_rad + dif_rad for dir_rad, dif_rad in zip(mtx[1], mtx[2])]\n ground_rad = [(sum(total_sky_rad) / len(total_sky_rad)) * mtx[0][1]] * len(total_sky_rad)\n all_rad = total_sky_rad + ground_rad \n lb_vecs = view_sphere.tregenza_dome_vectors if len(total_sky_rad) == 145 \\\n else view_sphere.reinhart_dome_vectors\n if mtx[0][0] != 0: # there is a north input for sky; rotate vectors\n north_angle = math.radians(mtx[0][0])\n lb_vecs = tuple(vec.rotate_xy(north_angle) for vec in lb_vecs)\n lb_grnd_vecs = tuple(vec.reverse() for vec in lb_vecs)\n all_vecs = [from_vector3d(vec) for vec in lb_vecs + lb_grnd_vecs]\n\n # intersect the rays with the mesh\n normals = [from_vector3d(vec) for vec in study_mesh.face_normals]\n int_matrix_init, angles = intersect_mesh_rays(\n shade_mesh, points, all_vecs, normals, cpu_count=workers)\n\n # compute the results\n results = []\n int_matrix = []\n for int_vals, angs in zip(int_matrix_init, angles):\n pt_rel = [ival * math.cos(ang) for ival, ang in zip(int_vals, angs)]\n int_matrix.append(pt_rel)\n rad_result = sum(r * w for r, w in zip(pt_rel, all_rad))\n results.append(rad_result)\n\n # convert to irradiance if requested\n study_name = 'Incident Radiation'\n if irradiance_:\n study_name = 'Incident Irradiance'\n factor = 1000 / _sky_mtx.wea_duration if hasattr(_sky_mtx, 'wea_duration') \\\n else 1000 / (((mtx[0][3] - mtx[0][2]).total_seconds() / 3600) + 1)\n results = [r * factor for r in results]\n\n # output the intersection matrix and compute total radiation\n int_mtx = objectify_output('Geometry/Sky Intersection Matrix', int_matrix)\n unit_conv = conversion_to_meters() ** 2\n total = 0\n for rad, area in zip(results, study_mesh.face_areas):\n total += rad * area * unit_conv\n\n # create the mesh and legend outputs\n l_par = legend_par_ if legend_par_ is not None else LegendParameters()\n if hasattr(_sky_mtx, 'benefit_matrix') and _sky_mtx.benefit_matrix is not None:\n study_name = '{} Benefit/Harm'.format(study_name)\n if l_par.are_colors_default:\n l_par.colors = reversed(Colorset.benefit_harm())\n if l_par.min is None:\n l_par.min = min((min(results), -max(results)))\n if l_par.max is None:\n l_par.max = max((-min(results), max(results)))\n graphic = GraphicContainer(results, study_mesh.min, study_mesh.max, l_par)\n graphic.legend_parameters.title = 'kWh/m2' if not irradiance_ else 'W/m2'\n title = text_objects(\n study_name, graphic.lower_title_location,\n graphic.legend_parameters.text_height * 1.5,\n graphic.legend_parameters.font)\n\n # create all of the visual outputs\n study_mesh.colors = graphic.value_colors\n mesh = from_mesh3d(study_mesh)\n legend = legend_objects(graphic.legend)\n",
"code": "\nimport math\ntry: # python 2\n from itertools import izip as zip\nexcept ImportError: # python 3\n pass\n\ntry:\n from ladybug.viewsphere import view_sphere\n from ladybug.graphic import GraphicContainer\n from ladybug.legend import LegendParameters\n from ladybug.color import Colorset\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters\n from ladybug_{{cad}}.togeometry import to_joined_gridded_mesh3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.intersect import join_geometry_to_mesh, intersect_mesh_rays\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, hide_output, \\\n show_output, objectify_output, de_objectify_output, recommended_processor_count\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # set the default offset distance and _cpu_count\n _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \\\n else 0.1 / conversion_to_meters()\n workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()\n\n # create the gridded mesh from the geometry\n study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)\n points = [from_point3d(pt.move(vec * _offset_dist_)) for pt, vec in\n zip(study_mesh.face_centroids, study_mesh.face_normals)]\n hide_output(ghenv.Component, 1)\n\n # mesh the geometry and context\n shade_mesh = join_geometry_to_mesh([from_mesh3d(study_mesh)] + context_)\n\n # deconstruct the matrix and get the sky dome vectors\n mtx = de_objectify_output(_sky_mtx)\n total_sky_rad = [dir_rad + dif_rad for dir_rad, dif_rad in zip(mtx[1], mtx[2])]\n ground_rad = [(sum(total_sky_rad) / len(total_sky_rad)) * mtx[0][1]] * len(total_sky_rad)\n all_rad = total_sky_rad + ground_rad \n lb_vecs = view_sphere.tregenza_dome_vectors if len(total_sky_rad) == 145 \\\n else view_sphere.reinhart_dome_vectors\n if mtx[0][0] != 0: # there is a north input for sky; rotate vectors\n north_angle = math.radians(mtx[0][0])\n lb_vecs = tuple(vec.rotate_xy(north_angle) for vec in lb_vecs)\n lb_grnd_vecs = tuple(vec.reverse() for vec in lb_vecs)\n all_vecs = [from_vector3d(vec) for vec in lb_vecs + lb_grnd_vecs]\n\n # intersect the rays with the mesh\n normals = [from_vector3d(vec) for vec in study_mesh.face_normals]\n int_matrix_init, angles = intersect_mesh_rays(\n shade_mesh, points, all_vecs, normals, cpu_count=workers)\n\n # compute the results\n results = []\n int_matrix = []\n for int_vals, angs in zip(int_matrix_init, angles):\n pt_rel = [ival * math.cos(ang) for ival, ang in zip(int_vals, angs)]\n int_matrix.append(pt_rel)\n rad_result = sum(r * w for r, w in zip(pt_rel, all_rad))\n results.append(rad_result)\n\n # convert to irradiance if requested\n study_name = 'Incident Radiation'\n if irradiance_:\n study_name = 'Incident Irradiance'\n factor = 1000 / _sky_mtx.wea_duration if hasattr(_sky_mtx, 'wea_duration') \\\n else 1000 / (((mtx[0][3] - mtx[0][2]).total_seconds() / 3600) + 1)\n results = [r * factor for r in results]\n\n # output the intersection matrix and compute total radiation\n int_mtx = objectify_output('Geometry/Sky Intersection Matrix', int_matrix)\n unit_conv = conversion_to_meters() ** 2\n total = 0\n for rad, area in zip(results, study_mesh.face_areas):\n total += rad * area * unit_conv\n\n # create the mesh and legend outputs\n l_par = legend_par_ if legend_par_ is not None else LegendParameters()\n if hasattr(_sky_mtx, 'benefit_matrix') and _sky_mtx.benefit_matrix is not None:\n study_name = '{} Benefit/Harm'.format(study_name)\n if l_par.are_colors_default:\n l_par.colors = reversed(Colorset.benefit_harm())\n if l_par.min is None:\n l_par.min = min((min(results), -max(results)))\n if l_par.max is None:\n l_par.max = max((-min(results), max(results)))\n graphic = GraphicContainer(results, study_mesh.min, study_mesh.max, l_par)\n graphic.legend_parameters.title = 'kWh/m2' if not irradiance_ else 'W/m2'\n title = text_objects(\n study_name, graphic.lower_title_location,\n graphic.legend_parameters.text_height * 1.5,\n graphic.legend_parameters.font)\n\n # create all of the visual outputs\n study_mesh.colors = graphic.value_colors\n mesh = from_mesh3d(study_mesh)\n legend = legend_objects(graphic.legend)\n",
"category": "Ladybug",
"name": "LB Incident Radiation",
"description": "Calculate the incident radiation on geometry using a sky matrix from the \"Cumulative\nSky Matrix\" component.\n_\nSuch studies of incident radiation can be used to apprxomiate the energy that can\nbe collected from photovoltaic or solar thermal systems. They are also useful\nfor evaluating the impact of a building's orientation on both energy use and the\nsize/cost of cooling systems. For studies of photovoltaic potential or building\nenergy use impact, a sky matrix from EPW radiation should be used. For studies\nof cooling system size/cost, a sky matrix derived from the STAT file's clear sky\nradiation should be used.\n_\nNOTE THAT NO REFLECTIONS OF SOLAR ENERGY ARE INCLUDED\nIN THE ANALYSIS PERFORMED BY THIS COMPONENT.\n_\nGround reflected irradiance is crudely acounted for by means of an emissive\n\"ground hemisphere,\" which is like the sky dome hemisphere and is derived from\nthe ground reflectance that is associated with the connected _sky_mtx. This\nmeans that including geometry that represents the ground surface will effectively\nblock such crude ground reflection.\n_\nAlso note that this component uses the CAD environment's ray intersection methods,\nwhich can be fast for geometries with low complexity but does not scale well for\ncomplex geometries or many test points. For such complex cases and situations\nwhere relfection of solar energy are important, honeybee-radiance should be used.\n-"
Expand Down
Loading

0 comments on commit ff79506

Please sign in to comment.