def test_monthlychart_daily_stack(): """Test the initialization of MonthlyChart with daily stacked data collections.""" header = Header(Energy(), 'kWh', AnalysisPeriod()) values = [i / 31 for i in range(365)] date_t = list(range(1, 366)) data_coll = DailyCollection(header, values, date_t) month_chart = MonthlyChart([data_coll]) meshes = month_chart.data_meshes assert len(meshes) == 1 assert isinstance(meshes[0], Mesh2D) assert len(meshes[0].faces) == 365 assert month_chart.data_polylines is None header2 = Header(Energy(), 'kWh', AnalysisPeriod()) values2 = [i / 31 for i in range(365)] data_coll2 = DailyCollection(header2, values2, date_t) month_chart = MonthlyChart([data_coll, data_coll2]) meshes = month_chart.data_meshes assert len(meshes) == 2 assert isinstance(meshes[1], Mesh2D) assert len(meshes[1].faces) == 365 month_chart = MonthlyChart([data_coll, data_coll2], stack=True) meshes = month_chart.data_meshes assert len(meshes) == 2 assert isinstance(meshes[1], Mesh2D) assert len(meshes[1].faces) == 365
def test_monthlychart_monthly_per_hour_stack(): """Test the initialization of MonthlyChart with monthly-per-hour stacked collections.""" header = Header(Energy(), 'kWh', AnalysisPeriod()) values = list(range(20, 12 * 24 + 20)) date_t = AnalysisPeriod().months_per_hour data_coll = MonthlyPerHourCollection(header, values, date_t) month_chart = MonthlyChart([data_coll]) assert month_chart.data_meshes is None plines = month_chart.data_polylines assert isinstance(plines[0], Polyline2D) assert len(plines) == 12 assert month_chart.y_axis_labels1[0] == '0.00' header2 = Header(Energy(), 'kWh', AnalysisPeriod()) values2 = [x / 10 for x in range(12 * 24)] data_coll2 = MonthlyPerHourCollection(header2, values2, date_t) month_chart = MonthlyChart([data_coll, data_coll2]) plines = month_chart.data_polylines assert isinstance(plines[0], Polyline2D) assert len(plines) == 12 * 2 month_chart = MonthlyChart([data_coll, data_coll2], stack=True) plines = month_chart.data_polylines assert isinstance(plines[0], Polyline2D) assert len(plines) == 12 * 2
def test_monthlychart_monthly_stack(): """Test the initialization of MonthlyChart with monthly stacked data collections.""" header = Header(Energy(), 'kWh', AnalysisPeriod()) values = [i for i in range(12, 24)] date_t = list(range(1, 13)) data_coll = MonthlyCollection(header, values, date_t) month_chart = MonthlyChart([data_coll]) meshes = month_chart.data_meshes assert len(meshes) == 1 assert isinstance(meshes[0], Mesh2D) assert len(meshes[0].faces) == 12 assert month_chart.y_axis_labels1[0] == '0.00' header2 = Header(Energy(), 'kWh', AnalysisPeriod()) values2 = [i for i in range(24, 36)] data_coll2 = MonthlyCollection(header2, values2, date_t) month_chart = MonthlyChart([data_coll, data_coll2]) meshes = month_chart.data_meshes assert len(meshes) == 2 assert isinstance(meshes[1], Mesh2D) assert len(meshes[1].faces) == 12 month_chart = MonthlyChart([data_coll, data_coll2], stack=True) meshes = month_chart.data_meshes assert len(meshes) == 2 assert isinstance(meshes[1], Mesh2D) assert len(meshes[1].faces) == 12
def test_monthlychart_hourly_stack(): """Test the initialization of MonthlyChart with hourly stacked data collections.""" header = Header(Energy(), 'kWh', AnalysisPeriod()) values = [i / 365 for i in range(20, 8780)] data_coll = HourlyContinuousCollection(header, values) month_chart = MonthlyChart([data_coll]) meshes = month_chart.data_meshes assert len(meshes) == 1 assert isinstance(meshes[0], Mesh2D) assert len(meshes[0].faces) == 24 * 12 assert month_chart.y_axis_labels1[0] == '0.00' header2 = Header(Energy(), 'kWh', AnalysisPeriod()) values2 = [i / 365 for i in range(8760, 0, -1)] data_coll2 = HourlyContinuousCollection(header2, values2) month_chart = MonthlyChart([data_coll, data_coll2]) meshes = month_chart.data_meshes assert len(meshes) == 2 assert isinstance(meshes[1], Mesh2D) assert len(meshes[1].faces) == 24 * 12 month_chart = MonthlyChart([data_coll, data_coll2], stack=True) meshes = month_chart.data_meshes assert len(meshes) == 2 assert isinstance(meshes[1], Mesh2D) assert len(meshes[1].faces) == 24 * 12 plines = month_chart.data_polylines assert isinstance(plines[0], Polyline2D) assert len(plines) == 2 * 12 * 2
] cmds.extend(sql_files) process = subprocess.Popen(cmds, stdout=subprocess.PIPE) stdout = process.communicate() results = json.loads(stdout[0], object_pairs_hook=OrderedDict) return results['eui'], results['total_floor_area'], results['end_uses'] if all_required_inputs(ghenv.Component): # ensure that _sql is a list rather than a single string if isinstance(_sql, basestring): _sql = [_sql] # get the results get_results = get_results_windows if os.name == 'nt' else get_results_mac eui, gross_floor, end_use_pairs = get_results(_sql) # create separate lists for end use values and labels eui_end_use = end_use_pairs.values() end_uses = [use.replace('_', ' ').title() for use in end_use_pairs.keys()] # convert data to IP if requested if ip_: eui_typ, a_typ, e_typ = EnergyIntensity(), Area(), Energy() eui = round(eui_typ.to_ip([eui], 'kWh/m2')[0][0], 3) gross_floor = round(a_typ.to_ip([gross_floor], 'm2')[0][0], 3) eui_end_use = [ round(eui_typ.to_ip([val], 'kWh/m2')[0][0], 3) for val in eui_end_use ]
def energy_use_intensity(result_paths, si, output_file): """Get information about energy use intensity and an EUI breakdown by end use. \b Args: result_paths: Path to one or more SQLite files that were generated by EnergyPlus or folders containing such files. Folders can be from a single EnergyPlus simulation or may contain multiple SQLite files. EUI will be computed across all files provided. """ try: # set initial values that will be computed based on results total_floor_area, conditioned_floor_area, total_energy = 0, 0, 0 all_uses = \ ('heating', 'cooling', 'interior_lighting', 'exterior_lighting', 'interior_equipment', 'exterior_equipment', 'fans', 'pumps', 'heat_rejection', 'humidification', 'heat_recovery', 'water_systems', 'refrigeration', 'generators') end_uses = {} for use in all_uses: end_uses[use] = 0 # create a list of sql file path that were either passed directly or are # contained within passed folders sql_paths = [] for file_or_folder_path in result_paths: if os.path.isdir(file_or_folder_path): for file_path in os.listdir(file_or_folder_path): if file_path.endswith('.sql'): sql_paths.append(os.path.join(file_or_folder_path, file_path)) elif file_or_folder_path.endswith('.sql'): sql_paths.append(file_or_folder_path) # loop through the sql files and add the energy use for sql_path in sql_paths: # parse the SQL file sql_obj = SQLiteResult(sql_path) # get the total floor area of the model area_dict = sql_obj.tabular_data_by_name('Building Area') areas = tuple(area_dict.values()) total_floor_area += areas[0][0] conditioned_floor_area += areas[1][0] # get the energy use eui_dict = sql_obj.tabular_data_by_name('End Uses') euis = tuple(eui_dict.values()) total_energy += sum([val for val in euis[-2][:12]]) end_uses['heating'] += sum([val for val in euis[0][:12]]) end_uses['cooling'] += sum([val for val in euis[1][:12]]) end_uses['interior_lighting'] += sum([val for val in euis[2][:12]]) end_uses['exterior_lighting'] += sum([val for val in euis[3][:12]]) end_uses['interior_equipment'] += sum([val for val in euis[4][:12]]) end_uses['exterior_equipment'] += sum([val for val in euis[5][:12]]) end_uses['fans'] += sum([val for val in euis[6][:12]]) end_uses['pumps'] += sum([val for val in euis[7][:12]]) end_uses['heat_rejection'] += sum([val for val in euis[8][:12]]) end_uses['humidification'] += sum([val for val in euis[9][:12]]) end_uses['heat_recovery'] += sum([val for val in euis[10][:12]]) end_uses['water_systems'] += sum([val for val in euis[11][:12]]) end_uses['refrigeration'] += sum([val for val in euis[12][:12]]) end_uses['generators'] += sum([val for val in euis[13][:12]]) # assemble all of the results into a final dictionary result_dict = { 'eui': round(total_energy / total_floor_area, 3), 'total_floor_area': total_floor_area, 'conditioned_floor_area': conditioned_floor_area, 'total_energy': round(total_energy, 3) } result_dict['end_uses'] = {key: round(val / total_floor_area, 3) for key, val in end_uses.items() if val != 0} # convert data to IP if requested if not si: eui_typ, a_typ, e_typ = EnergyIntensity(), Area(), Energy() result_dict['eui'] = \ round(eui_typ.to_ip([result_dict['eui']], 'kWh/m2')[0][0], 3) result_dict['total_floor_area'] = \ round(a_typ.to_ip([result_dict['total_floor_area']], 'm2')[0][0], 3) result_dict['conditioned_floor_area'] = \ round(a_typ.to_ip( [result_dict['conditioned_floor_area']], 'm2')[0][0], 3) result_dict['total_energy'] = \ round(e_typ.to_ip([result_dict['total_energy']], 'kWh')[0][0], 3) result_dict['end_uses'] = \ {key: round(eui_typ.to_ip([val], 'kWh/m2')[0][0], 3) for key, val in result_dict['end_uses'].items()} # write everthing into the output file output_file.write(json.dumps(result_dict, indent=4)) except Exception as e: _logger.exception('Failed to compute EUI from sql files.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)