Skip to content

Commit

Permalink
fix(result): Fix a couple of bugs in the result-matching components
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jul 15, 2023
1 parent 827c596 commit 2c28923
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
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 honeybee_grasshopper_energy/icon/HB Color Rooms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.6.1",
"nickname": "CEI",
"outputs": [
[
Expand Down Expand Up @@ -57,7 +57,7 @@
}
],
"subcategory": "6 :: Result",
"code": "\nimport os\nimport subprocess\nimport json\n\ntry:\n from ladybug.location import Location\nexcept ImportError as e:\n raise ImportError('\\nFailed to import location:\\n\\t{}'.format(e))\n\ntry:\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.result.emissions import future_electricity_emissions, \\\n emissions_from_sql\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\n# Use the SQLiteResult class to parse the result files directly on Windows.\ndef get_results_windows(sql_files, elec_emiss):\n results = emissions_from_sql(sql_files, elec_emiss)\n return results['carbon_intensity'], results['total_floor_area'], \\\n results['end_uses'], results['sources']\n\n\n# The SQLite3 module doesn't work in IronPython on Mac, so we must make a call\n# to the Honeybee CLI (which runs on CPython) to get the results.\ndef get_results_mac(sql_files, elec_emiss):\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'carbon-emission-intensity']\n cmds.extend(sql_files)\n cmds.extend(['--electricity-emissions', str(elec_emiss)])\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE)\n stdout = process.communicate()\n results = json.loads(stdout[0], object_pairs_hook=OrderedDict)\n return results['carbon_intensity'], results['total_floor_area'], \\\n results['end_uses'], results['sources']\n\n\nif all_required_inputs(ghenv.Component):\n # ensure that _sql is a list rather than a single string\n if isinstance(_sql, basestring):\n _sql = [_sql]\n\n # process the location and year or the electricity intensity\n if isinstance(_loc_kgMWh, Location):\n yr = 2030 if _year_ is None else int(_year_)\n elec_emiss = future_electricity_emissions(_loc_kgMWh, yr)\n if elec_emiss is None:\n msg = 'Location must be inside the USA in order to be used for carbon ' \\\n 'emissions estimation.\\nPlug in a number for carbon intensity in ' \\\n 'kg CO2/MWH for locations outside the USA.'\n print(msg)\n raise ValueError(msg)\n else:\n try:\n elec_emiss = float(_loc_kgMWh)\n except TypeError:\n msg = 'Expected location object or number for _loccation. ' \\\n 'Got {}.'.format(type(_loc_kgMWh))\n raise ValueError(msg)\n\n # get the results\n get_results = get_results_windows if os.name == 'nt' else get_results_mac\n cei, gross_floor, end_use_pairs, sources = get_results(_sql, elec_emiss)\n\n # create separate lists for end use values and labels\n cei_end_use = end_use_pairs.values()\n end_uses = [use.replace('_', ' ').title() for use in end_use_pairs.keys()]\n\n # give a warning if the sources include district heating or cooling\n if 'district_heat' in sources:\n msg = 'District heating was found in the results and so carbon emissions ' \\\n 'cannot be accurately estimated.\\nTry using a different HVAC or SHW system.'\n print(msg)\n give_warning(ghenv.Component, msg)\n if 'district_cool' in sources:\n msg = 'District cooling was found in the results and so carbon emissions ' \\\n 'cannot be accurately estimated.\\nTry using a different HVAC system.'\n print(msg)\n give_warning(ghenv.Component, msg)\n",
"code": "\nimport os\nimport subprocess\nimport json\n\ntry:\n from ladybug.location import Location\nexcept ImportError as e:\n raise ImportError('\\nFailed to import location:\\n\\t{}'.format(e))\n\ntry:\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.result.emissions import future_electricity_emissions, \\\n emissions_from_sql\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\n# Use the SQLiteResult class to parse the result files directly on Windows.\ndef get_results_windows(sql_files, elec_emiss):\n results = emissions_from_sql(sql_files, elec_emiss)\n return results['carbon_intensity'], results['total_floor_area'], \\\n results['end_uses'], results['sources']\n\n\n# The SQLite3 module doesn't work in IronPython on Mac, so we must make a call\n# to the Honeybee CLI (which runs on CPython) to get the results.\ndef get_results_mac(sql_files, elec_emiss):\n from collections import OrderedDict\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'carbon-emission-intensity']\n cmds.extend(sql_files)\n cmds.extend(['--electricity-emissions', str(elec_emiss)])\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE)\n stdout = process.communicate()\n results = json.loads(stdout[0], object_pairs_hook=OrderedDict)\n return results['carbon_intensity'], results['total_floor_area'], \\\n results['end_uses'], results['sources']\n\n\nif all_required_inputs(ghenv.Component):\n # ensure that _sql is a list rather than a single string\n if isinstance(_sql, basestring):\n _sql = [_sql]\n\n # process the location and year or the electricity intensity\n if isinstance(_loc_kgMWh, Location):\n yr = 2030 if _year_ is None else int(_year_)\n elec_emiss = future_electricity_emissions(_loc_kgMWh, yr)\n if elec_emiss is None:\n msg = 'Location must be inside the USA in order to be used for carbon ' \\\n 'emissions estimation.\\nPlug in a number for carbon intensity in ' \\\n 'kg CO2/MWH for locations outside the USA.'\n print(msg)\n raise ValueError(msg)\n else:\n try:\n elec_emiss = float(_loc_kgMWh)\n except TypeError:\n msg = 'Expected location object or number for _loccation. ' \\\n 'Got {}.'.format(type(_loc_kgMWh))\n raise ValueError(msg)\n\n # get the results\n get_results = get_results_windows if os.name == 'nt' else get_results_mac\n cei, gross_floor, end_use_pairs, sources = get_results(_sql, elec_emiss)\n\n # create separate lists for end use values and labels\n cei_end_use = end_use_pairs.values()\n end_uses = [use.replace('_', ' ').title() for use in end_use_pairs.keys()]\n\n # give a warning if the sources include district heating or cooling\n if 'district_heat' in sources:\n msg = 'District heating was found in the results and so carbon emissions ' \\\n 'cannot be accurately estimated.\\nTry using a different HVAC or SHW system.'\n print(msg)\n give_warning(ghenv.Component, msg)\n if 'district_cool' in sources:\n msg = 'District cooling was found in the results and so carbon emissions ' \\\n 'cannot be accurately estimated.\\nTry using a different HVAC system.'\n print(msg)\n give_warning(ghenv.Component, msg)\n",
"category": "HB-Energy",
"name": "HB Carbon Emission Intensity",
"description": "Get information about carbon emission intensity (CEI) from an EnergyPlus SQL file.\n_\nThe location and year (or input emissions of electricity intensity) will be used\nto compute carbon intensity for both electricity and district heating/cooling.\nFixed numbers will be used to convert the following on-site fuel sources:\n_\n* Natural Gas -- 277.358 kg/MWh\n* Propane -- 323.897 kg/MWh\n* Fuel Oil -- 294.962 kg/MWh\n-"
Expand Down
4 changes: 2 additions & 2 deletions honeybee_grasshopper_energy/json/HB_Color_Rooms.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.6.1",
"nickname": "ColorRooms",
"outputs": [
[
Expand Down Expand Up @@ -113,7 +113,7 @@
}
],
"subcategory": "6 :: Result",
"code": "\n\ntry:\n from honeybee.model import Model\n from honeybee.room import Room\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.result.colorobj import ColorRoom\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_point3d\n from ladybug_{{cad}}.fromgeometry import from_face3ds_to_colored_mesh, \\\n from_polyface3d_to_wireframe\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.color import color_to_color\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\n from ladybug_{{cad}}.config import units_abbreviation\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef split_solar_enclosure_data(data_to_split, rooms):\n \"\"\"Split solar enclosure data according to exterior aperture area.\"\"\"\n # figure out the ratios of exterior aperture area in each room\n enclosures = Room.group_by_air_boundary_adjacency(rooms)\n encl_ratios = {}\n for encl in enclosures:\n if len(encl) != 1:\n ap_areas = [rm.exterior_aperture_area for rm in encl]\n total_a = sum(ap_areas)\n if total_a != 0:\n rat_dict = {rm.identifier: ap / total_a\n for rm, ap in zip(encl, ap_areas)}\n else:\n rat_dict = {rm.identifier: 0 for rm in encl}\n encl_ratios[encl[0].identifier] = rat_dict\n encl_ratios = [x for _, x in sorted(zip(encl_ratios.keys(), encl_ratios.values()))]\n\n # create the list of split data collections\n split_data, enc_count = [], 0\n for dat in data_to_split:\n if 'Solar Enclosure' in dat.header.metadata['Zone']:\n rm_ratios = encl_ratios[enc_count]\n for rm_id, rm_rat in rm_ratios.items():\n new_data = dat.duplicate()\n new_data.header.metadata['Zone'] = rm_id.upper()\n new_data.values = [val * rm_rat for val in dat.values]\n split_data.append(new_data)\n enc_count += 1\n else:\n split_data.append(dat)\n return split_data\n\n\nif all_required_inputs(ghenv.Component):\n # extract any rooms from input Models\n rooms = []\n for hb_obj in _rooms_model:\n if isinstance(hb_obj, Model):\n rooms.extend(hb_obj.rooms)\n else:\n rooms.append(hb_obj)\n\n # apply analysis period to the data if connected\n if period_ is not None:\n _data = [coll.filter_by_analysis_period(period_) for coll in _data]\n\n # set default norm_by_floor value\n norm_by_flr_ = True if norm_by_flr_ is None else norm_by_flr_\n\n # sense if the conneccted data is for a solar enclosure and split the data if so\n zone_solar = 'Zone Windows Total Transmitted Solar Radiation Energy'\n if isinstance(_rooms_model[0], Model) and 'type' in _data[0].header.metadata and \\\n _data[0].header.metadata['type'] == zone_solar:\n _data = split_solar_enclosure_data(_data, rooms)\n\n # create the ColorRoom visualization object and output geometry\n color_obj = ColorRoom(_data, rooms, legend_par_, sim_step_, norm_by_flr_,\n units_abbreviation())\n graphic = color_obj.graphic_container\n mesh = [from_face3ds_to_colored_mesh(flrs, col) for flrs, col in\n zip(color_obj.matched_floor_faces, graphic.value_colors)]\n wire_frame = []\n for room in rooms:\n wire_frame.extend(from_polyface3d_to_wireframe(room.geometry))\n legend = legend_objects(graphic.legend)\n title = text_objects(color_obj.title_text, graphic.lower_title_location,\n graphic.legend_parameters.text_height,\n graphic.legend_parameters.font)\n rooms = color_obj.matched_rooms\n colors = [color_to_color(col, 125) for col in graphic.value_colors]\n values = graphic.values\n vis_set = color_obj\n",
"code": "\n\ntry:\n from honeybee.model import Model\n from honeybee.room import Room\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.result.colorobj import ColorRoom\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_point3d\n from ladybug_{{cad}}.fromgeometry import from_face3ds_to_colored_mesh, \\\n from_polyface3d_to_wireframe\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.color import color_to_color\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\n from ladybug_{{cad}}.config import units_abbreviation\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef split_solar_enclosure_data(data_to_split, rooms):\n \"\"\"Split solar enclosure data according to exterior aperture area.\"\"\"\n # figure out the ratios of exterior aperture area in each room\n enclosures = Room.group_by_air_boundary_adjacency(rooms)\n encl_ratios = {}\n for encl in enclosures:\n if len(encl) != 1:\n ap_areas = [rm.exterior_aperture_area for rm in encl]\n total_a = sum(ap_areas)\n if total_a != 0:\n rat_dict = {rm.identifier: ap / total_a\n for rm, ap in zip(encl, ap_areas)}\n else:\n rat_dict = {rm.identifier: 0 for rm in encl}\n encl_ratios[encl[0].identifier] = rat_dict\n encl_ratios = [x for _, x in sorted(zip(encl_ratios.keys(), encl_ratios.values()))]\n\n # create the list of split data collections\n split_data, enc_count = [], 0\n for dat in data_to_split:\n if 'Solar Enclosure' in dat.header.metadata['Zone']:\n rm_ratios = encl_ratios[enc_count]\n for rm_id, rm_rat in rm_ratios.items():\n new_data = dat.duplicate()\n new_data.header.metadata['Zone'] = rm_id.upper()\n new_data.values = [val * rm_rat for val in dat.values]\n split_data.append(new_data)\n enc_count += 1\n else:\n split_data.append(dat)\n return split_data\n\n\nif all_required_inputs(ghenv.Component):\n # extract any rooms from input Models\n rooms = []\n for hb_obj in _rooms_model:\n if isinstance(hb_obj, Model):\n rooms.extend(hb_obj.rooms)\n else:\n rooms.append(hb_obj)\n\n # apply analysis period to the data if connected\n if period_ is not None:\n _data = [coll.filter_by_analysis_period(period_) for coll in _data]\n\n # set default norm_by_floor value\n norm_by_flr_ = True if norm_by_flr_ is None else norm_by_flr_\n\n # sense if the conneccted data is for a solar enclosure and split the data if so\n space_based = False\n zone_solar = 'Zone Windows Total Transmitted Solar Radiation Energy'\n if 'type' in _data[0].header.metadata and _data[0].header.metadata['type'] == zone_solar:\n space_based = True\n if isinstance(_rooms_model[0], Model):\n _data = split_solar_enclosure_data(_data, rooms)\n\n # create the ColorRoom visualization object and output geometry\n color_obj = ColorRoom(_data, rooms, legend_par_, sim_step_, norm_by_flr_,\n units_abbreviation(), space_based=space_based)\n graphic = color_obj.graphic_container\n mesh = [from_face3ds_to_colored_mesh(flrs, col) for flrs, col in\n zip(color_obj.matched_floor_faces, graphic.value_colors)]\n wire_frame = []\n for room in rooms:\n wire_frame.extend(from_polyface3d_to_wireframe(room.geometry))\n legend = legend_objects(graphic.legend)\n title = text_objects(color_obj.title_text, graphic.lower_title_location,\n graphic.legend_parameters.text_height,\n graphic.legend_parameters.font)\n rooms = color_obj.matched_rooms\n colors = [color_to_color(col, 125) for col in graphic.value_colors]\n values = graphic.values\n vis_set = color_obj\n",
"category": "HB-Energy",
"name": "HB Color Rooms",
"description": "Visualize Room-level energy simulation results as colored Room geometry.\n-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

