def urban_district(directory): com_poly_file = './scripts/geometry/urban_commercial_geo.json' res_poly_file = './scripts/geometry/urban_residential_geo.json' with open(com_poly_file, 'r') as fp: com_geo_dict = json.load(fp) with open(res_poly_file, 'r') as fp: res_geo_dict = json.load(fp) # get all of the programs and construction sets c_set = constr_set_lib.construction_set_by_identifier('2013::ClimateZone5::SteelFramed') office = prog_type_lib.program_type_by_identifier('2013::MediumOffice::ClosedOffice') apartment = prog_type_lib.program_type_by_identifier('2013::MidriseApartment::Apartment') retail = prog_type_lib.program_type_by_identifier('2013::Retail::Retail') # create the Room2Ds rooms = [] for bldg in com_geo_dict: for i, floor in enumerate(bldg): room_geo = Face3D.from_dict(floor) if i < 3: hgt = 5 if i == 0 else 4 else: hgt = 3 program = retail if i == 0 else office room = Room2D('Commercial_{}'.format(i), room_geo, hgt) room.properties.energy.program_type = program room.properties.energy.construction_set = c_set room.properties.energy.add_default_ideal_air() ratio = 0.8 if i == 0 else 0.4 room.set_outdoor_window_parameters(SimpleWindowRatio(ratio)) if i == 0: room.is_ground_contact = True rooms.append(room) for bldg in res_geo_dict: for i, floor in enumerate(bldg): room_geo = Face3D.from_dict(floor) room = Room2D('Residential_{}'.format(i), room_geo, 4) room.properties.energy.program_type = apartment room.properties.energy.construction_set = c_set room.properties.energy.add_default_ideal_air() room.set_outdoor_window_parameters(SimpleWindowRatio(0.35)) if i == 0: room.is_ground_contact = True rooms.append(room) # create honeybee Rooms hb_rooms = [room.to_honeybee()[0] for room in rooms] model = Model('Mass_Pike_District', rooms=hb_rooms, units='Meters', tolerance=0.01, angle_tolerance=1.0) # write the model to a JSON dest_file = os.path.join(directory, 'urban_district.hbjson') with open(dest_file, 'w') as fp: json.dump(model.to_dict(), fp, indent=4)
def single_family_home(directory): poly_file = './scripts/geometry/single_family_geo.json' with open(poly_file, 'r') as fp: geo_dict = json.load(fp) # create the basic Room objects program = prog_type_lib.program_type_by_identifier('2013::MidriseApartment::Apartment') c_set = constr_set_lib.construction_set_by_identifier('2013::ClimateZone5::SteelFramed') rooms = [] for i, room_geo_dict in enumerate(geo_dict['rooms']): room_geo = Polyface3D.from_dict(room_geo_dict) room_geo.merge_overlapping_edges(0.01, math.radians(1)) room = Room.from_polyface3d('House_Room_{}'.format(i), room_geo) room.properties.energy.program_type = program room.properties.energy.construction_set = c_set room.properties.energy.add_default_ideal_air() rooms.append(room) # make some of the rooms different to make it interesting program2 = prog_type_lib.program_type_by_identifier('2013::MidriseApartment::Corridor') rooms[6].properties.energy.program_type = program2 cook_vals = [0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0] cook_meals = ScheduleRuleset.from_daily_values('Cooking_Meals', cook_vals) kitchen_equip = GasEquipment('Kitchen Stove', 20, cook_meals) rooms[0].properties.energy.gas_equipment = kitchen_equip # add the apertures to the rooms apertures = [] for i, ap_geo in enumerate(geo_dict['apertures']): ap_face = Face3D.from_dict(ap_geo) hb_ap = Aperture('House_Aperture_{}'.format(i), ap_face) hb_ap.extruded_border(0.3) apertures.append(hb_ap) # assign apertures and solve adjacency for room in rooms: for face in room.faces: for sf in apertures: if face.geometry.is_sub_face(sf.geometry, 0.5, 1.0): face.add_aperture(sf) Room.solve_adjacency(rooms, 0.01) # load up the context shades shades = [] for i, shd_geo in enumerate(geo_dict['shades']): shd_face = Face3D.from_dict(shd_geo) shades.append(Shade('Context_Shade_{}'.format(i), shd_face)) # put it all together in a Model and write out the JSON model = Model('Single_Family_Home', rooms=rooms, orphaned_shades=shades, units='Meters', tolerance=0.01, angle_tolerance=1.0) dest_file = os.path.join(directory, 'single_family_home.hbjson') with open(dest_file, 'w') as fp: json.dump(model.to_dict(), fp, indent=4)
def test_program_type_lib(): """Test that the honeybee-energy lib has been extended with new program type data.""" assert len(prog_type_lib.PROGRAM_TYPES ) > 2 # should now have many more constructions prog_from_lib = prog_type_lib.program_type_by_identifier( prog_type_lib.PROGRAM_TYPES[0]) assert isinstance(prog_from_lib, ProgramType) prog_from_lib = prog_type_lib.program_type_by_identifier( prog_type_lib.PROGRAM_TYPES[2]) assert isinstance(prog_from_lib, ProgramType)
def processItem(): progTypes = [] progIdentifiers = list(prog_type_lib.PROGRAM_TYPES) for progIdentifier in progIdentifiers: progTypes.append( prog_type_lib.program_type_by_identifier(progIdentifier)) return [progTypes, progIdentifiers]
def lab_building(directory): poly_file = './scripts/geometry/lab_building_geo.json' with open(poly_file, 'r') as fp: geo_dict = json.load(fp) # get all of the programs and construction sets c_set = constr_set_lib.construction_set_by_identifier('2013::ClimateZone5::SteelFramed') office = prog_type_lib.program_type_by_identifier('2013::MediumOffice::ClosedOffice') writeup = prog_type_lib.program_type_by_identifier('2013::Laboratory::Office') lab_support = prog_type_lib.program_type_by_identifier('2013::Laboratory::Lab with fume hood') laboratory = prog_type_lib.program_type_by_identifier('2013::Laboratory::Open lab') conference = prog_type_lib.program_type_by_identifier('2013::MediumOffice::Conference') classroom = prog_type_lib.program_type_by_identifier('2013::MediumOffice::Classroom') corridor = prog_type_lib.program_type_by_identifier('2013::MediumOffice::Corridor') storage = prog_type_lib.program_type_by_identifier('2013::MediumOffice::Storage') progs = [office, writeup, lab_support, laboratory, conference, classroom, corridor, storage] prog_keys = ['office', 'writeup', 'lab_support', 'laboratory', 'conference', 'classroom', 'corridor', 'storage'] # create the basic Room objects rooms = [] for prog_key, program in zip(prog_keys, progs): for i, room_geo_dict in enumerate(geo_dict[prog_key]): room_geo = Face3D.from_dict(room_geo_dict) room = Room2D('{}_{}'.format(prog_key, i), room_geo, 3.5) room.properties.energy.program_type = program room.properties.energy.construction_set = c_set room.properties.energy.add_default_ideal_air() rooms.append(room) # solve adjacency and set windows + shades story = Story('Lab_Floor_1', rooms, 4) story.remove_room_2d_colinear_vertices(0.01) story.intersect_room_2d_adjacency(0.01) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(RepeatingWindowRatio(0.35, 2.8, 0.8, 3)) story.set_ground_contact(True) story.set_top_exposed(True) bldg = Building('Lab_Building', [story]) # create the honeybee model model = bldg.to_honeybee(tolerance=0.01) model.units = 'Meters' model.tolerance = 0.01 model.angle_tolerance = 1.0 # generate louvers for all of the apertures for ap in model.apertures: ap.louvers_by_count(1, 0.5, 0.0, 0.0, Vector2D(1, 0)) # write the model to a JSON dest_file = os.path.join(directory, 'lab_building.hbjson') with open(dest_file, 'w') as fp: json.dump(model.to_dict(), fp, indent=4)
def lighting_2004(model_json, output_file): """Convert a Model's lighting to be conformant with ASHRAE 90.1-2004 appendix G. This includes determining whether an ASHRAE 2004 equivalent exists for each program type in the model. If none is found, the baseline_watts_per_area on the room's program's lighting will be used, which will default to a typical office if none has been specified. \b Args: model_json: Full path to a Model JSON file. """ try: # re-serialize the Model to Python and get the glazing ratios with open(model_json) as json_file: data = json.load(json_file) model = Model.from_dict(data) # loop through the rooms and try to find equivalent programs in 2004 for room in model.rooms: if room.properties.energy.lighting is None: continue prog_name = room.properties.energy.program_type.identifier.split( '::') prog_2004 = None if len(prog_name) == 3: new_prog_name = '2004::{}::{}'.format(prog_name[1], prog_name[2]) try: prog_2004 = program_type_by_identifier(new_prog_name) except ValueError: # no equivalent program in ASHRAE 2004 pass if prog_2004 is not None: # if program was found, use it to assign the LPD if prog_2004.lighting is not None: dup_light = room.properties.energy.lighting.duplicate() dup_light.watts_per_area = prog_2004.lighting.watts_per_area elif room.properties.energy.program_type.lighting is not None: dup_light = room.properties.energy.program_type.lighting.duplicate( ) dup_light.watts_per_area = dup_light.baseline_watts_per_area else: dup_light = room.properties.energy.lighting.duplicate() dup_light.watts_per_area = dup_light.baseline_watts_per_area dup_light.identifier = '{}_Lighting'.format(room.identifier) room.properties.energy.lighting = dup_light # write the Model JSON string output_file.write(json.dumps(model.to_dict())) except Exception as e: _logger.exception( 'Model baseline geometry creation failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def test_building_mix(): """Test that the building_mix ratios.""" bld_mix_file = './honeybee_energy_standards/building_mix.json' with open(bld_mix_file) as inf: bld_mix_dict = json.load(inf) for building in bld_mix_dict.values(): for program in building: prog_from_lib = prog_type_lib.program_type_by_identifier(program) assert isinstance(prog_from_lib, ProgramType) total_fracts = sum(f for f in building.values()) assert total_fracts == pytest.approx(1, rel=1e-3)
def program_type_abridged_patient_room(directory): pat_room_program = program_type_by_identifier( '2013::Hospital::ICU_PatRm').duplicate() pat_room_program.setpoint.identifier = 'Humidity Controlled PatRm Setpt' pat_room_program.setpoint.heating_setpoint = 21 pat_room_program.setpoint.cooling_setpoint = 24 pat_room_program.setpoint.humidifying_setpoint = 30 pat_room_program.setpoint.dehumidifying_setpoint = 55 dest_file = os.path.join(directory, 'program_type_abridged_patient_room.json') with open(dest_file, 'w') as fp: json.dump(pat_room_program.to_dict(abridged=True), fp, indent=4)
def program_type_by_id(program_type_id, abridged, output_file): """Get a program type definition from the standards lib with its identifier. \n Args: program_type_id: The identifier of a program type in the library. """ try: output_file.write(json.dumps(program_type_by_identifier( program_type_id).to_dict(abridged=abridged))) except Exception as e: _logger.exception('Retrieval from program type library failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def program_types_by_id(program_type_ids, abridged, output_file): """Get several program type definitions from the standards lib at once. \n Args: program_type_ids: A list of program type identifiers to be retrieved from the library. """ try: prgs = [] for prg_id in program_type_ids: prgs.append(program_type_by_identifier(prg_id)) output_file.write(json.dumps([prg.to_dict(abridged=abridged) for prg in prgs])) except Exception as e: _logger.exception('Retrieval from program type library failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def test_model_to_dict_with_program_type(): """Test Model.to_dict() with standards ProgramTypes.""" pat_room_program = prog_type_lib.program_type_by_identifier( '2013::Hospital::ICU_PatRm') room = Room.from_box('Hospital_Patient_Room', 5, 10, 3) room.properties.energy.program_type = pat_room_program room.properties.energy.add_default_ideal_air() ideal_air = room.properties.energy.hvac.duplicate() ideal_air.economizer_type = 'DifferentialEnthalpy' ideal_air.sensible_heat_recovery = 0.81 ideal_air.latent_heat_recovery = 0.68 room.properties.energy.hvac = ideal_air pat_rm_setpoint = room.properties.energy.setpoint.duplicate() pat_rm_setpoint.identifier = 'Humidity Controlled PatRm Setpt' pat_rm_setpoint.heating_setpoint = 21 pat_rm_setpoint.cooling_setpoint = 24 pat_rm_setpoint.humidifying_setpoint = 30 pat_rm_setpoint.dehumidifying_setpoint = 55 room.properties.energy.setpoint = pat_rm_setpoint south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.move_shades(Vector3D(0, 0, -0.5)) room[0].boundary_condition = boundary_conditions.adiabatic room[1].boundary_condition = boundary_conditions.adiabatic room[2].boundary_condition = boundary_conditions.adiabatic room[4].boundary_condition = boundary_conditions.adiabatic room[5].boundary_condition = boundary_conditions.adiabatic model = Model('Patient_Room_Test_Box', [room]) model_dict = model.to_dict() assert model_dict['properties']['energy']['program_types'][0]['identifier'] == \ '2013::Hospital::ICU_PatRm' assert model_dict['rooms'][0]['properties']['energy']['program_type'] == \ '2013::Hospital::ICU_PatRm' assert 'setpoint' in model_dict['rooms'][0]['properties']['energy'] assert model_dict['rooms'][0]['properties']['energy']['setpoint']['identifier'] == \ 'Humidity Controlled PatRm Setpt' assert 'hvac' in model_dict['rooms'][0]['properties']['energy']
def model_complete_patient_room(directory): pat_room_program = \ prog_type_lib.program_type_by_identifier('2013::Hospital::ICU_PatRm') room = Room.from_box('Hospital_Patient_Room', 5, 10, 3) room.properties.energy.program_type = pat_room_program room.properties.energy.add_default_ideal_air() ideal_air = room.properties.energy.hvac.duplicate() ideal_air.economizer_type = 'DifferentialEnthalpy' ideal_air.sensible_heat_recovery = 0.81 ideal_air.latent_heat_recovery = 0.68 room.properties.energy.hvac = ideal_air pat_rm_setpoint = room.properties.energy.setpoint.duplicate() pat_rm_setpoint.identifier = 'Humidity Controlled PatRm Setpt' pat_rm_setpoint.heating_setpoint = 21 pat_rm_setpoint.cooling_setpoint = 24 pat_rm_setpoint.humidifying_setpoint = 30 pat_rm_setpoint.dehumidifying_setpoint = 55 room.properties.energy.setpoint = pat_rm_setpoint south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.move_shades(Vector3D(0, 0, -0.5)) room[0].boundary_condition = boundary_conditions.adiabatic room[1].boundary_condition = boundary_conditions.adiabatic room[2].boundary_condition = boundary_conditions.adiabatic room[4].boundary_condition = boundary_conditions.adiabatic room[5].boundary_condition = boundary_conditions.adiabatic model = Model('Patient_Room_Test_Box', [room]) dest_file = os.path.join(directory, 'model_complete_patient_room.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(), fp, indent=4)
ghenv.Component.NickName = 'DeconstrProgram' ghenv.Component.Message = '1.2.0' ghenv.Component.Category = 'HB-Energy' ghenv.Component.SubCategory = '3 :: Loads' ghenv.Component.AdditionalHelpFromDocStrings = "1" try: from honeybee_energy.lib.programtypes import program_type_by_identifier except ImportError as e: raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # get the program from the library if it is a identifier if isinstance(_program, str): _program = program_type_by_identifier(_program) # get the components of the program people = _program.people lighting = _program.lighting electric_equip = _program.electric_equipment gas_equip = _program.gas_equipment hot_water = _program.service_hot_water infiltration = _program.infiltration ventilation = _program.ventilation setpoint = _program.setpoint
pnnl_resi.set_load( 'mel', mel_) pnnl_resi.set_load( 'plugloads', plugLoads_) pnnl_resi.set_load( 'lighting', lighting_) # Apply new loads and schedules to each Honeybee Room # ------------------------------------------------------------------------------ HB_rooms_ = [] for hb_room in _HB_rooms: # Duplicate the initial Honeybee Room object #--------------------------------------------------------------------------- if isinstance(hb_room, (Room)): new_room = hb_room.duplicate() elif isinstance(hb_room, str): program = program_type_by_identifier(hb_room) new_room = program.duplicate() else: raise TypeError('Expected Honeybee Room or ProgramType. ' 'Got {}.'.format(type(hb_room))) # Create the Honeybee-Room Loads #--------------------------------------------------------------------------- PNNL_ElecEquip_Load_ = pnnl_resi.calc_elec_equip_load(hb_room.floor_area) PNNL_Lighting_Load_ = pnnl_resi.load('lighting') PNNL_Occup_Load_ = pnnl_resi.load('occupancy') # Create the Honeybee-Room schedules #--------------------------------------------------------------------------- sched_vals_occupancy = pnnl_resi.schedule('occupancy') sched_vals_lighting = pnnl_resi.schedule('lighting')
def test_program_type_by_identifier(): """Test that all of the program types in the library can be loaded by identifier.""" for prog in prog_type_lib.PROGRAM_TYPES: prog_from_lib = prog_type_lib.program_type_by_identifier(prog) assert isinstance(prog_from_lib, ProgramType)
def convert_to_hb_json(source_dir=None, dest_dir=None): """Convert OpenStudio standards JSON files into Honeybee JSON files. Args: source_dir: Directory to the cleaned OpenStudio Standards JSONs. Default will be the data folder in this package. dest_dir: Optional path to a destination directory. Default will be the data folder in this package. """ # set default directories if source_dir is None: master_dir = local_data_dir() source_dir = os.path.join(master_dir, '_standards_data') if dest_dir is None: master_dir = local_data_dir() dest_dir = os.path.join(master_dir, 'data') # get all of the destination folders constr_dir = os.path.join(dest_dir, 'constructions') constrset_dir = os.path.join(dest_dir, 'constructionsets') sched_dir = os.path.join(dest_dir, 'schedules') ptype_dir = os.path.join(dest_dir, 'programtypes') ptype_reg_dir = os.path.join(dest_dir, 'programtypes_registry') # translate the materials and constructions to honeybee_json extra_folder = os.path.join( os.path.split(os.path.dirname(__file__))[0], '_extra') honeybee_construction_json( source_dir, constr_dir, mat_lib.opaque_material_by_identifier, 'opaque_material.json', [os.path.join(extra_folder, 'ground_materials.json')]) honeybee_construction_json(source_dir, constr_dir, mat_lib.window_material_by_identifier, 'window_material.json') honeybee_construction_json( source_dir, constr_dir, constr_lib.opaque_construction_by_identifier, 'opaque_construction.json', [os.path.join(extra_folder, 'ground_constructions.json')]) honeybee_construction_json(source_dir, constr_dir, constr_lib.window_construction_by_identifier, 'window_construction.json') # translate the construction sets to honeybee_json src_constr_set_dir = os.path.join(source_dir, 'construction_set') for f in os.listdir(src_constr_set_dir): dest_file = os.path.join(constrset_dir, f) f_path = os.path.join(src_constr_set_dir, f) if os.path.isfile(f_path) and f_path.endswith('.json'): with open(f_path, 'r') as json_file: c_dict = json.load(json_file) hb_dict = {} for c_id in c_dict: base_dict = \ constrset_lib.construction_set_by_identifier(c_id).to_dict(abridged=True) del_keys = [] for key in base_dict: if base_dict[key] is None: del_keys.append(key) elif isinstance(base_dict[key], dict): sub_del_keys = [] for s_key in base_dict[key]: if base_dict[key][s_key] is None: sub_del_keys.append(s_key) for s_key in sub_del_keys: del base_dict[key][s_key] for key in del_keys: del base_dict[key] hb_dict[c_id] = base_dict with open(dest_file, 'w') as fp: json.dump(hb_dict, fp, indent=2) # translate schedules to honeybee json sched_json = os.path.join(source_dir, 'schedule.json') hb_sch_dict = {} with open(sched_json, 'r') as json_file: sch_dict = json.load(json_file) for sch_id in sch_dict: hb_sch_dict[sch_id] = sch_lib.schedule_by_identifier(sch_id).to_dict( abridged=True) # get a string representation and clean it further init_str = json.dumps(hb_sch_dict, indent=2) new_str = re.sub(r'\s*(\d*\.\d*),\s*', r'\1, ', init_str) right_bracket_str = re.sub(r'\s*(])', r'\1', new_str) left_bracket_str = re.sub(r'(\[)\s*', r'\1', right_bracket_str) newer_str = re.sub(r'\[(.\d*),\s*(.\d*)\],\s*', r'[\1, \2], ', left_bracket_str) final_str = re.sub(r'\[(.\d*),\s*(.\d*)\]', r'[\1, \2]', newer_str) # write the data into a file sch_path = os.path.join(sched_dir, 'schedule.json') with open(sch_path, 'w') as fp: fp.write(final_str) # translate the program types to honeybee json src_ptype_dir = os.path.join(source_dir, 'program_type') for f in os.listdir(src_ptype_dir): f_path = os.path.join(src_ptype_dir, f) if os.path.isfile(f_path) and f_path.endswith('.json') \ and not f_path.endswith('registry.json'): with open(f_path, 'r') as json_file: p_dict = json.load(json_file) hb_dict = {} for p_id in p_dict: hb_dict[p_id] = \ program_lib.program_type_by_identifier(p_id).to_dict(abridged=True) dest_file = os.path.join(ptype_dir, f) with open(dest_file, 'w') as fp: json.dump(hb_dict, fp, indent=2) # copy the program registry files over to the data folder for f in os.listdir(src_ptype_dir): f_path = os.path.join(src_ptype_dir, f) if os.path.isfile(f_path) and f_path.endswith('registry.json'): dest_file = os.path.join(ptype_reg_dir, f) shutil.copy(f_path, dest_file) print('Successfully translated OpenStudio JSONs to Honeybee.')
ghenv.Component.AdditionalHelpFromDocStrings = "1" try: from honeybee.room import Room except ImportError as e: raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: from honeybee_energy.lib.programtypes import program_type_by_identifier, \ building_program_type_by_identifier except ImportError as e: raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: from ladybug_rhino.grasshopper import all_required_inputs, longest_list except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # duplicate the initial objects rooms = [obj.duplicate() for obj in _rooms if isinstance(obj, Room)] # apply the program to the rooms for i, room in enumerate(rooms): prog = longest_list(_program, i) if isinstance(prog, str): # get the program object if it is a string try: prog = building_program_type_by_identifier(prog) except ValueError: prog = program_type_by_identifier(prog) room.properties.energy.program_type = prog
def program_type_abridged_kitchen(directory): kitchen = program_type_by_identifier( '2013::FullServiceRestaurant::Kitchen').duplicate() dest_file = os.path.join(directory, 'program_type_abridged_kitchen.json') with open(dest_file, 'w') as fp: json.dump(kitchen.to_dict(abridged=True), fp, indent=4)
try: # import the core honeybee dependencies from honeybee.typing import clean_and_id_ep_string, clean_ep_string except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) try: from honeybee_energy.programtype import ProgramType from honeybee_energy.lib.programtypes import program_type_by_identifier except ImportError as e: raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # set default ratios to None _ratios_ = _ratios_ if len(_ratios_) != 0 else None name = clean_and_id_ep_string('ProgramType') if _name_ is None else \ clean_ep_string(_name_) # get programs from library if a name is input for i, prog in enumerate(_programs): if isinstance(prog, str): _programs[i] = program_type_by_identifier(prog) # create blended program program = ProgramType.average(name, _programs, _ratios_) if _name_ is not None: program.display_name = _name_
raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # get the base program type if base_program_ is None: program = ProgramType(clean_and_id_ep_string(_name)) program.display_name = _name else: if isinstance(base_program_, str): base_program_ = program_type_by_identifier(base_program_) program = base_program_.duplicate() program.identifier = clean_and_id_ep_string(_name) program.display_name = _name # go through each input load and assign it to the set if _people_ is not None: program.people = _people_ if _lighting_ is not None: program.lighting = _lighting_ if _electric_equip_ is not None: program.electric_equipment = _electric_equip_ if _gas_equip_ is not None: program.gas_equipment = _gas_equip_ if _infiltration_ is not None: program.infiltration = _infiltration_
def processItem(item): tpBuilding = item[0] tpShadingFacesCluster = item[1] buildingName = item[2] defaultProgramIdentifier = item[3] defaultConstructionSetIdentifier = item[4] coolingSetpoint = item[5] heatingSetpoint = item[6] humidifyingSetpoint = item[7] dehumidifyingSetpoint = item[8] roomNameKey = item[9] roomTypeKey = item[10] if buildingName: buildingName = buildingName.replace(" ","_") else: buildingName = "GENERICBUILDING" rooms = [] tpCells = [] _ = tpBuilding.Cells(None, tpCells) # Sort cells by Z Levels tpCells.sort(key=lambda c: cellFloor(c), reverse=False) fl = floorLevels(tpCells, 2) spaceNames = [] for spaceNumber, tpCell in enumerate(tpCells): tpDictionary = tpCell.GetDictionary() tpCellName = None tpCellStory = None tpCellProgramIdentifier = None tpCellConstructionSetIdentifier = None tpCellConditioned = True if tpDictionary: keyName = getKeyName(tpDictionary, 'Story') tpCellStory = DictionaryValueAtKey.processItem(tpDictionary, keyName) if tpCellStory: tpCellStory = tpCellStory.replace(" ","_") else: tpCellStory = fl[spaceNumber] if roomNameKey: keyName = getKeyName(tpDictionary, roomNameKey) else: keyName = getKeyName(tpDictionary, 'Name') tpCellName = DictionaryValueAtKey.processItem(tpDictionary,keyName) if tpCellName: tpCellName = createUniqueName(tpCellName.replace(" ","_"), spaceNames, 1) else: tpCellName = tpCellStory+"_SPACE_"+(str(spaceNumber+1)) if roomTypeKey: keyName = getKeyName(tpDictionary, roomTypeKey) else: keyName = getKeyName(tpDictionary, 'Program') tpCellProgramIdentifier = DictionaryValueAtKey.processItem(tpDictionary, keyName) if tpCellProgramIdentifier: program = prog_type_lib.program_type_by_identifier(tpCellProgramIdentifier) elif defaultProgramIdentifier: program = prog_type_lib.program_type_by_identifier(defaultProgramIdentifier) else: program = prog_type_lib.office_program #Default Office Program as a last resort keyName = getKeyName(tpDictionary, 'construction_set') tpCellConstructionSetIdentifier = DictionaryValueAtKey.processItem(tpDictionary, keyName) if tpCellConstructionSetIdentifier: constr_set = constr_set_lib.construction_set_by_identifier(tpCellConstructionSetIdentifier) elif defaultConstructionSetIdentifier: constr_set = constr_set_lib.construction_set_by_identifier(defaultConstructionSetIdentifier) else: constr_set = constr_set_lib.construction_set_by_identifier("Default Generic Construction Set") else: tpCellStory = fl[spaceNumber] tpCellName = tpCellStory+"_SPACE_"+(str(spaceNumber+1)) program = prog_type_lib.office_program constr_set = constr_set_lib.construction_set_by_identifier("Default Generic Construction Set") spaceNames.append(tpCellName) tpCellFaces = [] _ = tpCell.Faces(None, tpCellFaces) if tpCellFaces: hbRoomFaces = [] for tpFaceNumber, tpCellFace in enumerate(tpCellFaces): tpCellFaceNormal = topologic.FaceUtility.NormalAtParameters(tpCellFace, 0.5, 0.5) hbRoomFacePoints = [] tpFaceVertices = [] _ = tpCellFace.ExternalBoundary().Vertices(None, tpFaceVertices) for tpVertex in tpFaceVertices: hbRoomFacePoints.append(Point3D(tpVertex.X(), tpVertex.Y(), tpVertex.Z())) hbRoomFace = Face(tpCellName+'_Face_'+str(tpFaceNumber+1), Face3D(hbRoomFacePoints)) tpFaceApertures = [] _ = tpCellFace.Apertures(tpFaceApertures) if tpFaceApertures: for tpFaceApertureNumber, tpFaceAperture in enumerate(tpFaceApertures): apertureTopology = topologic.Aperture.Topology(tpFaceAperture) tpFaceApertureDictionary = apertureTopology.GetDictionary() if tpFaceApertureDictionary: tpFaceApertureType = DictionaryValueAtKey.processItem(tpFaceApertureDictionary,'type') hbFaceAperturePoints = [] tpFaceApertureVertices = [] _ = apertureTopology.ExternalBoundary().Vertices(None, tpFaceApertureVertices) for tpFaceApertureVertex in tpFaceApertureVertices: hbFaceAperturePoints.append(Point3D(tpFaceApertureVertex.X(), tpFaceApertureVertex.Y(), tpFaceApertureVertex.Z())) if(tpFaceApertureType): if ("door" in tpFaceApertureType.lower()): hbFaceAperture = Door(tpCellName+'_Face_'+str(tpFaceNumber+1)+'_Door_'+str(tpFaceApertureNumber), Face3D(hbFaceAperturePoints)) else: hbFaceAperture = Aperture(tpCellName+'_Face_'+str(tpFaceNumber+1)+'_Window_'+str(tpFaceApertureNumber), Face3D(hbFaceAperturePoints)) else: hbFaceAperture = Aperture(tpCellName+'_Face_'+str(tpFaceNumber+1)+'_Window_'+str(tpFaceApertureNumber), Face3D(hbFaceAperturePoints)) hbRoomFace.add_aperture(hbFaceAperture) else: tpFaceDictionary = tpCellFace.GetDictionary() if (abs(tpCellFaceNormal[2]) < 1e-6) and tpFaceDictionary: #It is a mostly vertical wall and has a dictionary apertureRatio = DictionaryValueAtKey.processItem(tpFaceDictionary,'apertureRatio') if apertureRatio: hbRoomFace.apertures_by_ratio(apertureRatio, tolerance=0.01) fType = honeybee.facetype.get_type_from_normal(Vector3D(tpCellFaceNormal[0],tpCellFaceNormal[1],tpCellFaceNormal[2]), roof_angle=30, floor_angle=150) hbRoomFace.type = fType hbRoomFaces.append(hbRoomFace) room = Room(tpCellName, hbRoomFaces, 0.01, 1) heat_setpt = ScheduleRuleset.from_constant_value('Room Heating', heatingSetpoint, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value('Room Cooling', coolingSetpoint, schedule_types.temperature) humidify_setpt = ScheduleRuleset.from_constant_value('Room Humidifying', humidifyingSetpoint, schedule_types.humidity) dehumidify_setpt = ScheduleRuleset.from_constant_value('Room Dehumidifying', dehumidifyingSetpoint, schedule_types.humidity) setpoint = Setpoint('Room Setpoint', heat_setpt, cool_setpt, humidify_setpt, dehumidify_setpt) simple_office = ScheduleDay('Simple Weekday', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) #Todo: Remove hardwired scheduleday schedule = ScheduleRuleset('Office Water Use', simple_office, None, schedule_types.fractional) #Todo: Remove hardwired schedule shw = ServiceHotWater('Office Hot Water', 0.1, schedule) #Todo: Remove hardwired schedule hot water room.properties.energy.program_type = program room.properties.energy.construction_set = constr_set room.properties.energy.add_default_ideal_air() #Ideal Air Exchange room.properties.energy.setpoint = setpoint #Heating/Cooling/Humidifying/Dehumidifying room.properties.energy.service_hot_water = shw #Service Hot Water if tpCellStory: room.story = tpCellStory rooms.append(room) Room.solve_adjacency(rooms, 0.01) #for room in rooms: #room.properties.energy.construction_set = constr_set #Room.stories_by_floor_height(rooms, min_difference=2.0) if(tpShadingFacesCluster): hbShades = [] tpShadingFaces = [] _ = tpShadingFacesCluster.Faces(None, tpShadingFaces) for faceIndex, tpShadingFace in enumerate(tpShadingFaces): faceVertices = [] _ = tpShadingFace.ExternalBoundary().Vertices(None, faceVertices) facePoints = [] for aVertex in faceVertices: facePoints.append(Point3D(aVertex.X(), aVertex.Y(), aVertex.Z())) hbShadingFace = Face3D(facePoints, None, []) hbShade = Shade("SHADINGSURFACE_" + str(faceIndex+1), hbShadingFace) hbShades.append(hbShade) model = Model(buildingName, rooms, orphaned_shades=hbShades) return model
new_prog = program.duplicate() new_prog.identifier = '{}_{}'.format(program.identifier, str(uuid.uuid4())[:8]) return new_prog if all_required_inputs(ghenv.Component): # duplicate the initial objects mod_obj = [] for obj in _room_or_program: if isinstance(obj, Room): mod_obj.append(obj.duplicate()) elif isinstance(obj, ProgramType): mod_obj.append(duplicate_and_id_program(obj)) elif isinstance(obj, str): program = program_type_by_identifier(obj) mod_obj.append(duplicate_and_id_program(program)) else: raise TypeError('Expected Honeybee Room or ProgramType. ' 'Got {}.'.format(type(obj))) # assign the occupancy schedule if len(occupancy_sch_) != 0: for i, obj in enumerate(mod_obj): people = dup_load(obj, 'people', 'occupancy_sch_') people.occupancy_schedule = schedule_object( longest_list(occupancy_sch_, i)) assign_load(obj, people, 'people') # assign the activity schedule if len(activity_sch_) != 0:
def processItem(item): return prog_type_lib.program_type_by_identifier(item)