diff --git a/honeybee_grasshopper_energy/icon/HB Read Environment Matrix.png b/honeybee_grasshopper_energy/icon/HB Read Environment Matrix.png index a24fd4f..5eacc2c 100644 Binary files a/honeybee_grasshopper_energy/icon/HB Read Environment Matrix.png and b/honeybee_grasshopper_energy/icon/HB Read Environment Matrix.png differ diff --git a/honeybee_grasshopper_energy/icon/HB Read Thermal Matrix.png b/honeybee_grasshopper_energy/icon/HB Read Thermal Matrix.png index b1563bf..ccf67fa 100644 Binary files a/honeybee_grasshopper_energy/icon/HB Read Thermal Matrix.png and b/honeybee_grasshopper_energy/icon/HB Read Thermal Matrix.png differ diff --git a/honeybee_grasshopper_energy/json/HB_Read_Environment_Matrix.json b/honeybee_grasshopper_energy/json/HB_Read_Environment_Matrix.json index 1f2f3a8..1a0bf5d 100644 --- a/honeybee_grasshopper_energy/json/HB_Read_Environment_Matrix.json +++ b/honeybee_grasshopper_energy/json/HB_Read_Environment_Matrix.json @@ -1,5 +1,5 @@ { - "version": "1.8.0", + "version": "1.8.1", "nickname": "EnvMtx", "outputs": [ [ @@ -36,7 +36,7 @@ } ], "subcategory": "7 :: Thermal Map", - "code": "\nimport subprocess\nimport os\nimport shutil\nimport json\n\ntry:\n from ladybug.datatype.temperature import AirTemperature, \\\n MeanRadiantTemperature, RadiantTemperature\n from ladybug.datatype.temperaturedelta import RadiantTemperatureDelta\n from ladybug.datatype.fraction import RelativeHumidity\n from ladybug.header import Header\n from ladybug.datacollection import HourlyContinuousCollection, \\\n HourlyDiscontinuousCollection\n from ladybug.futil import csv_to_num_matrix\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\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 ladybug_{{cad}}.{{plugin}} import all_required_inputs, objectify_output\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\nENV_CONDS_MAP = {\n '0': 'mrt',\n 'mrt': 'mrt',\n 'mean radiant temperature': 'mrt',\n '1': 'air_temperature',\n 'air temperature': 'air_temperature',\n '2': 'longwave_mrt',\n 'longwave mrt': 'longwave_mrt',\n '3': 'shortwave_mrt',\n 'shortwave mrt': 'shortwave_mrt',\n 'shortwave mrt delta': 'shortwave_mrt',\n '4': 'rel_humidity',\n 'relative humidity': 'rel_humidity'\n}\n\n\ndef load_matrix(comf_result):\n \"\"\"Load a matrix of data into an object that can be output in {{Plugin}}.\n\n Args:\n comf_result: Path to a folder with CSV data to be loaded into {{Plugin}}.\n \"\"\"\n # parse the result_info.json into a data collection header\n with open(os.path.join(comf_result, 'results_info.json')) as json_file:\n data_header = Header.from_dict(json.load(json_file))\n a_per = data_header.analysis_period\n continuous = True if a_per.st_hour == 0 and a_per.end_hour == 23 else False\n if not continuous:\n dates = a_per.datetimes\n\n # parse the grids_info.json with the correct order of the grid files\n with open(os.path.join(comf_result, 'grids_info.json')) as json_file:\n grid_list = json.load(json_file)\n\n # loop through the grid CSV files, parse their results, and build data collections\n comf_matrix = []\n for grid in grid_list:\n grid_name = grid['full_id'] if 'full_id' in grid else 'id'\n metadata = {'grid': grid_name}\n grid_file = os.path.join(comf_result, '{}.csv'.format(grid_name))\n data_matrix = csv_to_num_matrix(grid_file)\n grid_data = []\n for i, row in enumerate(data_matrix):\n header = data_header.duplicate()\n header.metadata = metadata.copy()\n header.metadata['sensor_index'] = i\n data = HourlyContinuousCollection(header, row) if continuous else \\\n HourlyDiscontinuousCollection(header, row, dates)\n grid_data.append(data)\n comf_matrix.append(grid_data)\n\n # wrap the maptrix into an object so that it does not slow the {{Plugin}} UI\n comf_mtx = objectify_output(\n '{} Matrix'.format(data_header.data_type.name), comf_matrix)\n return comf_mtx\n\n\ndef create_result_header(env_conds, sub_path):\n \"\"\"Create a DataCollection Header for a given metric.\"\"\"\n with open(os.path.join(env_conds, 'results_info.json')) as json_file:\n base_head = Header.from_dict(json.load(json_file))\n if sub_path == 'mrt':\n return Header(MeanRadiantTemperature(), 'C', base_head.analysis_period)\n elif sub_path == 'air_temperature':\n return Header(AirTemperature(), 'C', base_head.analysis_period)\n elif sub_path == 'longwave_mrt':\n return Header(RadiantTemperature(), 'C', base_head.analysis_period)\n elif sub_path == 'shortwave_mrt':\n return Header(RadiantTemperatureDelta(), 'dC', base_head.analysis_period)\n elif sub_path == 'rel_humidity':\n return Header(RelativeHumidity(), '%', base_head.analysis_period)\n\n\ndef sum_matrices(mtxs_1, mtxs_2, dest_dir):\n \"\"\"Sum together matrices of two folders.\"\"\"\n if not os.path.isdir(dest_dir):\n os.makedirs(dest_dir)\n for mtx_file in os.listdir(mtxs_1):\n if mtx_file.endswith('.csv'):\n mtx_file1 = os.path.join(mtxs_1, mtx_file)\n mtx_file2 = os.path.join(mtxs_2, mtx_file)\n matrix_1 = csv_to_num_matrix(mtx_file1)\n matrix_2 = csv_to_num_matrix(mtx_file2)\n data = [[d1 + d2 for d1, d2 in zip(r1, r2)]\n for r1, r2 in zip(matrix_1, matrix_2)]\n csv_path = os.path.join(dest_dir, mtx_file)\n with open(csv_path, 'w') as csv_file:\n for dat in data:\n str_data = (str(v) for v in dat)\n csv_file.write(','.join(str_data) + '\\n')\n elif mtx_file == 'grids_info.json':\n shutil.copyfile(\n os.path.join(mtxs_1, mtx_file),\n os.path.join(dest_dir, mtx_file)\n )\n\n\nif all_required_inputs(ghenv.Component) and _load:\n # get the folders and that correspond with the requested metric\n _metric_ = _metric_ if _metric_ is not None else 'mrt'\n try:\n sub_path = ENV_CONDS_MAP[_metric_.lower()]\n except KeyError:\n raise ValueError(\n 'Input metric \"{}\" is not recognized. Choose from: {}'.format(\n _metric_, '\\n'.join(ENV_CONDS_MAP.keys()))\n )\n source_folder = os.path.join(_env_conds, sub_path)\n dest_folder = os.path.join(_env_conds, 'final', sub_path)\n\n # if the results have already been processed, then load them up\n if os.path.isdir(dest_folder):\n comf_mtx = load_matrix(dest_folder)\n else: # otherwise, process them into a load-able format\n # make sure the requested metric is valid for the study\n if sub_path == 'mrt':\n source_folders = [os.path.join(_env_conds, 'longwave_mrt'),\n os.path.join(_env_conds, 'shortwave_mrt')]\n dest_folders = [os.path.join(_env_conds, 'final', 'longwave_mrt'),\n os.path.join(_env_conds, 'final', 'shortwave_mrt')]\n else:\n assert os.path.isdir(source_folder), \\\n 'Metric \"{}\" does not exist for this comfort study.'.format(sub_path)\n source_folders, dest_folders = [source_folder], [dest_folder]\n # restructure the results to align with the sensor grids\n dist_info = os.path.join(_env_conds, '_redist_info.json')\n for src_f, dst_f in zip(source_folders, dest_folders):\n if not os.path.isdir(dst_f):\n os.makedirs(dst_f)\n cmds = [folders.python_exe_path, '-m', 'honeybee_radiance', 'grid',\n 'merge-folder', src_f, dst_f, 'csv',\n '--dist-info', dist_info]\n shell = True if os.name == 'nt' else False\n custom_env = os.environ.copy()\n custom_env['PYTHONHOME'] = ''\n process = subprocess.Popen(\n cmds, stdout=subprocess.PIPE, shell=shell, env=custom_env)\n stdout = process.communicate()\n grid_info_src = os.path.join(_env_conds, 'grids_info.json')\n grid_info_dst = os.path.join(dst_f, 'grids_info.json')\n shutil.copyfile(grid_info_src, grid_info_dst)\n data_header = create_result_header(_env_conds, os.path.split(dst_f)[-1])\n result_info_path = os.path.join(dst_f, 'results_info.json')\n with open(result_info_path, 'w') as fp:\n json.dump(data_header.to_dict(), fp, indent=4)\n # if MRT was requested, sum together the longwave and shortwave\n if sub_path == 'mrt':\n sum_matrices(dest_folders[0], dest_folders[1], dest_folder)\n data_header = create_result_header(_env_conds, sub_path)\n result_info_path = os.path.join(dest_folder, 'results_info.json')\n with open(result_info_path, 'w') as fp:\n json.dump(data_header.to_dict(), fp, indent=4)\n # load the resulting matrix into {{Plugin}}\n comf_mtx = load_matrix(dest_folder)\n", + "code": "\nimport subprocess\nimport os\nimport shutil\nimport json\n\ntry:\n from ladybug.datatype.temperature import AirTemperature, \\\n MeanRadiantTemperature, RadiantTemperature\n from ladybug.datatype.temperaturedelta import RadiantTemperatureDelta\n from ladybug.datatype.fraction import RelativeHumidity\n from ladybug.header import Header\n from ladybug.datacollection import HourlyContinuousCollection, \\\n HourlyDiscontinuousCollection\n from ladybug.futil import csv_to_num_matrix\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\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 ladybug_{{cad}}.{{plugin}} import all_required_inputs, objectify_output\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\nENV_CONDS_MAP = {\n '0': 'mrt',\n 'mrt': 'mrt',\n 'mean radiant temperature': 'mrt',\n '1': 'air_temperature',\n 'air temperature': 'air_temperature',\n '2': 'longwave_mrt',\n 'longwave mrt': 'longwave_mrt',\n '3': 'shortwave_mrt',\n 'shortwave mrt': 'shortwave_mrt',\n 'shortwave mrt delta': 'shortwave_mrt',\n '4': 'rel_humidity',\n 'relative humidity': 'rel_humidity'\n}\n\n\ndef load_matrix(comf_result):\n \"\"\"Load a matrix of data into an object that can be output in {{Plugin}}.\n\n Args:\n comf_result: Path to a folder with CSV data to be loaded into {{Plugin}}.\n \"\"\"\n # parse the result_info.json into a data collection header\n with open(os.path.join(comf_result, 'results_info.json')) as json_file:\n data_header = Header.from_dict(json.load(json_file))\n a_per = data_header.analysis_period\n continuous = True if a_per.st_hour == 0 and a_per.end_hour == 23 else False\n if not continuous:\n dates = a_per.datetimes\n\n # parse the grids_info.json with the correct order of the grid files\n with open(os.path.join(comf_result, 'grids_info.json')) as json_file:\n grid_list = json.load(json_file)\n\n # loop through the grid CSV files, parse their results, and build data collections\n comf_matrix = []\n for grid in grid_list:\n grid_name = grid['full_id'] if 'full_id' in grid else 'id'\n metadata = {'grid': grid_name}\n grid_file = os.path.join(comf_result, '{}.csv'.format(grid_name))\n data_matrix = csv_to_num_matrix(grid_file)\n grid_data = []\n for i, row in enumerate(data_matrix):\n header = data_header.duplicate()\n header.metadata = metadata.copy()\n header.metadata['sensor_index'] = i\n data = HourlyContinuousCollection(header, row) if continuous else \\\n HourlyDiscontinuousCollection(header, row, dates)\n grid_data.append(data)\n comf_matrix.append(grid_data)\n\n # wrap the maptrix into an object so that it does not slow the {{Plugin}} UI\n comf_mtx = objectify_output(\n '{} Matrix'.format(data_header.data_type.name), comf_matrix)\n return comf_mtx\n\n\nif all_required_inputs(ghenv.Component) and _load:\n # get the folders and that correspond with the requested metric\n _metric_ = _metric_ if _metric_ is not None else 'mrt'\n try:\n sub_path = ENV_CONDS_MAP[_metric_.lower()]\n except KeyError:\n raise ValueError(\n 'Input metric \"{}\" is not recognized. Choose from: {}'.format(\n _metric_, '\\n'.join(ENV_CONDS_MAP.keys()))\n )\n source_folder = os.path.join(_env_conds, sub_path)\n dest_folder = os.path.join(_env_conds, 'final', sub_path)\n\n # if the results have already been processed, then load them up\n if os.path.isdir(dest_folder):\n comf_mtx = load_matrix(dest_folder)\n else: # otherwise, process them into a load-able format\n # make sure the requested metric is valid for the study\n if sub_path != 'mrt':\n assert os.path.isdir(source_folder), \\\n 'Metric \"{}\" does not exist for this comfort study.'.format(sub_path)\n cmds = [folders.python_exe_path, '-m', 'ladybug_comfort', 'map',\n 'restructure-env-conditions', _env_conds, dest_folder, sub_path]\n shell = True if os.name == 'nt' else False\n custom_env = os.environ.copy()\n custom_env['PYTHONHOME'] = ''\n process = subprocess.Popen(\n cmds, stdout=subprocess.PIPE, shell=shell, env=custom_env)\n stdout = process.communicate()\n # load the resulting matrix into {{Plugin}}\n comf_mtx = load_matrix(dest_folder)\n", "category": "HB-Energy", "name": "HB Read Environment Matrix", "description": "Read the detailed environmental conditions of a thermal mapping analysis from\nthe env_conds output by a thermal mapping component.\n_\nEnvironemntal conditions include raw inputs to the thermal comfort model, such as\nair temperature, MRT, longwave MRT, and shortwave MRT delta.\n-" diff --git a/honeybee_grasshopper_energy/json/HB_Read_Thermal_Matrix.json b/honeybee_grasshopper_energy/json/HB_Read_Thermal_Matrix.json index 0e2ff51..6d36f42 100644 --- a/honeybee_grasshopper_energy/json/HB_Read_Thermal_Matrix.json +++ b/honeybee_grasshopper_energy/json/HB_Read_Thermal_Matrix.json @@ -1,5 +1,5 @@ { - "version": "1.8.0", + "version": "1.8.1", "nickname": "ThermalMtx", "outputs": [ [ @@ -29,7 +29,7 @@ } ], "subcategory": "7 :: Thermal Map", - "code": "\nimport os\nimport json\n\ntry:\n from ladybug.header import Header\n from ladybug.datacollection import HourlyContinuousCollection, \\\n HourlyDiscontinuousCollection\n from ladybug.futil import csv_to_num_matrix\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, objectify_output\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 _load:\n # parse the result_info.json into a data collection header\n with open(os.path.join(_comf_result, 'results_info.json')) as json_file:\n data_header = Header.from_dict(json.load(json_file))\n a_per = data_header.analysis_period\n continuous = True if a_per.st_hour == 0 and a_per.end_hour == 23 else False\n if not continuous:\n dates = a_per.datetimes\n\n # parse the grids_info.json with the correct order of the grid files\n with open(os.path.join(_comf_result, 'grids_info.json')) as json_file:\n grid_list = json.load(json_file)\n\n # loop through the grid CSV files, parse their results, and build data collections\n comf_matrix = []\n for grid in grid_list:\n grid_name = grid['full_id'] if 'full_id' in grid else 'id'\n metadata = {'grid': grid_name}\n grid_file = os.path.join(_comf_result, '{}.csv'.format(grid_name))\n data_matrix = csv_to_num_matrix(grid_file)\n grid_data = []\n for i, row in enumerate(data_matrix):\n header = data_header.duplicate()\n header.metadata = metadata.copy()\n header.metadata['sensor_index'] = i\n data = HourlyContinuousCollection(header, row) if continuous else \\\n HourlyDiscontinuousCollection(header, row, dates)\n grid_data.append(data)\n comf_matrix.append(grid_data)\n\n # wrap the maptrix into an object so that it does not slow the {{Plugin}} UI\n comf_mtx = objectify_output(\n '{} Matrix'.format(data_header.data_type.name), comf_matrix)\n", + "code": "\nimport os\nimport json\nimport subprocess\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 ladybug.header import Header\n from ladybug.datacollection import HourlyContinuousCollection, \\\n HourlyDiscontinuousCollection\n from ladybug.futil import csv_to_num_matrix\n from ladybug.datautil import collections_from_csv\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, objectify_output\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 _load:\n # parse the result_info.json into a data collection header\n with open(os.path.join(_comf_result, 'results_info.json')) as json_file:\n data_header = Header.from_dict(json.load(json_file))\n a_per = data_header.analysis_period\n continuous = True if a_per.st_hour == 0 and a_per.end_hour == 23 else False\n if not continuous:\n dates = a_per.datetimes\n\n # parse the grids_info.json with the correct order of the grid files\n with open(os.path.join(_comf_result, 'grids_info.json')) as json_file:\n grid_list = json.load(json_file)\n\n # check file extension\n grid_file = os.path.join(_comf_result, '{}.csv'.format(grid_list[0]['full_id']))\n extension = 'csv'\n if not os.path.exists(grid_file):\n extension = 'npy'\n\n comf_matrix = []\n if extension == 'csv':\n # loop through the grid CSV files, parse their results, and build data collections\n for grid in grid_list:\n grid_name = grid['full_id'] if 'full_id' in grid else 'id'\n metadata = {'grid': grid_name}\n grid_file = os.path.join(_comf_result, '{}.csv'.format(grid_name))\n data_matrix = csv_to_num_matrix(grid_file)\n grid_data = []\n for i, row in enumerate(data_matrix):\n header = data_header.duplicate()\n header.metadata = metadata.copy()\n header.metadata['sensor_index'] = i\n data = HourlyContinuousCollection(header, row) if continuous else \\\n HourlyDiscontinuousCollection(header, row, dates)\n grid_data.append(data)\n comf_matrix.append(grid_data)\n else:\n csv_files = []\n csv_exists = []\n # collect csv files and check if they already exists\n for grid in grid_list:\n grid_name = grid['full_id'] if 'full_id' in grid else 'id'\n grid_file = os.path.join(_comf_result, 'datacollections', '{}.csv'.format(grid_name))\n csv_files.append(grid_file)\n csv_exists.append(os.path.exists(grid_file))\n # run command if csv files do not exist\n if not all(csv_exists):\n cmds = [folders.python_exe_path, '-m', 'honeybee_radiance_postprocess',\n 'data-collection', 'folder-to-datacollections', _comf_result,\n os.path.join(_comf_result, 'results_info.json')]\n use_shell = True if os.name == 'nt' else False\n custom_env = os.environ.copy()\n custom_env['PYTHONHOME'] = ''\n process = subprocess.Popen(\n cmds, cwd=_comf_result, shell=use_shell, env=custom_env,\n stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n stdout = process.communicate() # wait for the process to finish\n for grid_file in csv_files:\n grid_data = collections_from_csv(grid_file)\n comf_matrix.append(grid_data)\n\n # wrap the maptrix into an object so that it does not slow the {{Plugin}} UI\n comf_mtx = objectify_output(\n '{} Matrix'.format(data_header.data_type.name), comf_matrix)\n", "category": "HB-Energy", "name": "HB Read Thermal Matrix", "description": "Read the detailed results of a thermal mapping analysis from a folder of CSV\nfiles output by a thermal mapping component.\n_\nDetailed results include temperature amd thermal condition results. It also\nincludes metrics that give a sense of how hot or cold condition are like\npmv, utci category, or adaptive comfort degrees from neutral temperature.\n-" diff --git a/honeybee_grasshopper_energy/src/HB Read Environment Matrix.py b/honeybee_grasshopper_energy/src/HB Read Environment Matrix.py index f8c7728..603f395 100644 --- a/honeybee_grasshopper_energy/src/HB Read Environment Matrix.py +++ b/honeybee_grasshopper_energy/src/HB Read Environment Matrix.py @@ -43,7 +43,7 @@ ghenv.Component.Name = 'HB Read Environment Matrix' ghenv.Component.NickName = 'EnvMtx' -ghenv.Component.Message = '1.8.0' +ghenv.Component.Message = '1.8.1' ghenv.Component.Category = 'HB-Energy' ghenv.Component.SubCategory = '7 :: Thermal Map' ghenv.Component.AdditionalHelpFromDocStrings = '0' @@ -132,46 +132,6 @@ def load_matrix(comf_result): return comf_mtx -def create_result_header(env_conds, sub_path): - """Create a DataCollection Header for a given metric.""" - with open(os.path.join(env_conds, 'results_info.json')) as json_file: - base_head = Header.from_dict(json.load(json_file)) - if sub_path == 'mrt': - return Header(MeanRadiantTemperature(), 'C', base_head.analysis_period) - elif sub_path == 'air_temperature': - return Header(AirTemperature(), 'C', base_head.analysis_period) - elif sub_path == 'longwave_mrt': - return Header(RadiantTemperature(), 'C', base_head.analysis_period) - elif sub_path == 'shortwave_mrt': - return Header(RadiantTemperatureDelta(), 'dC', base_head.analysis_period) - elif sub_path == 'rel_humidity': - return Header(RelativeHumidity(), '%', base_head.analysis_period) - - -def sum_matrices(mtxs_1, mtxs_2, dest_dir): - """Sum together matrices of two folders.""" - if not os.path.isdir(dest_dir): - os.makedirs(dest_dir) - for mtx_file in os.listdir(mtxs_1): - if mtx_file.endswith('.csv'): - mtx_file1 = os.path.join(mtxs_1, mtx_file) - mtx_file2 = os.path.join(mtxs_2, mtx_file) - matrix_1 = csv_to_num_matrix(mtx_file1) - matrix_2 = csv_to_num_matrix(mtx_file2) - data = [[d1 + d2 for d1, d2 in zip(r1, r2)] - for r1, r2 in zip(matrix_1, matrix_2)] - csv_path = os.path.join(dest_dir, mtx_file) - with open(csv_path, 'w') as csv_file: - for dat in data: - str_data = (str(v) for v in dat) - csv_file.write(','.join(str_data) + '\n') - elif mtx_file == 'grids_info.json': - shutil.copyfile( - os.path.join(mtxs_1, mtx_file), - os.path.join(dest_dir, mtx_file) - ) - - if all_required_inputs(ghenv.Component) and _load: # get the folders and that correspond with the requested metric _metric_ = _metric_ if _metric_ is not None else 'mrt' @@ -190,42 +150,16 @@ def sum_matrices(mtxs_1, mtxs_2, dest_dir): comf_mtx = load_matrix(dest_folder) else: # otherwise, process them into a load-able format # make sure the requested metric is valid for the study - if sub_path == 'mrt': - source_folders = [os.path.join(_env_conds, 'longwave_mrt'), - os.path.join(_env_conds, 'shortwave_mrt')] - dest_folders = [os.path.join(_env_conds, 'final', 'longwave_mrt'), - os.path.join(_env_conds, 'final', 'shortwave_mrt')] - else: + if sub_path != 'mrt': assert os.path.isdir(source_folder), \ - 'Metric "{}" does not exist for this comfort study.'.format(sub_path) - source_folders, dest_folders = [source_folder], [dest_folder] - # restructure the results to align with the sensor grids - dist_info = os.path.join(_env_conds, '_redist_info.json') - for src_f, dst_f in zip(source_folders, dest_folders): - if not os.path.isdir(dst_f): - os.makedirs(dst_f) - cmds = [folders.python_exe_path, '-m', 'honeybee_radiance', 'grid', - 'merge-folder', src_f, dst_f, 'csv', - '--dist-info', dist_info] - shell = True if os.name == 'nt' else False - custom_env = os.environ.copy() - custom_env['PYTHONHOME'] = '' - process = subprocess.Popen( - cmds, stdout=subprocess.PIPE, shell=shell, env=custom_env) - stdout = process.communicate() - grid_info_src = os.path.join(_env_conds, 'grids_info.json') - grid_info_dst = os.path.join(dst_f, 'grids_info.json') - shutil.copyfile(grid_info_src, grid_info_dst) - data_header = create_result_header(_env_conds, os.path.split(dst_f)[-1]) - result_info_path = os.path.join(dst_f, 'results_info.json') - with open(result_info_path, 'w') as fp: - json.dump(data_header.to_dict(), fp, indent=4) - # if MRT was requested, sum together the longwave and shortwave - if sub_path == 'mrt': - sum_matrices(dest_folders[0], dest_folders[1], dest_folder) - data_header = create_result_header(_env_conds, sub_path) - result_info_path = os.path.join(dest_folder, 'results_info.json') - with open(result_info_path, 'w') as fp: - json.dump(data_header.to_dict(), fp, indent=4) + 'Metric "{}" does not exist for this comfort study.'.format(sub_path) + cmds = [folders.python_exe_path, '-m', 'ladybug_comfort', 'map', + 'restructure-env-conditions', _env_conds, dest_folder, sub_path] + shell = True if os.name == 'nt' else False + custom_env = os.environ.copy() + custom_env['PYTHONHOME'] = '' + process = subprocess.Popen( + cmds, stdout=subprocess.PIPE, shell=shell, env=custom_env) + stdout = process.communicate() # load the resulting matrix into Grasshopper comf_mtx = load_matrix(dest_folder) diff --git a/honeybee_grasshopper_energy/src/HB Read Thermal Matrix.py b/honeybee_grasshopper_energy/src/HB Read Thermal Matrix.py index 59fd241..cc98069 100644 --- a/honeybee_grasshopper_energy/src/HB Read Thermal Matrix.py +++ b/honeybee_grasshopper_energy/src/HB Read Thermal Matrix.py @@ -37,19 +37,26 @@ ghenv.Component.Name = 'HB Read Thermal Matrix' ghenv.Component.NickName = 'ThermalMtx' -ghenv.Component.Message = '1.8.0' +ghenv.Component.Message = '1.8.1' ghenv.Component.Category = 'HB-Energy' ghenv.Component.SubCategory = '7 :: Thermal Map' ghenv.Component.AdditionalHelpFromDocStrings = '2' import os import json +import subprocess + +try: + from honeybee.config import folders +except ImportError as e: + raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) try: from ladybug.header import Header from ladybug.datacollection import HourlyContinuousCollection, \ HourlyDiscontinuousCollection from ladybug.futil import csv_to_num_matrix + from ladybug.datautil import collections_from_csv except ImportError as e: raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e)) @@ -72,22 +79,53 @@ with open(os.path.join(_comf_result, 'grids_info.json')) as json_file: grid_list = json.load(json_file) - # loop through the grid CSV files, parse their results, and build data collections + # check file extension + grid_file = os.path.join(_comf_result, '{}.csv'.format(grid_list[0]['full_id'])) + extension = 'csv' + if not os.path.exists(grid_file): + extension = 'npy' + comf_matrix = [] - for grid in grid_list: - grid_name = grid['full_id'] if 'full_id' in grid else 'id' - metadata = {'grid': grid_name} - grid_file = os.path.join(_comf_result, '{}.csv'.format(grid_name)) - data_matrix = csv_to_num_matrix(grid_file) - grid_data = [] - for i, row in enumerate(data_matrix): - header = data_header.duplicate() - header.metadata = metadata.copy() - header.metadata['sensor_index'] = i - data = HourlyContinuousCollection(header, row) if continuous else \ - HourlyDiscontinuousCollection(header, row, dates) - grid_data.append(data) - comf_matrix.append(grid_data) + if extension == 'csv': + # loop through the grid CSV files, parse their results, and build data collections + for grid in grid_list: + grid_name = grid['full_id'] if 'full_id' in grid else 'id' + metadata = {'grid': grid_name} + grid_file = os.path.join(_comf_result, '{}.csv'.format(grid_name)) + data_matrix = csv_to_num_matrix(grid_file) + grid_data = [] + for i, row in enumerate(data_matrix): + header = data_header.duplicate() + header.metadata = metadata.copy() + header.metadata['sensor_index'] = i + data = HourlyContinuousCollection(header, row) if continuous else \ + HourlyDiscontinuousCollection(header, row, dates) + grid_data.append(data) + comf_matrix.append(grid_data) + else: + csv_files = [] + csv_exists = [] + # collect csv files and check if they already exists + for grid in grid_list: + grid_name = grid['full_id'] if 'full_id' in grid else 'id' + grid_file = os.path.join(_comf_result, 'datacollections', '{}.csv'.format(grid_name)) + csv_files.append(grid_file) + csv_exists.append(os.path.exists(grid_file)) + # run command if csv files do not exist + if not all(csv_exists): + cmds = [folders.python_exe_path, '-m', 'honeybee_radiance_postprocess', + 'data-collection', 'folder-to-datacollections', _comf_result, + os.path.join(_comf_result, 'results_info.json')] + use_shell = True if os.name == 'nt' else False + custom_env = os.environ.copy() + custom_env['PYTHONHOME'] = '' + process = subprocess.Popen( + cmds, cwd=_comf_result, shell=use_shell, env=custom_env, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout = process.communicate() # wait for the process to finish + for grid_file in csv_files: + grid_data = collections_from_csv(grid_file) + comf_matrix.append(grid_data) # wrap the maptrix into an object so that it does not slow the Grasshopper UI comf_mtx = objectify_output( diff --git a/honeybee_grasshopper_energy/user_objects/HB Read Environment Matrix.ghuser b/honeybee_grasshopper_energy/user_objects/HB Read Environment Matrix.ghuser index fdabb91..89b182c 100644 Binary files a/honeybee_grasshopper_energy/user_objects/HB Read Environment Matrix.ghuser and b/honeybee_grasshopper_energy/user_objects/HB Read Environment Matrix.ghuser differ diff --git a/honeybee_grasshopper_energy/user_objects/HB Read Thermal Matrix.ghuser b/honeybee_grasshopper_energy/user_objects/HB Read Thermal Matrix.ghuser index c227006..d1f9745 100644 Binary files a/honeybee_grasshopper_energy/user_objects/HB Read Thermal Matrix.ghuser and b/honeybee_grasshopper_energy/user_objects/HB Read Thermal Matrix.ghuser differ