Skip to content

Commit

Permalink
fix(des): Update to run GHE sizing with GeoJSON geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Nov 29, 2024
1 parent 2424fcd commit 5c003f1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dragonfly_grasshopper/json/DF_Run_Modelica_DES.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.2",
"version": "1.8.3",
"nickname": "RunDES",
"outputs": [
[
Expand Down Expand Up @@ -57,7 +57,7 @@
}
],
"subcategory": "5 :: District Thermal",
"code": "\nimport os\nimport subprocess\n\ntry:\n from ladybug.futil import nukedir\n from ladybug.config import folders as lb_folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\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: # import the dragonfly_energy dependencies\n from dragonfly_energy.config import folders as df_folders\n from dragonfly_energy.run import run_des_sys_param, run_des_modelica, \\\n run_modelica_docker\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.download import download_file_by_name\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\nUO_GMT_VERSION = '0.8.0'\nUO_TN_VERSION = '0.3.0'\nMBL_VERSION = '10.0.0'\n\n\nif all_required_inputs(ghenv.Component) and _write:\n # set up the custom python environment\n custom_env = os.environ.copy()\n custom_env['PYTHONHOME'] = ''\n\n # set global values\n ext = '.exe' if os.name == 'nt' else ''\n executor_path = os.path.join(\n lb_folders.ladybug_tools_folder, '{{plugin}}',\n 'ladybug_{{plugin}}_dotnet', 'Ladybug.Executor.exe')\n\n # check to see if the geojson-modelica-translator is installed\n uo_gmt = '{}/uo_des{}'.format(folders.python_scripts_path, ext)\n uo_gmt_pack = '{}/geojson_modelica_translator-{}.dist-info'.format(\n folders.python_package_path, UO_GMT_VERSION)\n if not os.path.isfile(uo_gmt) or not os.path.isdir(uo_gmt_pack):\n install_cmd = 'pip install geojson-modelica-translator=={}'.format(UO_GMT_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the ThermalNetwork package is installed\n uo_tn = '{}/thermalnetwork{}'.format(folders.python_scripts_path, ext)\n uo_tn_pack = '{}/ThermalNetwork-{}.dist-info'.format(\n folders.python_package_path, UO_TN_VERSION)\n if not os.path.isfile(uo_tn) or not os.path.isdir(uo_tn_pack):\n install_cmd = 'pip install thermalnetwork=={}'.format(UO_TN_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the Modelica Buildings Library is installed\n install_directory = os.path.join(lb_folders.ladybug_tools_folder, 'resources')\n final_dir = os.path.join(install_directory, 'mbl')\n version_file = os.path.join(final_dir, 'version.txt')\n already_installed = False\n if os.path.isdir(final_dir) and os.path.isfile(version_file):\n with open(version_file, 'r') as vf:\n install_version = vf.read()\n if install_version == MBL_VERSION:\n already_installed = True\n else:\n nukedir(final_dir, True)\n if not already_installed:\n install_cmd = 'dragonfly_energy install mbl --version {}'.format(MBL_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # run the command that adds the building loads to the system parameters\n sys_param = run_des_sys_param(_geojson, _scenario)\n\n # run the command that generates the modelica files\n modelica = run_des_modelica(sys_param, _geojson, _scenario)\n\n # execute the modelica files in URBANopt\n if run_:\n if df_folders.docker_version_str is not None:\n results = run_modelica_docker(modelica)\n else:\n docker_url = 'https://www.docker.com/products/docker-desktop/'\n msg = 'No Docker installation was found on this machine.\\n' \\\n 'This is needed to execute Modelica simulations.\\n' \\\n 'Download Docker Desktop from: {}'.format(docker_url)\n print(msg)\n give_warning(ghenv.Component, msg)\n",
"code": "\nimport os\nimport subprocess\n\ntry:\n from ladybug.futil import nukedir\n from ladybug.config import folders as lb_folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\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: # import the dragonfly_energy dependencies\n from dragonfly_energy.config import folders as df_folders\n from dragonfly_energy.run import run_des_sys_param, run_des_modelica, \\\n run_modelica_docker\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.download import download_file_by_name\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\nUO_GMT_VERSION = '0.8.0'\nUO_TN_VERSION = '0.1.dev194+gddad013'\nMBL_VERSION = '10.0.0'\n\n\nif all_required_inputs(ghenv.Component) and _write:\n # set up the custom python environment\n custom_env = os.environ.copy()\n custom_env['PYTHONHOME'] = ''\n\n # set global values\n ext = '.exe' if os.name == 'nt' else ''\n executor_path = os.path.join(\n lb_folders.ladybug_tools_folder, '{{plugin}}',\n 'ladybug_{{plugin}}_dotnet', 'Ladybug.Executor.exe')\n\n # check to see if the geojson-modelica-translator is installed\n uo_gmt = '{}/uo_des{}'.format(folders.python_scripts_path, ext)\n uo_gmt_pack = '{}/geojson_modelica_translator-{}.dist-info'.format(\n folders.python_package_path, UO_GMT_VERSION)\n if not os.path.isfile(uo_gmt) or not os.path.isdir(uo_gmt_pack):\n install_cmd = 'pip install geojson-modelica-translator=={}'.format(UO_GMT_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the ThermalNetwork package is installed\n uo_tn = '{}/thermalnetwork{}'.format(folders.python_scripts_path, ext)\n uo_tn_pack = '{}/ThermalNetwork-{}.dist-info'.format(\n folders.python_package_path, UO_TN_VERSION)\n if not os.path.isfile(uo_tn) or not os.path.isdir(uo_tn_pack):\n # install_cmd = 'pip install thermalnetwork=={}'.format(UO_TN_VERSION)\n install_cmd = 'pip install git+https://github.com/chriswmackey/ThermalNetwork'\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the Modelica Buildings Library is installed\n install_directory = os.path.join(lb_folders.ladybug_tools_folder, 'resources')\n final_dir = os.path.join(install_directory, 'mbl')\n version_file = os.path.join(final_dir, 'version.txt')\n already_installed = False\n if os.path.isdir(final_dir) and os.path.isfile(version_file):\n with open(version_file, 'r') as vf:\n install_version = vf.read()\n if install_version == MBL_VERSION:\n already_installed = True\n else:\n nukedir(final_dir, True)\n if not already_installed:\n install_cmd = 'dragonfly_energy install mbl --version {}'.format(MBL_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # run the command that adds the building loads to the system parameters\n sys_param = run_des_sys_param(_geojson, _scenario)\n\n # run the command that generates the modelica files\n modelica = run_des_modelica(sys_param, _geojson, _scenario)\n\n # execute the modelica files in URBANopt\n if run_:\n if df_folders.docker_version_str is not None:\n results = run_modelica_docker(modelica)\n else:\n docker_url = 'https://www.docker.com/products/docker-desktop/'\n msg = 'No Docker installation was found on this machine.\\n' \\\n 'This is needed to execute Modelica simulations.\\n' \\\n 'Download Docker Desktop from: {}'.format(docker_url)\n print(msg)\n give_warning(ghenv.Component, msg)\n",
"category": "Dragonfly",
"name": "DF Run Modelica DES",
"description": "Run a an URBANopt geoJSON and scenario through Modelica Distric Energy System\n(DES) simulation.\n_\nThe geoJSON must have a valid DES Loop assigned to it in order to run correctly\nthrough Modelica DES simulation.\n-"
Expand Down
7 changes: 4 additions & 3 deletions dragonfly_grasshopper/src/DF Run Modelica DES.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

