def model_complete_single_zone_office(directory): room = Room.from_box('Tiny_House_Office', 5, 10, 3) room.properties.energy.program_type = prog_type_lib.office_program room.properties.energy.add_default_ideal_air() stone = EnergyMaterial('Thick Stone', 0.3, 2.31, 2322, 832, 'Rough', 0.95, 0.75, 0.8) thermal_mass_constr = OpaqueConstruction('Thermal Mass Floor', [stone]) room[0].properties.energy.construction = thermal_mass_constr south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.apertures[0].overhang(0.5, indoor=True) south_face.move_shades(Vector3D(0, 0, -0.5)) light_shelf_out = ShadeConstruction('Outdoor_Light_Shelf', 0.5, 0.5) light_shelf_in = ShadeConstruction('Indoor_Light_Shelf', 0.7, 0.7) south_face.apertures[0].outdoor_shades[ 0].properties.energy.construction = light_shelf_out south_face.apertures[0].indoor_shades[ 0].properties.energy.construction = light_shelf_in north_face = room[1] north_face.overhang(0.25, indoor=False) door_verts = [ Point3D(2, 10, 0.1), Point3D(1, 10, 0.1), Point3D(1, 10, 2.5), Point3D(2, 10, 2.5) ] door = Door('Front_Door', Face3D(door_verts)) north_face.add_door(door) aperture_verts = [ Point3D(4.5, 10, 1), Point3D(2.5, 10, 1), Point3D(2.5, 10, 2.5), Point3D(4.5, 10, 2.5) ] aperture = Aperture('Front_Aperture', Face3D(aperture_verts)) triple_pane = WindowConstruction( 'Triple Pane Window', [clear_glass, air_gap, clear_glass, air_gap, clear_glass]) aperture.properties.energy.construction = triple_pane north_face.add_aperture(aperture) tree_canopy_geo = Face3D.from_regular_polygon( 6, 2, Plane(Vector3D(0, 0, 1), Point3D(5, -3, 4))) tree_canopy = Shade('Tree_Canopy', tree_canopy_geo) table_geo = Face3D.from_rectangle(2, 2, Plane(o=Point3D(1.5, 4, 1))) table = Shade('Table', table_geo) room.add_indoor_shade(table) model = Model('Tiny_House', [room], orphaned_shades=[tree_canopy]) dest_file = os.path.join(directory, 'model_complete_single_zone_office.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(), fp, indent=4)
def model_complete_single_zone_office_user_data(directory): room = Room.from_box('Tiny_House_Office', 5, 10, 3) room.properties.energy.program_type = prog_type_lib.office_program room.properties.energy.add_default_ideal_air() south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.apertures[0].overhang(0.5, indoor=True) south_face.move_shades(Vector3D(0, 0, -0.5)) light_shelf_out = ShadeConstruction('Outdoor_Light_Shelf', 0.5, 0.5) light_shelf_in = ShadeConstruction('Indoor_Light_Shelf', 0.7, 0.7) south_face.apertures[0].outdoor_shades[ 0].properties.energy.construction = light_shelf_out south_face.apertures[0].indoor_shades[ 0].properties.energy.construction = light_shelf_in north_face = room[1] north_face.overhang(0.25, indoor=False) door_verts = [ Point3D(2, 10, 0.1), Point3D(1, 10, 0.1), Point3D(1, 10, 2.5), Point3D(2, 10, 2.5) ] door = Door('Front_Door', Face3D(door_verts)) north_face.add_door(door) aperture_verts = [ Point3D(4.5, 10, 1), Point3D(2.5, 10, 1), Point3D(2.5, 10, 2.5), Point3D(4.5, 10, 2.5) ] aperture = Aperture('Front_Aperture', Face3D(aperture_verts)) north_face.add_aperture(aperture) model = Model('Tiny_House', [room]) model_dict = model.to_dict() model_dict['user_data'] = {'site': 'The backyard'} model_dict['rooms'][0]['user_data'] = {'alt_name': 'Little old tiny house'} model_dict['rooms'][0]['faces'][0]['user_data'] = {'alt_name': 'The floor'} model_dict['rooms'][0]['faces'][3]['apertures'][0]['user_data'] = \ {'alt_name': 'Picture window'} model_dict['rooms'][0]['faces'][1]['doors'][0]['user_data'] = \ {'alt_name': 'Front door'} model_dict['rooms'][0]['faces'][3]['apertures'][0]['outdoor_shades'][0]['user_data'] = \ {'alt_name': 'Awning'} dest_file = os.path.join(directory, 'model_complete_user_data.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(), fp, indent=4)
def model_energy_fixed_interval(directory): room = Room.from_box('Tiny_House_Office', 5, 10, 3) room.properties.energy.program_type = prog_type_lib.office_program room.properties.energy.add_default_ideal_air() occ_sched = ScheduleFixedInterval( 'Random Occupancy', [round(random.random(), 4) for i in range(8760)], schedule_types.fractional) new_people = room.properties.energy.people.duplicate() new_people.occupancy_schedule = occ_sched room.properties.energy.people = new_people south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.apertures[0].overhang(0.5, indoor=True) south_face.move_shades(Vector3D(0, 0, -0.5)) light_shelf_out = ShadeConstruction('Outdoor_Light_Shelf', 0.5, 0.5) light_shelf_in = ShadeConstruction('Indoor_Light_Shelf', 0.7, 0.7) south_face.apertures[0].outdoor_shades[0].properties.energy.construction = light_shelf_out south_face.apertures[0].indoor_shades[0].properties.energy.construction = light_shelf_in north_face = room[1] north_face.overhang(0.25, indoor=False) door_verts = [Point3D(2, 10, 0.1), Point3D(1, 10, 0.1), Point3D(1, 10, 2.5), Point3D(2, 10, 2.5)] door = Door('Front_Door', Face3D(door_verts)) north_face.add_door(door) aperture_verts = [Point3D(4.5, 10, 1), Point3D(2.5, 10, 1), Point3D(2.5, 10, 2.5), Point3D(4.5, 10, 2.5)] aperture = Aperture('Front_Aperture', Face3D(aperture_verts)) north_face.add_aperture(aperture) tree_canopy_geo = Face3D.from_regular_polygon( 6, 2, Plane(Vector3D(0, 0, 1), Point3D(5, -3, 4))) tree_canopy = Shade('Tree_Canopy', tree_canopy_geo) winter = [0.75] * 2190 spring = [0.75 - ((x / 2190) * 0.5) for x in range(2190)] summer = [0.25] * 2190 fall = [0.25 + ((x / 2190) * 0.5) for x in range(2190)] trans_sched = ScheduleFixedInterval( 'Seasonal Tree Transmittance', winter + spring + summer + fall, schedule_types.fractional) tree_canopy.properties.energy.transmittance_schedule = trans_sched model = Model('Tiny_House', [room], orphaned_shades=[tree_canopy]) model.north_angle = 15 dest_file = os.path.join( directory, 'model_energy_fixed_interval.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(included_prop=['energy']), fp, indent=4)
def test_shade_lockability(): """Test the lockability of the ShadeConstruction.""" light_shelf_out = ShadeConstruction('Outdoor Light Shelf', 0.4, 0.6) light_shelf_out.solar_reflectance = 0.5 light_shelf_out.lock() with pytest.raises(AttributeError): light_shelf_out.solar_reflectance = 0.4 light_shelf_out.unlock() light_shelf_out.solar_reflectance = 0.4
def test_shade_construction_init(): """Test the initalization of ShadeConstruction objects and basic properties.""" default_constr = ShadeConstruction('Default Shade Construction') light_shelf_out = ShadeConstruction('Outdoor Light Shelf', 0.5, 0.6) str(light_shelf_out) # test the string representation of the construction assert default_constr.is_default assert not light_shelf_out.is_default constr_dup = light_shelf_out.duplicate() assert light_shelf_out.name == constr_dup.name == 'Outdoor Light Shelf' assert light_shelf_out.solar_reflectance == constr_dup.solar_reflectance == 0.5 assert light_shelf_out.visible_reflectance == constr_dup.visible_reflectance == 0.6 assert light_shelf_out.is_specular is constr_dup.is_specular
def test_shade_equivalency(): """Test the equality of a ShadeConstruction to another.""" shade_constr_1 = ShadeConstruction('Outdoor Light Shelf', 0.4, 0.6) shade_constr_2 = shade_constr_1.duplicate() shade_constr_3 = ShadeConstruction('Outdoor Light Shelf', 0.5, 0.6) shade_constr_4 = ShadeConstruction('Indoor Light Shelf', 0.4, 0.6) collection = [shade_constr_1, shade_constr_1, shade_constr_2, shade_constr_3] assert len(set(collection)) == 2 assert shade_constr_1 == shade_constr_2 assert shade_constr_1 != shade_constr_3 assert shade_constr_1 != shade_constr_4 shade_constr_2.identifier = 'Indoor Light Shelf' assert shade_constr_1 != shade_constr_2
def test_writer_to_idf(): """Test the Model to.idf method.""" room = Room.from_box('TinyHouseZone', 5, 10, 3) room.properties.energy.program_type = office_program room.properties.energy.add_default_ideal_air() stone = EnergyMaterial('Thick Stone', 0.3, 2.31, 2322, 832, 'Rough', 0.95, 0.75, 0.8) thermal_mass_constr = OpaqueConstruction('Thermal Mass Floor', [stone]) room[0].properties.energy.construction = thermal_mass_constr south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.apertures[0].overhang(0.5, indoor=True) south_face.move_shades(Vector3D(0, 0, -0.5)) light_shelf_out = ShadeConstruction('OutdoorLightShelf', 0.5, 0.5) light_shelf_in = ShadeConstruction('IndoorLightShelf', 0.7, 0.7) south_face.apertures[0].outdoor_shades[0].properties.energy.construction = light_shelf_out south_face.apertures[0].indoor_shades[0].properties.energy.construction = light_shelf_in north_face = room[1] north_face.overhang(0.25, indoor=False) door_verts = [Point3D(2, 10, 0.1), Point3D(1, 10, 0.1), Point3D(1, 10, 2.5), Point3D(2, 10, 2.5)] door = Door('FrontDoor', Face3D(door_verts)) north_face.add_door(door) aperture_verts = [Point3D(4.5, 10, 1), Point3D(2.5, 10, 1), Point3D(2.5, 10, 2.5), Point3D(4.5, 10, 2.5)] aperture = Aperture('FrontAperture', Face3D(aperture_verts)) triple_pane = WindowConstruction( 'Triple Pane Window', [clear_glass, air_gap, clear_glass, air_gap, clear_glass]) aperture.properties.energy.construction = triple_pane north_face.add_aperture(aperture) tree_canopy_geo = Face3D.from_regular_polygon( 6, 2, Plane(Vector3D(0, 0, 1), Point3D(5, -3, 4))) tree_canopy = Shade('TreeCanopy', tree_canopy_geo) table_geo = Face3D.from_rectangle(2, 2, Plane(o=Point3D(1.5, 4, 1))) table = Shade('Table', table_geo) room.add_indoor_shade(table) model = Model('TinyHouse', [room], orphaned_shades=[tree_canopy]) assert hasattr(model.to, 'idf') idf_string = model.to.idf(model, schedule_directory='./tests/idf/')
def test_duplicate(): """Test what happens to energy properties when duplicating a Shade.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade_original = Shade('overhang', Face3D(verts)) shade_dup_1 = shade_original.duplicate() light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) bright_light_shelf = ShadeConstruction('Bright Light Shelf', 0.7, 0.7, True) fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.5, schedule_types.fractional) assert shade_original.properties.energy.host is shade_original assert shade_dup_1.properties.energy.host is shade_dup_1 assert shade_original.properties.energy.host is not \ shade_dup_1.properties.energy.host assert shade_original.properties.energy.construction == \ shade_dup_1.properties.energy.construction shade_dup_1.properties.energy.construction = light_shelf assert shade_original.properties.energy.construction != \ shade_dup_1.properties.energy.construction shade_dup_2 = shade_dup_1.duplicate() assert shade_dup_1.properties.energy.construction == \ shade_dup_2.properties.energy.construction shade_dup_2.properties.energy.construction = bright_light_shelf assert shade_dup_1.properties.energy.construction != \ shade_dup_2.properties.energy.construction assert shade_original.properties.energy.transmittance_schedule == \ shade_dup_1.properties.energy.transmittance_schedule shade_dup_1.properties.energy.transmittance_schedule = fritted_glass_trans assert shade_original.properties.energy.transmittance_schedule != \ shade_dup_1.properties.energy.transmittance_schedule shade_dup_3 = shade_dup_1.duplicate() assert shade_dup_1.properties.energy.transmittance_schedule == \ shade_dup_3.properties.energy.transmittance_schedule shade_dup_3.properties.energy.transmittance_schedule = None assert shade_dup_1.properties.energy.transmittance_schedule != \ shade_dup_3.properties.energy.transmittance_schedule
def from_dict(cls, data, host): """Create ContextShadeEnergyProperties from a dictionary. Note that the dictionary must be a non-abridged version for this classmethod to work. Args: data: A dictionary representation of ContextShadeEnergyProperties. host: A ContextShade object that hosts these properties. """ assert data['type'] == 'ContextShadeEnergyProperties', \ 'Expected ContextShadeEnergyProperties. Got {}.'.format(data['type']) new_prop = cls(host) if 'construction' in data and data['construction'] is not None: new_prop.construction = ShadeConstruction.from_dict( data['construction']) if 'transmittance_schedule' in data and \ data['transmittance_schedule'] is not None: sch_dict = data['transmittance_schedule'] if sch_dict['type'] == 'ScheduleRuleset': new_prop.transmittance_schedule = \ ScheduleRuleset.from_dict(data['transmittance_schedule']) elif sch_dict['type'] == 'ScheduleFixedInterval': new_prop.transmittance_schedule = \ ScheduleFixedInterval.from_dict(data['transmittance_schedule']) else: raise ValueError( 'Expected non-abridged Schedule dictionary for ContextShade ' 'transmittance_schedule. Got {}.'.format(sch_dict['type'])) return new_prop
def test_set_construction_set(): """Test the setting of a ConstructionSet on a Room2D.""" pts = (Point3D(0, 0, 3), Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(0, 10, 3)) ashrae_base = SimpleWindowRatio(0.4) overhang = Overhang(1) boundarycs = (bcs.outdoors, bcs.ground, bcs.outdoors, bcs.ground) window = (ashrae_base, None, ashrae_base, None) shading = (overhang, None, None, None) room = Room2D('SquareShoebox', Face3D(pts), 3, boundarycs, window, shading) mass_set = ConstructionSet('Thermal Mass Construction Set') concrete20 = EnergyMaterial('20cm Concrete', 0.2, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) concrete10 = EnergyMaterial('10cm Concrete', 0.1, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) thick_constr = OpaqueConstruction('Thick Concrete Construction', [concrete20]) thin_constr = OpaqueConstruction('Thin Concrete Construction', [concrete10]) shade_constr = ShadeConstruction('Light Shelf', 0.5, 0.5) mass_set.wall_set.exterior_construction = thick_constr mass_set.roof_ceiling_set.interior_construction = thin_constr mass_set.shade_construction = shade_constr room.properties.energy.construction_set = mass_set assert room.properties.energy.construction_set == mass_set hb_room, adj = room.to_honeybee() assert hb_room.properties.energy.construction_set == mass_set assert hb_room[1].properties.energy.construction == thick_constr assert hb_room[5].properties.energy.construction == thin_constr assert hb_room[1].shades[0].properties.energy.construction == shade_constr
def test_to_dict(): """Test the Building to_dict method with energy properties.""" tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon( 6, 2, Plane(o=Point3D(-5, -10, 3))) tree_canopy = ContextShade('TreeCanopy', [tree_canopy_geo1, tree_canopy_geo2]) sd = tree_canopy.to_dict() assert 'properties' in sd assert sd['properties']['type'] == 'ContextShadeProperties' assert 'energy' in sd['properties'] assert sd['properties']['energy']['type'] == 'ContextShadeEnergyProperties' assert 'construction' not in sd['properties']['energy'] or \ sd['properties']['energy']['construction'] is None bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True) tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) tree_canopy.properties.energy.construction = bright_leaves tree_canopy.properties.energy.transmittance_schedule = tree_trans sd = tree_canopy.to_dict() assert sd['properties']['energy']['construction'] is not None assert sd['properties']['energy']['transmittance_schedule'] is not None
def test_duplicate(): """Test what happens to energy properties when duplicating a Room2D.""" tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon( 6, 2, Plane(o=Point3D(-5, -10, 3))) shade_original = ContextShade('TreeCanopy', [tree_canopy_geo1, tree_canopy_geo2]) shade_dup_1 = shade_original.duplicate() bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True) tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) assert shade_original.properties.energy.host is shade_original assert shade_dup_1.properties.energy.host is shade_dup_1 assert shade_original.properties.energy.host is not \ shade_dup_1.properties.energy.host assert shade_original.properties.energy.construction == \ shade_dup_1.properties.energy.construction shade_dup_1.properties.energy.construction = bright_leaves assert shade_original.properties.energy.construction != \ shade_dup_1.properties.energy.construction shade_dup_2 = shade_dup_1.duplicate() assert shade_dup_1.properties.energy.construction == \ shade_dup_2.properties.energy.construction shade_dup_2.properties.energy.construction = None assert shade_dup_1.properties.energy.construction != \ shade_dup_2.properties.energy.construction
def test_to_dict(): """Test the Shade to_dict method with energy properties.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade = Shade('overhang', Face3D(verts)) shade_dict = shade.to_dict() assert 'properties' in shade_dict assert shade_dict['properties']['type'] == 'ShadeProperties' assert 'energy' in shade_dict['properties'] assert shade_dict['properties']['energy'][ 'type'] == 'ShadeEnergyProperties' light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) shade.properties.energy.construction = light_shelf shade_dict = shade.to_dict() assert 'construction' in shade_dict['properties']['energy'] assert shade_dict['properties']['energy']['construction'][ 'solar_reflectance'] == 0.5 assert shade_dict['properties']['energy']['construction'][ 'visible_reflectance'] == 0.5 assert shade_dict['properties']['energy']['construction']['is_specular'] fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.5, schedule_types.fractional) shade.properties.energy.transmittance_schedule = fritted_glass_trans shade_dict = shade.to_dict() assert 'transmittance_schedule' in shade_dict['properties']['energy'] assert shade_dict['properties']['energy'][ 'transmittance_schedule'] is not None
def test_writer_to_idf(): """Test the Shade to_idf method.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade = Shade('overhang', Face3D(verts)) assert hasattr(shade.to, 'idf') idf_string = shade.to.idf(shade) assert 'overhang,' in idf_string assert 'Shading:Building:Detailed,' in idf_string assert 'ShadingProperty:Reflectance' not in idf_string shade = Shade('overhang', Face3D(verts)) light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) shade.properties.energy.construction = light_shelf fritted_glass_trans = ScheduleRuleset.from_constant_value( 'FrittedGlass', 0.5, schedule_types.fractional) shade.properties.energy.transmittance_schedule = fritted_glass_trans assert hasattr(shade.to, 'idf') idf_string = shade.to.idf(shade) assert 'overhang,' in idf_string assert 'Shading:Building:Detailed,' in idf_string assert 'ShadingProperty:Reflectance' in idf_string assert 'FrittedGlass' in idf_string
def dict_to_construction(constr_dict, raise_exception=True): """Get a Python object of any Construction from a dictionary. Args: constr_dict: A dictionary of any Honeybee energy construction. Note that this should be a non-abridged dictionary to be valid. raise_exception: Boolean to note whether an excpetion should be raised if the object is not identified as a construction. Default: True. Returns: A Python object derived from the input constr_dict. """ try: # get the type key from the dictionary constr_type = constr_dict['type'] except KeyError: raise ValueError('Construction dictionary lacks required "type" key.') if constr_type == 'OpaqueConstruction': return OpaqueConstruction.from_dict(constr_dict) elif constr_type == 'WindowConstruction': return WindowConstruction.from_dict(constr_dict) elif constr_type == 'WindowConstructionShade': return WindowConstructionShade.from_dict(constr_dict) elif constr_type == 'ShadeConstruction': return ShadeConstruction.from_dict(constr_dict) elif constr_type == 'AirBoundaryConstruction': return AirBoundaryConstruction.from_dict(constr_dict) elif raise_exception: raise ValueError( '{} is not a recognized energy Construction type'.format( constr_type))
def test_shade_construction_to_idf(): """Test the initialization of ShadeConstruction objects and basic properties.""" default_constr = ShadeConstruction('Default Shade Construction') light_shelf_out = ShadeConstruction('Outdoor Light Shelf', 0.5, 0.6, True) assert isinstance(default_constr.to_idf('Test Shade'), str) assert isinstance(light_shelf_out.to_idf('Test Shade'), str) assert default_constr.glazing_construction() is None assert isinstance(light_shelf_out.glazing_construction(), WindowConstruction)
def test_energy_properties(): """Test the existence of the Model energy properties.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) pts_3 = (Point3D(0, 10, 3), Point3D(0, 20, 3), Point3D(10, 20, 3), Point3D(10, 10, 3)) pts_4 = (Point3D(10, 10, 3), Point3D(10, 20, 3), Point3D(20, 20, 3), Point3D(20, 10, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) room2d_3 = Room2D('Office3', Face3D(pts_3), 3) room2d_4 = Room2D('Office4', Face3D(pts_4), 3) story = Story('OfficeFloor', [room2d_1, room2d_2, room2d_3, room2d_4]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 4 for room in story.room_2ds: room.properties.energy.program_type = office_program room.properties.energy.add_default_ideal_air() building = Building('OfficeBuilding', [story]) tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon( 6, 2, Plane(o=Point3D(-5, -10, 3))) tree_canopy = ContextShade('TreeCanopy', [tree_canopy_geo1, tree_canopy_geo2]) bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True) tree_canopy.properties.energy.construction = bright_leaves tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) tree_canopy.properties.energy.transmittance_schedule = tree_trans model = Model('NewDevelopment', [building], [tree_canopy]) assert hasattr(model.properties, 'energy') assert isinstance(model.properties.energy, ModelEnergyProperties) assert isinstance(model.properties.host, Model) assert len(model.properties.energy.materials) == 0 for mat in model.properties.energy.materials: assert isinstance(mat, _EnergyMaterialBase) assert len(model.properties.energy.constructions) == 1 for cnst in model.properties.energy.constructions: assert isinstance(cnst, (WindowConstruction, OpaqueConstruction, ShadeConstruction, AirBoundaryConstruction)) assert len(model.properties.energy.shade_constructions) == 1 assert len(model.properties.energy.construction_sets) == 0 assert len(model.properties.energy.schedule_type_limits) == 3 assert len(model.properties.energy.schedules) == 8 assert len(model.properties.energy.shade_schedules) == 1 assert len(model.properties.energy.program_types) == 1
def test_setting_construction(): """Test the setting of constructions on the ConstructionSet.""" default_set = ConstructionSet('Thermal Mass Construction Set') concrete20 = EnergyMaterial('20cm Concrete', 0.2, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) concrete10 = EnergyMaterial('10cm Concrete', 0.1, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) stone_door = EnergyMaterial('Stone Door', 0.05, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) thick_constr = OpaqueConstruction( 'Thick Concrete Construction', [concrete20]) thin_constr = OpaqueConstruction( 'Thin Concrete Construction', [concrete10]) door_constr = OpaqueConstruction( 'Stone Door', [stone_door]) light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) default_set.wall_set.exterior_construction = thick_constr assert default_set.wall_set.exterior_construction == thick_constr assert len(default_set.modified_constructions_unique) == 1 assert len(default_set.modified_materials_unique) == 1 assert isinstance(default_set.wall_set.exterior_construction[0], EnergyMaterial) with pytest.raises(AttributeError): default_set.wall_set.exterior_construction[0].thickness = 0.15 default_set.wall_set.interior_construction = thin_constr assert default_set.wall_set.interior_construction == thin_constr default_set.wall_set.ground_construction = thick_constr assert default_set.wall_set.ground_construction == thick_constr default_set.floor_set.exterior_construction = thick_constr assert default_set.floor_set.exterior_construction == thick_constr default_set.floor_set.interior_construction = thin_constr assert default_set.floor_set.interior_construction == thin_constr default_set.floor_set.ground_construction = thick_constr assert default_set.floor_set.ground_construction == thick_constr default_set.roof_ceiling_set.exterior_construction = thick_constr assert default_set.roof_ceiling_set.exterior_construction == thick_constr default_set.roof_ceiling_set.interior_construction = thin_constr assert default_set.roof_ceiling_set.interior_construction == thin_constr default_set.roof_ceiling_set.ground_construction = thick_constr assert default_set.roof_ceiling_set.ground_construction == thick_constr default_set.door_set.exterior_construction = door_constr assert default_set.door_set.exterior_construction == door_constr default_set.door_set.interior_construction = door_constr assert default_set.door_set.interior_construction == door_constr default_set.door_set.overhead_construction = door_constr assert default_set.door_set.overhead_construction == door_constr default_set.shade_construction = light_shelf assert default_set.shade_construction == light_shelf assert len(default_set.modified_constructions_unique) == 4 assert len(default_set.modified_materials_unique) == 3
def test_set_construction(): """Test the setting of construction on a Shade.""" shade = Shade.from_vertices('overhang', [[0, 0, 3], [1, 0, 3], [1, 1, 3], [0, 1, 3]]) light_shelf_construction = ShadeConstruction('Light Shelf', 0.5, 0.5, True) shade.properties.energy.construction = light_shelf_construction assert shade.properties.energy.construction == light_shelf_construction assert shade.properties.energy.construction.solar_reflectance == 0.5 assert shade.properties.energy.construction.visible_reflectance == 0.5 assert shade.properties.energy.construction.is_specular
def shade_construction_by_identifier(construction_identifier): """Get an shade construction from the library given the construction identifier. Args: construction_identifier: A text string for the identifier of the construction. """ try: return _shade_constructions[construction_identifier] except KeyError: try: # search the extension data constr_dict = _shade_constr_standards_dict[construction_identifier] return ShadeConstruction.from_dict(constr_dict) except KeyError: # construction is nowhere to be found; raise an error raise ValueError( '"{}" was not found in the shade energy construction library.'. format(construction_identifier))
def test_set_construction_set(): """Test the setting of a ConstructionSet on a Story.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) pts_3 = (Point3D(0, 10, 3), Point3D(0, 20, 3), Point3D(10, 20, 3), Point3D(10, 10, 3)) pts_4 = (Point3D(10, 10, 3), Point3D(10, 20, 3), Point3D(20, 20, 3), Point3D(20, 10, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) room2d_3 = Room2D('Office3', Face3D(pts_3), 3) room2d_4 = Room2D('Office4', Face3D(pts_4), 3) story = Story('OfficeFloor', [room2d_1, room2d_2, room2d_3, room2d_4]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) mass_set = ConstructionSet('Thermal Mass Construction Set') concrete20 = EnergyMaterial('20cm Concrete', 0.2, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) concrete10 = EnergyMaterial('10cm Concrete', 0.1, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) thick_constr = OpaqueConstruction('Thick Concrete Construction', [concrete20]) thin_constr = OpaqueConstruction('Thin Concrete Construction', [concrete10]) shade_constr = ShadeConstruction('Light Shelf', 0.5, 0.5) mass_set.wall_set.exterior_construction = thick_constr mass_set.roof_ceiling_set.interior_construction = thin_constr mass_set.shade_construction = shade_constr story.properties.energy.construction_set = mass_set assert story.properties.energy.construction_set == mass_set assert story[0].properties.energy.construction_set == mass_set rooms = story.to_honeybee() model = hb_model.Model(story.identifier, rooms) assert len(model.properties.energy.construction_sets) == 1 assert model.properties.energy.construction_sets[0] == mass_set assert model.rooms[0].properties.energy.construction_set == mass_set
def test_set_construction_schedule(): """Test the setting of a Construction and Schedule on a ContextShade.""" tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon( 6, 2, Plane(o=Point3D(-5, -10, 3))) tree_canopy = ContextShade('TreeCanopy', [tree_canopy_geo1, tree_canopy_geo2]) bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True) tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) tree_canopy.properties.energy.construction = bright_leaves tree_canopy.properties.energy.transmittance_schedule = tree_trans assert tree_canopy.properties.energy.construction == bright_leaves assert tree_canopy.properties.energy.transmittance_schedule == tree_trans
def context_shade_two_tree_canopy(directory): """Generate the context_shade_two_tree_canopy sample.""" tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon( 6, 2, Plane(o=Point3D(-5, -10, 3))) tree_canopy = ContextShade('Tree Canopy', [tree_canopy_geo1, tree_canopy_geo2]) bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True) tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) tree_canopy.properties.energy.construction = bright_leaves tree_canopy.properties.energy.transmittance_schedule = tree_trans dest_file = os.path.join(directory, 'context_shade_two_tree_canopy.json') with open(dest_file, 'w') as fp: json.dump(tree_canopy.to_dict(True), fp, indent=4)
def test_set_construction_set(): """Test the setting of a ConstructionSet on a Room.""" room = Room.from_box('Shoe Box', 5, 10, 3) door_verts = [[1, 0, 0.1], [2, 0, 0.1], [2, 0, 3], [1, 0, 3]] room[3].add_door(Door.from_vertices('test_door', door_verts)) room[1].apertures_by_ratio(0.4, 0.01) room[1].apertures[0].overhang(0.5, indoor=False) room[1].apertures[0].overhang(0.5, indoor=True) room[1].apertures[0].move_shades(Vector3D(0, 0, -0.5)) mass_set = ConstructionSet('Thermal Mass Construction Set') concrete20 = EnergyMaterial('20cm Concrete', 0.2, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) concrete10 = EnergyMaterial('10cm Concrete', 0.1, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) stone_door = EnergyMaterial('Stone Door', 0.05, 2.31, 2322, 832, 'MediumRough', 0.95, 0.75, 0.8) thick_constr = OpaqueConstruction('Thick Concrete Construction', [concrete20]) thin_constr = OpaqueConstruction('Thin Concrete Construction', [concrete10]) door_constr = OpaqueConstruction('Stone Door', [stone_door]) shade_constr = ShadeConstruction('Light Shelf', 0.5, 0.5) mass_set.wall_set.exterior_construction = thick_constr mass_set.roof_ceiling_set.exterior_construction = thin_constr mass_set.door_set.exterior_construction = door_constr mass_set.shade_construction = shade_constr room.properties.energy.construction_set = mass_set assert room.properties.energy.construction_set == mass_set assert room[1].properties.energy.construction == thick_constr assert room[5].properties.energy.construction == thin_constr assert room[3].doors[0].properties.energy.construction == door_constr assert room[1].apertures[0].shades[ 0].properties.energy.construction == shade_constr with pytest.raises(AttributeError): room[1].properties.energy.construction.thickness = 0.3 with pytest.raises(AttributeError): room[5].properties.energy.construction.thickness = 0.3 with pytest.raises(AttributeError): room[3].doors[0].properties.energy.construction.thickness = 0.3
def test_from_dict(): """Test the Story from_dict method with energy properties.""" tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon( 6, 2, Plane(o=Point3D(-5, -10, 3))) tree_canopy = ContextShade('TreeCanopy', [tree_canopy_geo1, tree_canopy_geo2]) bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True) tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) tree_canopy.properties.energy.construction = bright_leaves tree_canopy.properties.energy.transmittance_schedule = tree_trans sd = tree_canopy.to_dict() new_shd = ContextShade.from_dict(sd) assert new_shd.properties.energy.construction == bright_leaves assert new_shd.properties.energy.transmittance_schedule == tree_trans assert new_shd.to_dict() == sd
def dict_abridged_to_construction(constr_dict, materials, schedules, raise_exception=True): """Get a Python object of any Construction from an abridged dictionary. Args: constr_dict: An abridged dictionary of any Honeybee energy construction. materials: Dictionary of all material objects that might be used in the construction with the material identifiers as the keys. schedules: Dictionary of all schedule objects that might be used in the construction with the schedule identifiers as the keys. raise_exception: Boolean to note whether an excpetion should be raised if the object is not identified as a construction. Default: True. Returns: A Python object derived from the input constr_dict. """ try: # get the type key from the dictionary constr_type = constr_dict['type'] except KeyError: raise ValueError('Construction dictionary lacks required "type" key.') if constr_type == 'OpaqueConstructionAbridged': return OpaqueConstruction.from_dict_abridged(constr_dict, materials) elif constr_type == 'WindowConstructionAbridged': return WindowConstruction.from_dict_abridged(constr_dict, materials) elif constr_type == 'WindowConstructionShade': return WindowConstructionShade.from_dict_abridged( constr_dict, materials, schedules) elif constr_type == 'ShadeConstruction': return ShadeConstruction.from_dict(constr_dict) elif constr_type == 'AirBoundaryConstructionAbridged': return AirBoundaryConstruction.from_dict_abridged( constr_dict, schedules) elif constr_type == 'AirBoundaryConstruction': # special case for ConstructionSet return AirBoundaryConstruction.from_dict(constr_dict) elif raise_exception: raise ValueError( '{} is not a recognized energy Construction type'.format( constr_type))
def test_construction_from_lib(): """Test the existence of construction objects in the library.""" runner = CliRunner() result = runner.invoke(opaque_material_by_id, ['Generic Gypsum Board']) assert result.exit_code == 0 mat_dict = json.loads(result.output) assert isinstance(EnergyMaterial.from_dict(mat_dict), EnergyMaterial) result = runner.invoke(window_material_by_id, ['Generic Low-e Glass']) assert result.exit_code == 0 mat_dict = json.loads(result.output) assert isinstance(EnergyWindowMaterialGlazing.from_dict(mat_dict), EnergyWindowMaterialGlazing) result = runner.invoke(opaque_construction_by_id, ['Generic Exterior Wall']) assert result.exit_code == 0 con_dict = json.loads(result.output) assert isinstance(OpaqueConstruction.from_dict(con_dict), OpaqueConstruction) result = runner.invoke(window_construction_by_id, ['Generic Double Pane']) assert result.exit_code == 0 con_dict = json.loads(result.output) assert isinstance(WindowConstruction.from_dict(con_dict), WindowConstruction) result = runner.invoke(shade_construction_by_id, ['Generic Context']) assert result.exit_code == 0 mat_dict = json.loads(result.output) assert isinstance(ShadeConstruction.from_dict(mat_dict), ShadeConstruction) result = runner.invoke(construction_set_by_id, ['Default Generic Construction Set']) assert result.exit_code == 0 con_dict = json.loads(result.output) assert isinstance(ConstructionSet.from_dict(con_dict), ConstructionSet)
def test_from_dict(): """Test the Shade from_dict method with energy properties.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade = Shade('overhang', Face3D(verts)) light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) shade.properties.energy.construction = light_shelf fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.5, schedule_types.fractional) shade.properties.energy.transmittance_schedule = fritted_glass_trans shade_dict = shade.to_dict() new_shade = Shade.from_dict(shade_dict) assert new_shade.properties.energy.construction == light_shelf assert shade.properties.energy.construction.solar_reflectance == 0.5 assert shade.properties.energy.construction.visible_reflectance == 0.5 assert shade.properties.energy.construction.is_specular assert new_shade.properties.energy.transmittance_schedule == fritted_glass_trans assert new_shade.to_dict() == shade_dict
def test_shade_dict_methods(): """Test the to/from dict methods.""" shade_constr = ShadeConstruction('Outdoor Light Shelf', 0.4, 0.6) constr_dict = shade_constr.to_dict() new_constr = ShadeConstruction.from_dict(constr_dict) assert constr_dict == new_constr.to_dict()
generic_interior_door = _idf_opaque_constructions['Generic Interior Door'] except KeyError: generic_interior_door = OpaqueConstruction( 'Generic Interior Door', _default_prop['generic_interior_door']) generic_interior_door.lock() _idf_opaque_constructions['Generic Interior Door'] = generic_interior_door try: air_wall = _idf_opaque_constructions['Air Wall'] except KeyError: air_wall = OpaqueConstruction('Air Wall', _default_prop['air_wall']) air_wall.lock() _idf_opaque_constructions['Air Wall'] = air_wall # make a dictionary of default shade constructions generic_context = ShadeConstruction('Generic Context') generic_shade = ShadeConstruction('Generic Shade', 0.35, 0.35) _idf_shade_constructions = { generic_context.name: generic_context, generic_shade.name: generic_shade } # make lists of construction names to look up items in the library OPAQUE_CONSTRUCTIONS = tuple(_idf_opaque_constructions.keys()) WINDOW_CONSTRUCTIONS = tuple(_idf_window_constructions.keys()) SHADE_CONSTRUCTIONS = tuple(_idf_shade_constructions.keys()) def opaque_construction_by_name(construction_name): """Get an opaque construction from the library given the construction name.