def test_construction_set_lib(): """Test that the honeybee-energy lib has been extended with new counstruction set data.""" assert len(constr_set_lib.CONSTRUCTION_SETS ) > 2 # should now have many more construction sets cset_from_lib = constr_set_lib.construction_set_by_identifier( constr_set_lib.CONSTRUCTION_SETS[0]) assert isinstance(cset_from_lib, ConstructionSet) cset_from_lib = constr_set_lib.construction_set_by_identifier( constr_set_lib.CONSTRUCTION_SETS[2]) assert isinstance(cset_from_lib, ConstructionSet)
def construction_sets_by_id(construction_set_ids, none_defaults, complete, output_file): """Get several construction set definitions from the standards lib at once. \b Args: construction_set_ids: Any number of construction set identifiers to be retrieved from the library. """ try: abridged = not complete cons = [] for con_id in construction_set_ids: cons.append(construction_set_by_identifier(con_id)) output_file.write( json.dumps([ con.to_dict(none_for_defaults=none_defaults, abridged=abridged) for con in cons ])) except Exception as e: _logger.exception( 'Retrieval from construction set library failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
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 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 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 construction_set_by_id(construction_set_id, none_defaults, abridged, output_file): """Get a construction set definition from the standards lib with its identifier. \n Args: construction_set_id: The identifier of a construction set in the library. """ try: c_set = construction_set_by_identifier(construction_set_id) output_file.write(json.dumps(c_set.to_dict( none_for_defaults=none_defaults, abridged=abridged))) except Exception as e: _logger.exception( 'Retrieval from construction set library failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def apply_properties_from_geojson_dict(self, data): """Apply properties from a geoJSON dictionary. Args: data: A dictionary representation of a geoJSON feature properties. Specifically, this should be the "properties" key describing a Polygon or MultiPolygon object. """ # determine the vintage of the building template = data['template'] if 'template' in data else '90.1-2013' vintage = self._VINTAGE_MAP[template] # assign the construction set based on climate zone if 'climate_zone' in data: zone_int = str(data['climate_zone'])[0] c_set_id = '{}::{}{}::SteelFramed'.format(vintage[0], 'ClimateZone', zone_int) try: self.construction_set = construction_set_by_identifier( c_set_id) except ValueError: # not a construction set in the library pass # assign the program based on the building type if 'building_type' in data: try: self.set_all_program_type_from_building_type( data['building_type']) except ValueError: # not a building type in the library pass # assign the HVAC based on the name if 'system_type' in data: hvac_instance = self._hvac_from_long_name(data['system_type'], vintage[1]) if hvac_instance is not None: self.set_all_room_2d_hvac(hvac_instance, False)
""" ghenv.Component.Name = "HB Apply ConstructionSet" ghenv.Component.NickName = 'ApplyConstrSet' ghenv.Component.Message = '0.1.1' ghenv.Component.Category = 'HB-Energy' ghenv.Component.SubCategory = '1 :: Constructions' ghenv.Component.AdditionalHelpFromDocStrings = '3' try: # import the honeybee-energy extension from honeybee_energy.lib.constructionsets import construction_set_by_identifier except ImportError as e: raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: # import the ladybug_rhino dependencies 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): # duplicate the initial objects rooms = [obj.duplicate() for obj in _rooms] # process the input construction set if it's a string if isinstance(_constr_set, str): _constr_set = construction_set_by_identifier(_constr_set) # assign the construction set for rm in rooms: rm.properties.energy.construction_set = _constr_set
def constructionset_partial_exterior(directory): exterior_set = construction_set_by_identifier('2013::ClimateZone5::SteelFramed') dest_file = os.path.join(directory, 'constructionset_partial_exterior.json') with open(dest_file, 'w') as fp: json.dump(exterior_set.to_dict(False, True), fp, indent=4)
from honeybee_energy.lib.programtypes import program_type_by_identifier from honeybee_energy.lib.constructionsets import construction_set_by_identifier except ImportError as e: raise ImportError( '\nFailed to import honeybee_energy energy:\n\t{}'.format(e)) try: # import the dragonfly-energy extension import dragonfly_energy except ImportError as e: raise ImportError( '\nFailed to import dragonfly_energy energy:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # duplicate the initial objects df_obj = _df_obj.duplicate() # try to assign the program if program_ is not None: if isinstance(program_, str): program_ = program_type_by_identifier(program_) if isinstance(df_obj, (Building, Story)): df_obj.properties.energy.set_all_room_2d_program_type(program_) else: # it's a Room2D df_obj.properties.energy.program_type = program_ # try to assign the construction set if constr_set_ is not None: if isinstance(constr_set_, str): constr_set_ = construction_set_by_identifier(constr_set_) df_obj.properties.energy.construction_set = constr_set_
def processItem(): constrSets = [] constrIdentifiers = list(constr_set_lib.CONSTRUCTION_SETS) for constrIdentifier in constrIdentifiers: constrSets.append(constr_set_lib.construction_set_by_identifier(constrIdentifier)) return [constrSets, constrIdentifiers]
def test_construction_set_by_identifier(): """Test that all of the construction sets in the library can be loaded by identifier.""" for c_set in constr_set_lib.CONSTRUCTION_SETS: cset_from_lib = constr_set_lib.construction_set_by_identifier(c_set) assert isinstance(cset_from_lib, ConstructionSet)
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
def processItem(item): return constr_set_lib.construction_set_by_identifier(item)
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.')
raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies 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 construction set name = clean_and_id_ep_string('ConstructionSet') if _name_ is None else \ clean_ep_string(_name_) if base_constr_set_ is None: constr_set = ConstructionSet(name) else: if isinstance(base_constr_set_, str): base_constr_set_ = construction_set_by_identifier(base_constr_set_) constr_set = base_constr_set_.duplicate() constr_set.identifier = name if _name_ is not None: constr_set.display_name = _name_ # go through each input construction subset and assign it to the set if len(_exterior_subset_) != 0: assert len( _exterior_subset_) == 3, 'Input _exterior_subset_ is not valid.' if _exterior_subset_[0] is not None: constr_set.wall_set.exterior_construction = _exterior_subset_[0] if _exterior_subset_[1] is not None: constr_set.roof_ceiling_set.exterior_construction = _exterior_subset_[ 1] if _exterior_subset_[2] is not None:
def constructions_2004(model_json, climate_zone, output_file): """Convert a Model's constructions to be conformant with ASHRAE 90.1-2004 appendix G. This includes assigning a ConstructionSet that is compliant with Table 5.5 to all rooms in the model. \b Args: model_json: Full path to a Model JSON file. climate_zone: Text indicating the ASHRAE climate zone. This can be a single integer (in which case it is interpreted as A) or it can include the A, B, or C qualifier (eg. 3C). """ 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) w_area = model.exterior_wall_area r_area = model.exterior_roof_area wr = model.exterior_wall_aperture_area / w_area if w_area != 0 else 0 sr = model.exterior_skylight_aperture_area / r_area if r_area != 0 else 0 # get the base ConstructionSet from the standards library clean_cz = str(climate_zone)[0] constr_set_id = '2004::ClimateZone{}::SteelFramed'.format(clean_cz) base_set = construction_set_by_identifier(constr_set_id) # parse the CSV file with exceptions to the base construction set ex_file = os.path.join(os.path.dirname(__file__), 'data', 'ashrae_2004.csv') ex_data = csv_to_matrix(ex_file) ex_cz = clean_cz if climate_zone != '3C' else climate_zone ex_ratio = '100' for ratio in (40, 30, 20, 10): if wr < ratio / 100 + 0.001: ex_ratio = str(ratio) for row in ex_data: if row[0] == ex_cz and row[1] == ex_ratio: vert_except = [float(val) for val in row[2:]] break # change the constructions for fixed and operable windows si_ip_u = 5.678263337 fixed_id = 'U {} SHGC {} Fixed Glz'.format(vert_except[0], vert_except[2]) fixed_mat = EnergyWindowMaterialSimpleGlazSys(fixed_id, vert_except[0] * si_ip_u, vert_except[2]) fixed_constr = WindowConstruction(fixed_id.replace('Glz', 'Window'), [fixed_mat]) oper_id = 'U {} SHGC {} Operable Glz'.format(vert_except[1], vert_except[2]) oper_mat = EnergyWindowMaterialSimpleGlazSys(oper_id, vert_except[1] * si_ip_u, vert_except[2]) oper_constr = WindowConstruction(oper_id.replace('Glz', 'Window'), [oper_mat]) base_set.aperture_set.window_construction = fixed_constr base_set.aperture_set.operable_construction = oper_constr # change the construction for skylights if the ratio is greater than 2% if sr > 0.021: for row in ex_data: if row[0] == ex_cz and row[1] == 'sky_5': sky_except = [float(row[2]), float(row[4])] break sky_id = 'U {} SHGC {} Skylight Glz'.format( sky_except[0], sky_except[1]) sky_mat = EnergyWindowMaterialSimpleGlazSys( sky_id, sky_except[0] * si_ip_u, sky_except[1]) sky_constr = WindowConstruction(sky_id.replace('Glz', 'Window'), [sky_mat]) base_set.aperture_set.skylight_construction = sky_constr # remove child constructions ans assign the construction set to all rooms model.properties.energy.remove_child_constructions() for room in model.rooms: room.properties.energy.construction_set = base_set # write the Model JSON string output_file.write(json.dumps(model.to_dict())) except Exception as e: _logger.exception( 'Model baseline construction creation failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)