ghenv.Component.Name = 'DF Run Modelica DES'
ghenv.Component.NickName = 'RunDES'
ghenv.Component.Message = '1.8.2'
ghenv.Component.Message = '1.8.3'
ghenv.Component.Category = 'Dragonfly'
ghenv.Component.SubCategory = '5 :: District Thermal'
ghenv.Component.AdditionalHelpFromDocStrings = '1'
Expand Down Expand Up @@ -73,7 +73,7 @@
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

UO_GMT_VERSION = '0.8.0'
UO_TN_VERSION = '0.3.0'
UO_TN_VERSION = '0.1.dev194+gddad013'
MBL_VERSION = '10.0.0'


Expand Down Expand Up @@ -112,7 +112,8 @@
uo_tn_pack = '{}/ThermalNetwork-{}.dist-info'.format(
folders.python_package_path, UO_TN_VERSION)
if not os.path.isfile(uo_tn) or not os.path.isdir(uo_tn_pack):
install_cmd = 'pip install thermalnetwork=={}'.format(UO_TN_VERSION)
# install_cmd = 'pip install thermalnetwork=={}'.format(UO_TN_VERSION)
install_cmd = 'pip install git+https://github.com/chriswmackey/ThermalNetwork'
if os.name == 'nt' and os.path.isfile(executor_path) and \
'Program Files' in executor_path:
pip_cmd = [
Expand Down
Binary file modified dragonfly_grasshopper/user_objects/DF Run Modelica DES.ghuser
Binary file not shown.
Binary file modified samples/ghe_example.gh
Binary file not shown.
Binary file added samples/ghe_multiple_example.gh
Binary file not shown.

0 comments on commit 5c003f1

Please sign in to comment.