Skip to content

Commit

Permalink
fix(python): Ensure compatibility with Python 3 for Rhino 8 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Aug 21, 2023
1 parent 1ecfc86 commit 9d87d49
Show file tree
Hide file tree
Showing 24 changed files with 24 additions and 25 deletions.
Binary file modified honeybee_grasshopper_energy/icon/HB Annual Loads.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 honeybee_grasshopper_energy/icon/HB Balance Temperature.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 honeybee_grasshopper_energy/icon/HB Run IDF.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 honeybee_grasshopper_energy/icon/HB Run OSM.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 honeybee_grasshopper_energy/icon/HB Run OSW.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 honeybee_grasshopper_energy/icon/HB Thermal Load Balance.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 honeybee_grasshopper_energy/json/HB_Annual_Loads.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions honeybee_grasshopper_energy/json/HB_Balance_Temperature.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.6.1",
"nickname": "BalTemp",
"outputs": [
[
Expand Down Expand Up @@ -50,7 +50,7 @@
}
],
"subcategory": "6 :: Result",
"code": "\ntry:\n from ladybug.datacollection import HourlyContinuousCollection, DailyCollection\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef sum_collection(data):\n \"\"\"Sum a list of data collections into a single daily collection.\"\"\"\n total_data = data[0]\n for data_i in data[1:]:\n total_data = total_data + data_i\n if isinstance(total_data, HourlyContinuousCollection):\n total_data = total_data.average_daily()\n elif not isinstance(total_data, DailyCollection):\n raise TypeError('Expected Hourly or Daily data collection. '\n 'Got {}'.format(type(_temperature)))\n return total_data\n\n\nif all_required_inputs(ghenv.Component):\n # set the defaut day count and ensure temperature is daily\n _day_count_ = 10 if _day_count_ is None else _day_count_\n if isinstance(_temperature, HourlyContinuousCollection):\n _temperature = _temperature.average_daily()\n elif not isinstance(_temperature, DailyCollection):\n raise TypeError('Expected Hourly or Daily data collection for '\n '_temperature. Got {}'.format(type(_temperature)))\n\n # convert the heating and cooling collections to a single daily balance\n total_cool = sum_collection(_cooling)\n total_heat = sum_collection(_heating)\n total_load = total_cool + total_heat\n\n # check that all data collections are annual\n assert len(total_load) >= 365, 'Cooling and heating loads are not annual.'\n assert len(_temperature) >= 365, 'Temperature is not annual.'\n\n # sort the load to find the days with the lowest load\n temp_sort = []\n load_sort = []\n for i, (load, temp) in enumerate(sorted(zip(total_load, _temperature))):\n if i == _day_count_:\n break\n temp_sort.append(temp)\n load_sort.append(load)\n\n # return the average temperature and balance day load\n print len(temp_sort)\n bal_day_load = sum(load_sort) / _day_count_\n bal_temp = sum(temp_sort) / _day_count_\n",
"code": "\ntry:\n from ladybug.datacollection import HourlyContinuousCollection, DailyCollection\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef sum_collection(data):\n \"\"\"Sum a list of data collections into a single daily collection.\"\"\"\n total_data = data[0]\n for data_i in data[1:]:\n total_data = total_data + data_i\n if isinstance(total_data, HourlyContinuousCollection):\n total_data = total_data.average_daily()\n elif not isinstance(total_data, DailyCollection):\n raise TypeError('Expected Hourly or Daily data collection. '\n 'Got {}'.format(type(_temperature)))\n return total_data\n\n\nif all_required_inputs(ghenv.Component):\n # set the defaut day count and ensure temperature is daily\n _day_count_ = 10 if _day_count_ is None else _day_count_\n if isinstance(_temperature, HourlyContinuousCollection):\n _temperature = _temperature.average_daily()\n elif not isinstance(_temperature, DailyCollection):\n raise TypeError('Expected Hourly or Daily data collection for '\n '_temperature. Got {}'.format(type(_temperature)))\n\n # convert the heating and cooling collections to a single daily balance\n total_cool = sum_collection(_cooling)\n total_heat = sum_collection(_heating)\n total_load = total_cool + total_heat\n\n # check that all data collections are annual\n assert len(total_load) >= 365, 'Cooling and heating loads are not annual.'\n assert len(_temperature) >= 365, 'Temperature is not annual.'\n\n # sort the load to find the days with the lowest load\n temp_sort = []\n load_sort = []\n for i, (load, temp) in enumerate(sorted(zip(total_load, _temperature))):\n if i == _day_count_:\n break\n temp_sort.append(temp)\n load_sort.append(load)\n\n # return the average temperature and balance day load\n bal_day_load = sum(load_sort) / _day_count_\n bal_temp = sum(temp_sort) / _day_count_\n",
"category": "HB-Energy",
"name": "HB Balance Temperature",
"description": "Calculate a building (or zone) balance temperature from a ideal air load simulation\nresults. The balance point is the outdoor temperature at which a building switches\nbetween heating and cooling.\n_\nIf the outdoor temperture drops below the balance temperature, the building will\nusually be in heating mode and, if the outdoor temperture is above the balance\ntemperature, the building will usually be in cooling mode.\n_\nThe balance temperture concept is useful for setting things such as automated\nblinds and airflow schedules since having these things directly controlled by\nhourly cooling or heating demand isn't always straightforward.\n_\nThis component works by taking the average combined heating/cooling values for\neach day and the average outdoor air temperature for each day. The days with\nthe smallest combined heating + cooling will have their daily mean outdoor air\ntempertures averaged to produce the output balance temperture.\n-"
Expand Down
4 changes: 2 additions & 2 deletions honeybee_grasshopper_energy/json/HB_Run_IDF.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.6.1",
"nickname": "RunIDF",
"outputs": [
[
Expand Down Expand Up @@ -71,7 +71,7 @@
}
],
"subcategory": "5 :: Simulate",
"code": "\nimport os\nimport shutil\n\ntry:\n from ladybug.futil import preparedir\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.run import run_idf\n from honeybee_energy.result.err import Err\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, \\\n recommended_processor_count, run_function_in_parallel\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef run_idf_and_report_errors(i):\n \"\"\"Run an IDF file through EnergyPlus and report errors/warnings on this component.\"\"\"\n # process the additional strings\n idf_i = idfs[i]\n if add_str_ != [] and add_str_[0] is not None:\n a_str = '/n'.join(add_str_)\n with open(idf_i, \"a\") as idf_file:\n idf_file.write(a_str)\n sql_i, zsz_i, rdd_i, html_i, err_i = run_idf(idf_i, _epw_file, silent=silent)\n\n # report any errors on this component\n if err_i is not None:\n err_obj = Err(err_i)\n err_objs[i] = err_obj\n for warn in err_obj.severe_errors:\n give_warning(ghenv.Component, warn)\n for error in err_obj.fatal_errors:\n print err_obj.file_contents # print before raising the error\n raise Exception(error)\n\n # append everything to the global lists\n sql[i] = sql_i\n zsz[i] = zsz_i\n rdd[i] = rdd_i\n html[i] = html_i\n err[i] = err_i\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # global lists of outputs to be filled\n iter_count = len(_idf)\n sql = [None] * iter_count\n zsz = [None] * iter_count\n rdd = [None] * iter_count\n html = [None] * iter_count\n err = [None] * iter_count\n err_objs = [None] * iter_count\n\n # copy the IDFs into a sub-directory if they are not already labeled as in.idf\n idfs = []\n for idf_file_path in _idf:\n idf_dir, idf_file_name = os.path.split(idf_file_path)\n if idf_file_name != 'in.idf': # copy the IDF file into a sub-directory\n sub_dir = os.path.join(idf_dir, 'run')\n target = os.path.join(sub_dir, 'in.idf')\n preparedir(sub_dir)\n shutil.copy(idf_file_path, target)\n idfs.append(target)\n else:\n idfs.append(idf_file_path)\n\n # run the IDF files through E+\n silent = True if _run == 2 else False\n if _cpu_count_ is not None:\n workers = _cpu_count_\n else:\n workers = recommended_processor_count() if iter_count != 1 else 1\n run_function_in_parallel(run_idf_and_report_errors, iter_count, workers)\n\n # print out error report if it's only one\n # otherwise it's too much data to be read-able\n if len(err_objs) == 1:\n print(err_objs[0].file_contents)\n",
"code": "\nimport os\nimport shutil\n\ntry:\n from ladybug.futil import preparedir\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.run import run_idf\n from honeybee_energy.result.err import Err\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, \\\n recommended_processor_count, run_function_in_parallel\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef run_idf_and_report_errors(i):\n \"\"\"Run an IDF file through EnergyPlus and report errors/warnings on this component.\"\"\"\n # process the additional strings\n idf_i = idfs[i]\n if add_str_ != [] and add_str_[0] is not None:\n a_str = '/n'.join(add_str_)\n with open(idf_i, \"a\") as idf_file:\n idf_file.write(a_str)\n sql_i, zsz_i, rdd_i, html_i, err_i = run_idf(idf_i, _epw_file, silent=silent)\n\n # report any errors on this component\n if err_i is not None:\n err_obj = Err(err_i)\n err_objs[i] = err_obj\n for warn in err_obj.severe_errors:\n give_warning(ghenv.Component, warn)\n for error in err_obj.fatal_errors:\n print(err_obj.file_contents) # print before raising the error\n raise Exception(error)\n\n # append everything to the global lists\n sql[i] = sql_i\n zsz[i] = zsz_i\n rdd[i] = rdd_i\n html[i] = html_i\n err[i] = err_i\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # global lists of outputs to be filled\n iter_count = len(_idf)\n sql = [None] * iter_count\n zsz = [None] * iter_count\n rdd = [None] * iter_count\n html = [None] * iter_count\n err = [None] * iter_count\n err_objs = [None] * iter_count\n\n # copy the IDFs into a sub-directory if they are not already labeled as in.idf\n idfs = []\n for idf_file_path in _idf:\n idf_dir, idf_file_name = os.path.split(idf_file_path)\n if idf_file_name != 'in.idf': # copy the IDF file into a sub-directory\n sub_dir = os.path.join(idf_dir, 'run')\n target = os.path.join(sub_dir, 'in.idf')\n preparedir(sub_dir)\n shutil.copy(idf_file_path, target)\n idfs.append(target)\n else:\n idfs.append(idf_file_path)\n\n # run the IDF files through E+\n silent = True if _run == 2 else False\n if _cpu_count_ is not None:\n workers = _cpu_count_\n else:\n workers = recommended_processor_count() if iter_count != 1 else 1\n run_function_in_parallel(run_idf_and_report_errors, iter_count, workers)\n\n # print out error report if it's only one\n # otherwise it's too much data to be read-able\n if len(err_objs) == 1:\n print(err_objs[0].file_contents)\n",
"category": "HB-Energy",
"name": "HB Run IDF",
"description": "Run an IDF file through EnergyPlus.\n-"
Expand Down
4 changes: 2 additions & 2 deletions honeybee_grasshopper_energy/json/HB_Run_OSM.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.6.1",
"nickname": "RunOSM",
"outputs": [
[
Expand Down Expand Up @@ -85,7 +85,7 @@
}
],
"subcategory": "5 :: Simulate",
"code": "\nimport os\nimport json\n\ntry:\n from honeybee_energy.run import run_osw, run_idf\n from honeybee_energy.result.err import Err\n from honeybee_energy.result.osw import OSW\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, \\\n recommended_processor_count, run_function_in_parallel\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef run_osm_and_report_errors(i):\n \"\"\"Run an OSW through OpenStudio CLI.\"\"\"\n # create a blank osw for the translation\n osw_dict = {\n 'seed_file': _osm[i],\n 'weather_file': _epw_file\n }\n osw_directory = os.path.dirname(_osm[i])\n sch_directory1 = os.path.join(os.path.dirname(osw_directory), 'schedules')\n sch_directory2 = os.path.join(osw_directory, 'schedules')\n if os.path.isdir(sch_directory1):\n osw_dict['file_paths'] = [sch_directory1]\n elif os.path.isdir(sch_directory2):\n osw_dict['file_paths'] = [sch_directory2]\n osw = os.path.join(osw_directory, 'workflow.osw')\n with open(osw, 'w') as fp:\n json.dump(osw_dict, fp, indent=4)\n\n # get an IDF from the OSM using the OpenStudio CLI\n osm_i, idf_i = run_osw(osw, silent=silent)\n if idf_i is None:\n log_osw = OSW(os.path.join(osw_directory, 'out.osw'))\n errors = []\n print(log_osw.stdout)\n for error, tb in zip(log_osw.errors, log_osw.error_tracebacks):\n print(tb)\n errors.append(error)\n raise Exception('Failed to run OpenStudio CLI:\\n{}'.format('\\n'.join(errors)))\n\n # process the additional strings\n if add_str_ != [] and add_str_[0] is not None and idf is not None:\n a_str = '/n'.join(add_str_)\n with open(idf_i, \"a\") as idf_file:\n idf_file.write(a_str)\n osm[i] = osm_i\n idf[i] = idf_i\n\n # run the IDF through EnergyPlus\n if run_:\n sql_i, zsz_i, rdd_i, html_i, err_i = run_idf(idf_i, _epw_file, silent=silent)\n\n # report any errors on this component\n if err_i is not None:\n err_obj = Err(err_i)\n err_objs[i] = err_obj\n for warn in err_obj.severe_errors:\n give_warning(ghenv.Component, warn)\n for error in err_obj.fatal_errors:\n print err_obj.file_contents # print before raising the error\n raise Exception(error)\n\n # append everything to the global lists\n sql[i] = sql_i\n zsz[i] = zsz_i\n rdd[i] = rdd_i\n html[i] = html_i\n err[i] = err_i\n\n\nif all_required_inputs(ghenv.Component) and _translate:\n # global lists of outputs to be filled\n iter_count = len(_osm)\n osm = [None] * iter_count\n idf = [None] * iter_count\n sql = [None] * iter_count\n zsz = [None] * iter_count\n rdd = [None] * iter_count\n html = [None] * iter_count\n err = [None] * iter_count\n err_objs = [None] * iter_count\n\n # run the OSW files through OpenStudio CLI\n silent = True if run_ == 2 else False\n if _cpu_count_ is not None:\n workers = _cpu_count_\n else:\n workers = recommended_processor_count() if iter_count != 1 else 1\n run_function_in_parallel(run_osm_and_report_errors, iter_count, workers)\n\n # print out error report if it's only one file\n # otherwise it's too much data to be read-able\n if len(err_objs) == 1 and err_objs[0] is not None:\n print(err_objs[0].file_contents)\n",
"code": "\nimport os\nimport json\n\ntry:\n from honeybee_energy.run import run_osw, run_idf\n from honeybee_energy.result.err import Err\n from honeybee_energy.result.osw import OSW\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, \\\n recommended_processor_count, run_function_in_parallel\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\ndef run_osm_and_report_errors(i):\n \"\"\"Run an OSW through OpenStudio CLI.\"\"\"\n # create a blank osw for the translation\n osw_dict = {\n 'seed_file': _osm[i],\n 'weather_file': _epw_file\n }\n osw_directory = os.path.dirname(_osm[i])\n sch_directory1 = os.path.join(os.path.dirname(osw_directory), 'schedules')\n sch_directory2 = os.path.join(osw_directory, 'schedules')\n if os.path.isdir(sch_directory1):\n osw_dict['file_paths'] = [sch_directory1]\n elif os.path.isdir(sch_directory2):\n osw_dict['file_paths'] = [sch_directory2]\n osw = os.path.join(osw_directory, 'workflow.osw')\n with open(osw, 'w') as fp:\n json.dump(osw_dict, fp, indent=4)\n\n # get an IDF from the OSM using the OpenStudio CLI\n osm_i, idf_i = run_osw(osw, silent=silent)\n if idf_i is None:\n log_osw = OSW(os.path.join(osw_directory, 'out.osw'))\n errors = []\n print(log_osw.stdout)\n for error, tb in zip(log_osw.errors, log_osw.error_tracebacks):\n print(tb)\n errors.append(error)\n raise Exception('Failed to run OpenStudio CLI:\\n{}'.format('\\n'.join(errors)))\n\n # process the additional strings\n if add_str_ != [] and add_str_[0] is not None and idf is not None:\n a_str = '/n'.join(add_str_)\n with open(idf_i, \"a\") as idf_file:\n idf_file.write(a_str)\n osm[i] = osm_i\n idf[i] = idf_i\n\n # run the IDF through EnergyPlus\n if run_:\n sql_i, zsz_i, rdd_i, html_i, err_i = run_idf(idf_i, _epw_file, silent=silent)\n\n # report any errors on this component\n if err_i is not None:\n err_obj = Err(err_i)\n err_objs[i] = err_obj\n for warn in err_obj.severe_errors:\n give_warning(ghenv.Component, warn)\n for error in err_obj.fatal_errors:\n print(err_obj.file_contents) # print before raising the error\n raise Exception(error)\n\n # append everything to the global lists\n sql[i] = sql_i\n zsz[i] = zsz_i\n rdd[i] = rdd_i\n html[i] = html_i\n err[i] = err_i\n\n\nif all_required_inputs(ghenv.Component) and _translate:\n # global lists of outputs to be filled\n iter_count = len(_osm)\n osm = [None] * iter_count\n idf = [None] * iter_count\n sql = [None] * iter_count\n zsz = [None] * iter_count\n rdd = [None] * iter_count\n html = [None] * iter_count\n err = [None] * iter_count\n err_objs = [None] * iter_count\n\n # run the OSW files through OpenStudio CLI\n silent = True if run_ == 2 else False\n if _cpu_count_ is not None:\n workers = _cpu_count_\n else:\n workers = recommended_processor_count() if iter_count != 1 else 1\n run_function_in_parallel(run_osm_and_report_errors, iter_count, workers)\n\n # print out error report if it's only one file\n # otherwise it's too much data to be read-able\n if len(err_objs) == 1 and err_objs[0] is not None:\n print(err_objs[0].file_contents)\n",
"category": "HB-Energy",
"name": "HB Run OSM",
"description": "Translate a fully-simualte-able OpenStudio model (.osm) to an IDF and run the it\nthrough EnergyPlus.\n-"
Expand Down
Loading

0 comments on commit 9d87d49

Please sign in to comment.