ghenv.Component.Name = 'HB Carbon Emission Intensity'
ghenv.Component.NickName = 'CEI'
ghenv.Component.Message = '1.6.0'
ghenv.Component.Message = '1.6.1'
ghenv.Component.Category = 'HB-Energy'
ghenv.Component.SubCategory = '6 :: Result'
ghenv.Component.AdditionalHelpFromDocStrings = '0'
Expand Down Expand Up @@ -98,6 +98,7 @@ def get_results_windows(sql_files, elec_emiss):
# The SQLite3 module doesn't work in IronPython on Mac, so we must make a call
# to the Honeybee CLI (which runs on CPython) to get the results.
def get_results_mac(sql_files, elec_emiss):
from collections import OrderedDict
cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',
'carbon-emission-intensity']
cmds.extend(sql_files)
Expand Down
12 changes: 7 additions & 5 deletions honeybee_grasshopper_energy/src/HB Color Rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

ghenv.Component.Name = "HB Color Rooms"
ghenv.Component.NickName = 'ColorRooms'
ghenv.Component.Message = '1.6.0'
ghenv.Component.Message = '1.6.1'
ghenv.Component.Category = 'HB-Energy'
ghenv.Component.SubCategory = '6 :: Result'
ghenv.Component.AdditionalHelpFromDocStrings = '2'
Expand Down Expand Up @@ -142,14 +142,16 @@ def split_solar_enclosure_data(data_to_split, rooms):
norm_by_flr_ = True if norm_by_flr_ is None else norm_by_flr_

# sense if the conneccted data is for a solar enclosure and split the data if so
space_based = False
zone_solar = 'Zone Windows Total Transmitted Solar Radiation Energy'
if isinstance(_rooms_model[0], Model) and 'type' in _data[0].header.metadata and \
_data[0].header.metadata['type'] == zone_solar:
_data = split_solar_enclosure_data(_data, rooms)
if 'type' in _data[0].header.metadata and _data[0].header.metadata['type'] == zone_solar:
space_based = True
if isinstance(_rooms_model[0], Model):
_data = split_solar_enclosure_data(_data, rooms)

# create the ColorRoom visualization object and output geometry
color_obj = ColorRoom(_data, rooms, legend_par_, sim_step_, norm_by_flr_,
units_abbreviation())
units_abbreviation(), space_based=space_based)
graphic = color_obj.graphic_container
mesh = [from_face3ds_to_colored_mesh(flrs, col) for flrs, col in
zip(color_obj.matched_floor_faces, graphic.value_colors)]
Expand Down
Binary file not shown.
Binary file modified honeybee_grasshopper_energy/user_objects/HB Color Rooms.ghuser
Binary file not shown.

0 comments on commit 2c28923

Please sign in to comment.