def all_data_load_balance(rooms, data): """Get a LoadBalance object from a list of all relavant data collections.""" return LoadBalance(rooms, lighting_data=data[0], electric_equip_data=data[1], gas_equip_data=c_data[2], service_hot_water_data=data[3], people_data=data[4], solar_data=data[5], infiltration_data=data[6], surface_flow_data=data[7], use_all_solar=True)
def test_load_balance(): """Test the initialization of LoadBalance from an sql file.""" model_json = './tests/result/triangulated/TriangleModel.json' with open(model_json, 'r') as fp: model_data = json.load(fp) model = Model.from_dict(model_data) sql_path = './tests/result/triangulated/eplusout.sql' load_bal_obj = LoadBalance.from_sql_file(model, sql_path) load_colls = load_bal_obj.load_balance_terms() load_colls_storage = load_bal_obj.load_balance_terms(include_storage=True) assert len(load_colls) == 10 assert len(load_colls_storage) == 11 load_colls_norm_storage = load_bal_obj.load_balance_terms(True, True) assert len(load_colls_norm_storage) == 11
def load_balance(model_json, result_sql, normalize, storage, output_file): """Get an array of DataCollection JSONs for a complete model's load balance. \b Args: model_json: Full path to a Model JSON file used for simulation. result_sql: Full path to an SQLite file that was generated by EnergyPlus. """ try: # serialize the objects to Python with open(model_json) as json_file: data = json.load(json_file) model = Model.from_dict(data) # create the load balance object and output data to a JSON bal_obj = LoadBalance.from_sql_file(model, result_sql) balance = bal_obj.load_balance_terms(normalize, storage) output_file.write(json.dumps([data.to_dict() for data in balance])) except Exception as e: _logger.exception('Failed to construct load balance.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
process1 = data_to_load_intensity(process1_init, floor_area, 'Process', 1, mults) process2 = data_to_load_intensity(process2_init, floor_area, 'Process', 1, mults) process = process1 + process2 total_load.append(process.total) # add hot water if it is there hot_water = [] if len(shw_init) != 0: hot_water = data_to_load_intensity(shw_init, floor_area, 'Service Hot Water', 1, mults) total_load.append(hot_water.total) # construct the load balance if requested if run_bal_: if os.name == 'nt': # we are on windows; use IronPython like usual bal_obj = LoadBalance.from_sql_file(_model, sql) balance = bal_obj.load_balance_terms(True, True) else: # we are on Mac; sqlite3 module doesn't work in Mac IronPython # Execute the honybee CLI to obtain the results via CPython model_json = os.path.join(directory, 'in.hbjson') with open(model_json, 'w') as fp: json.dump(_model.to_dict(), fp) cmds = [ folders.python_exe_path, '-m', 'honeybee_energy', 'result', 'load-balance', model_json, sql ] process = subprocess.Popen(cmds, stdout=subprocess.PIPE) stdout = process.communicate() balance = serialize_data(json.loads(stdout[0]))
data_coll_dicts = json.loads(stdout[0]) light = serialize_data(data_coll_dicts[0]) ele_equip = serialize_data(data_coll_dicts[1]) gas_equip = serialize_data(data_coll_dicts[2]) hot_water = serialize_data(data_coll_dicts[3]) people = serialize_data(data_coll_dicts[4]) solar = serialize_data(data_coll_dicts[5]) infil_gain = serialize_data(data_coll_dicts[6]) infil_loss = serialize_data(data_coll_dicts[7]) opaque_flow = serialize_data(data_coll_dicts[8]) window_loss = serialize_data(data_coll_dicts[9]) window_gain = serialize_data(data_coll_dicts[10]) for dat in opaque_flow + window_loss + window_gain: dat.header.metadata['Surface'] = dat.header.metadata['Zone'] infil = LoadBalance.subtract_loss_from_gain(infil_gain, infil_loss) window_flow = [] window_flow = LoadBalance.subtract_loss_from_gain( window_gain, window_loss) face_flow = opaque_flow + window_flow all_data = [ light, ele_equip, gas_equip, hot_water, people, solar, infil, face_flow ] # construct the cooling design day balance c_data = filter_data_by_date(c_dt, all_data) load_bal = all_data_load_balance(_rooms, c_data) cool_bal = reorder_balance(load_bal.load_balance_terms(), term_order) # construct the heating design day balance
hot_water_ = check_input(hot_water_) people_gain_ = check_input(people_gain_) solar_gain_ = check_input(solar_gain_) infiltration_load_ = check_input(infiltration_load_) mech_vent_load_ = check_input(mech_vent_load_) nat_vent_load_ = check_input(nat_vent_load_) face_energy_flow_ = check_input(face_energy_flow_) # construct the load balance object and output the results load_bal_obj = LoadBalance(rooms, cooling_, heating_, lighting_, electric_equip_, gas_equip_, hot_water_, people_gain_, solar_gain_, infiltration_load_, mech_vent_load_, nat_vent_load_, face_energy_flow_, units_system(), use_all_solar=is_model) balance = load_bal_obj.load_balance_terms(False, False) if len(balance) != 0: balance_storage = balance + [load_bal_obj.storage] norm_bal = load_bal_obj.load_balance_terms(True, False) norm_bal_storage = load_bal_obj.load_balance_terms(True, True)