def test_energy_properties(): """Test the existence of the Shade energy properties.""" shade = Shade.from_vertices('overhang', [[0, 0, 3], [1, 0, 3], [1, 1, 3], [0, 1, 3]]) assert hasattr(shade.properties, 'energy') assert isinstance(shade.properties.energy, ShadeEnergyProperties) assert isinstance(shade.properties.energy.construction, ShadeConstruction)
def test_default_properties(): """Test the auto-assigning of shade properties.""" out_shade = Shade.from_vertices( 'overhang', [[0, 0, 3], [1, 0, 3], [1, 1, 3], [0, 1, 3]]) in_shade = Shade.from_vertices( 'light_shelf', [[0, 0, 3], [-1, 0, 3], [-1, -1, 3], [0, -1, 3]]) aperture = Aperture.from_vertices( 'parent_aperture', [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]]) assert out_shade.properties.radiance.modifier == generic_context assert in_shade.properties.radiance.modifier == generic_context aperture.add_outdoor_shade(out_shade) assert out_shade.properties.radiance.modifier == generic_exterior_shade aperture.add_indoor_shade(in_shade) assert in_shade.properties.radiance.modifier == generic_interior_shade
def test_writer(): """Test the Shade writer object.""" vertices = [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]] shd = Shade.from_vertices('RectangleShade', vertices) writers = [mod for mod in dir(shd.to) if not mod.startswith('_')] for writer in writers: assert callable(getattr(shd.to, writer))
def test_to_from_dict(): """Test the to/from dict of Shade objects.""" vertices = [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]] shd = Shade.from_vertices('RectangleShade', vertices, True) shd_dict = shd.to_dict() new_shd = Shade.from_dict(shd_dict) assert isinstance(new_shd, Shade) assert new_shd.to_dict() == shd_dict
def test_set_transmittance_schedule(): """Test the setting of transmittance_schedule on a Shade.""" shade = Shade.from_vertices('overhang', [[0, 0, 3], [1, 0, 3], [1, 1, 3], [0, 1, 3]]) fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.5, schedule_types.fractional) shade.properties.energy.transmittance_schedule = fritted_glass_trans assert shade.properties.energy.transmittance_schedule == fritted_glass_trans
def test_from_dict(): """Test the Shade from_dict method with radiance properties.""" shade = Shade.from_vertices( 'tree', [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]]) foliage = Glass.from_single_transmittance('Foliage', 0.2) shade.properties.radiance.modifier = foliage shdd = shade.to_dict() new_shade = Shade.from_dict(shdd) assert new_shade.properties.radiance.modifier == foliage assert new_shade.to_dict() == shdd
def test_set_modifier(): """Test the setting of a modifier on a Shade.""" shade = Shade.from_vertices('tree', [[0, 0, 3], [1, 0, 3], [1, 1, 3], [0, 1, 3]]) foliage = Glass.from_single_transmittance('Foliage', 0.2) shade.properties.radiance.modifier = foliage assert shade.properties.radiance.modifier == foliage assert shade.properties.radiance.is_modifier_set_on_object with pytest.raises(AttributeError): shade.properties.radiance.modifier.r_transmittance = 0.1
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 test_to_dict(): """Test the shade to_dict method.""" vertices = [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]] dr = Shade.from_vertices('Rectangle Shade', vertices) drd = dr.to_dict() assert drd['type'] == 'Shade' assert drd['name'] == 'RectangleShade' assert drd['display_name'] == 'Rectangle Shade' assert 'geometry' in drd assert len(drd['geometry']['boundary']) == len(vertices) assert 'properties' in drd assert drd['properties']['type'] == 'ShadeProperties'
def test_writer_to_rad(): """Test the Shade to.rad method.""" pts = [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]] shade = Shade.from_vertices('tree', pts) foliage = Glass.from_single_transmittance('Foliage', 0.2) shade.properties.radiance.modifier = foliage assert hasattr(shade.to, 'rad') rad_string = shade.to.rad(shade) assert 'polygon tree' in rad_string assert 'Foliage' in rad_string for pt in pts: assert ' '.join([str(float(x)) for x in pt]) in rad_string
def test_to_dict(): """Test the shade to_dict method.""" vertices = [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]] shd = Shade.from_vertices('RectangleShade', vertices) shd = shd.to_dict() assert shd['type'] == 'Shade' assert shd['identifier'] == 'RectangleShade' assert shd['display_name'] == 'RectangleShade' assert 'geometry' in shd assert len(shd['geometry']['boundary']) == len(vertices) assert 'properties' in shd assert shd['properties']['type'] == 'ShadeProperties'
def test_shade_from_vertices(): """Test the initialization of shade objects from vertices.""" pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0)) shade = Shade.from_vertices('Test Shade', pts) assert shade.name == 'TestShade' assert shade.display_name == 'Test Shade' assert isinstance(shade.geometry, Face3D) assert len(shade.vertices) == 4 assert shade.upper_left_vertices[0] == Point3D(1, 0, 3) assert shade.normal == Vector3D(0, 1, 0) assert shade.center == Point3D(0.5, 0, 1.5) assert shade.area == 3 assert shade.perimeter == 8 assert not shade.has_parent
def test_default_properties(): """Test the auto-assigning of shade properties.""" shade = Shade.from_vertices('overhang', [[0, 0, 3], [1, 0, 3], [1, 1, 3], [0, 1, 3]]) aperture = Aperture.from_vertices( 'ParentAperture', [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]]) assert shade.properties.energy.transmittance_schedule is None assert shade.properties.energy.construction.solar_reflectance == 0.2 assert shade.properties.energy.construction.visible_reflectance == 0.2 assert not shade.properties.energy.construction.is_specular assert shade.properties.energy.transmittance_schedule is None aperture.add_outdoor_shade(shade) assert shade.properties.energy.construction.solar_reflectance == 0.35 assert shade.properties.energy.construction.visible_reflectance == 0.35 assert not shade.properties.energy.construction.is_specular
def test_radiance_properties(): """Test the existence of the Shade radiance properties.""" shade = Shade.from_vertices('overhang', [[0, 0, 3], [1, 0, 3], [1, 1, 3], [0, 1, 3]]) assert hasattr(shade.properties, 'radiance') assert isinstance(shade.properties.radiance, ShadeRadianceProperties) assert isinstance(shade.properties.radiance.modifier, Modifier) assert shade.properties.radiance.modifier == generic_context assert shade.properties.radiance.modifier_blk == black assert not shade.properties.radiance.is_modifier_set_on_object frit_glass = Glass.from_single_transmittance('FritGlass', 0.2) shade.properties.radiance.modifier = frit_glass assert shade.properties.radiance.modifier_blk == frit_glass assert shade.properties.radiance.is_modifier_set_on_object
def test_to_dict(): """Test the Shade to_dict method with radiance properties.""" shade = Shade.from_vertices( 'tree', [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]]) foliage = Glass.from_single_transmittance('Foliage', 0.2) shdd = shade.to_dict() assert 'properties' in shdd assert shdd['properties']['type'] == 'ShadeProperties' assert 'radiance' in shdd['properties'] assert shdd['properties']['radiance']['type'] == 'ShadeRadianceProperties' shade.properties.radiance.modifier = foliage shdd = shade.to_dict() assert 'modifier' in shdd['properties']['radiance'] assert shdd['properties']['radiance']['modifier'] is not None assert shdd['properties']['radiance']['modifier'][ 'identifier'] == 'Foliage'
def test_writer_to_rad_folder_dynamic(): """Test the Model to.rad_folder method with dynamic geometry.""" room = Room.from_box('Tiny_House_Zone', 5, 10, 3) garage = Room.from_box('Tiny_Garage', 5, 10, 3, origin=Point3D(5, 0, 0)) south_face = room[3] south_face.apertures_by_ratio(0.5, 0.01) shd1 = StateGeometry.from_vertices( 'outdoor_awning', [[0, 0, 2], [5, 0, 2], [5, 2, 2], [0, 2, 2]]) ecglass1 = Glass.from_single_transmittance('ElectrochromicState1', 0.4) ecglass2 = Glass.from_single_transmittance('ElectrochromicState2', 0.27) ecglass3 = Glass.from_single_transmittance('ElectrochromicState3', 0.14) ecglass4 = Glass.from_single_transmittance('ElectrochromicState4', 0.01) tint1 = RadianceSubFaceState(ecglass1) tint2 = RadianceSubFaceState(ecglass2) tint3 = RadianceSubFaceState(ecglass3, [shd1]) tint4 = RadianceSubFaceState(ecglass4, [shd1.duplicate()]) states = (tint1, tint2, tint3, tint4) south_face.apertures[0].properties.radiance.dynamic_group_identifier = \ 'ElectrochromicWindow' south_face.apertures[0].properties.radiance.states = states shd2 = Shade.from_vertices( 'indoor_light_shelf', [[0, 0, 2], [-1, 0, 2], [-1, 2, 2], [0, 2, 2]]) ref_1 = Plastic.from_single_reflectance('outdoor_light_shelf_0.5', 0.5) ref_2 = Plastic.from_single_reflectance('indoor_light_shelf_0.70', 0.7) light_shelf_1 = RadianceShadeState(ref_1) light_shelf_2 = RadianceShadeState(ref_2) shelf_states = (light_shelf_1, light_shelf_2) shd2.properties.radiance.dynamic_group_identifier = 'DynamicLightShelf' shd2.properties.radiance.states = shelf_states room.add_indoor_shade(shd2) 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 = Glass.from_single_transmittance('custom_triple_pane_0.3', 0.3) aperture.properties.radiance.modifier = 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) sum_tree_trans = Trans.from_single_reflectance('SummerLeaves', 0.3, 0.0, 0.1, 0.15, 0.15) win_tree_trans = Trans.from_single_reflectance('WinterLeaves', 0.1, 0.0, 0.1, 0.1, 0.6) summer = RadianceShadeState(sum_tree_trans) winter = RadianceShadeState(win_tree_trans) tree_canopy.properties.radiance.dynamic_group_identifier = 'DeciduousTree' tree_canopy.properties.radiance.states = (summer, winter) ground_geo = Face3D.from_rectangle(10, 10, Plane(o=Point3D(0, -10, 0))) ground = Shade('Ground', ground_geo) grass = Plastic.from_single_reflectance('grass', 0.3) snow = Plastic.from_single_reflectance('snow', 0.7) summer_ground = RadianceShadeState(grass) winter_ground = RadianceShadeState(snow) ground.properties.radiance.dynamic_group_identifier = 'SeasonalGround' ground.properties.radiance.states = (summer_ground, winter_ground) east_face = room[2] east_face.apertures_by_ratio(0.1, 0.01) west_face = garage[4] west_face.apertures_by_ratio(0.1, 0.01) Room.solve_adjacency([room, garage], 0.01) model = Model('Tiny_House', [room, garage], orphaned_shades=[ground, tree_canopy]) folder = os.path.abspath('./tests/assets/model/rad_folder_dynamic') model.to.rad_folder(model, folder) model_folder = ModelFolder(folder) ap_dir = model_folder.aperture_group_folder(full=True) assert os.path.isfile(os.path.join(ap_dir, 'states.json')) group_name = south_face.apertures[0].properties.radiance.dynamic_group_identifier assert os.path.isfile(os.path.join(ap_dir, '{}..black.rad'.format(group_name))) for i in range(len(south_face.apertures[0].properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..default..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) for i in range(len(south_face.apertures[0].properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..direct..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) out_scene_dir = model_folder.dynamic_scene_folder(full=True, indoor=False) assert os.path.isfile(os.path.join(out_scene_dir, 'states.json')) grp_name = tree_canopy.properties.radiance.dynamic_group_identifier for i in range(len(tree_canopy.properties.radiance.states)): d_file = (os.path.join(out_scene_dir, '{}..default..{}.rad'.format(grp_name, i))) assert os.path.isfile(d_file) for i in range(len(tree_canopy.properties.radiance.states)): d_file = (os.path.join(out_scene_dir, '{}..direct..{}.rad'.format(grp_name, i))) assert os.path.isfile(d_file) grp_name = ground.properties.radiance.dynamic_group_identifier for i in range(len(ground.properties.radiance.states)): d_file = (os.path.join(out_scene_dir, '{}..default..{}.rad'.format(grp_name, i))) assert os.path.isfile(d_file) for i in range(len(ground.properties.radiance.states)): d_file = (os.path.join(out_scene_dir, '{}..direct..{}.rad'.format(grp_name, i))) d_file = (os.path.join(out_scene_dir, '{}..direct..{}.rad'.format(grp_name, i))) assert os.path.isfile(d_file) in_scene_dir = model_folder.dynamic_scene_folder(full=True, indoor=True) assert os.path.isfile(os.path.join(in_scene_dir, 'states.json')) grp_name = shd2.properties.radiance.dynamic_group_identifier for i in range(len(shd2.properties.radiance.states)): d_file = (os.path.join(in_scene_dir, '{}..default..{}.rad'.format(grp_name, i))) assert os.path.isfile(d_file) for i in range(len(shd2.properties.radiance.states)): d_file = (os.path.join(in_scene_dir, '{}..direct..{}.rad'.format(grp_name, i))) assert os.path.isfile(d_file) # clean up the folder nukedir(folder, rmdir=True)
def model_radiance_dynamic_states(directory): room = Room.from_box('Tiny_House_Zone', 5, 10, 3) garage = Room.from_box('Tiny_Garage', 5, 10, 3, origin=Point3D(5, 0, 0)) south_face = room[3] south_face.apertures_by_ratio(0.5, 0.01) shd1 = StateGeometry.from_vertices( 'outdoor_awning', [[0, 0, 2], [5, 0, 2], [5, 2, 2], [0, 2, 2]]) ecglass1 = Glass.from_single_transmittance('ElectrochromicState1', 0.4) ecglass2 = Glass.from_single_transmittance('ElectrochromicState2', 0.27) ecglass3 = Glass.from_single_transmittance('ElectrochromicState3', 0.14) ecglass4 = Glass.from_single_transmittance('ElectrochromicState4', 0.01) tint1 = RadianceSubFaceState(ecglass1) tint2 = RadianceSubFaceState(ecglass2) tint3 = RadianceSubFaceState(ecglass3, [shd1]) tint4 = RadianceSubFaceState(ecglass4, [shd1.duplicate()]) states = (tint1, tint2, tint3, tint4) south_face.apertures[0].properties.radiance.dynamic_group_identifier = \ 'ElectrochromicWindow' south_face.apertures[0].properties.radiance.states = states shd2 = Shade.from_vertices('indoor_light_shelf', [[0, 0, 2], [-1, 0, 2], [-1, 2, 2], [0, 2, 2]]) ref_1 = Plastic.from_single_reflectance('outdoor_light_shelf_0.5', 0.5) ref_2 = Plastic.from_single_reflectance('indoor_light_shelf_0.70', 0.7) light_shelf_1 = RadianceShadeState(ref_1) light_shelf_2 = RadianceShadeState(ref_2) shelf_states = (light_shelf_1, light_shelf_2) shd2.properties.radiance.dynamic_group_identifier = 'DynamicLightShelf' shd2.properties.radiance.states = shelf_states room.add_indoor_shade(shd2) 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 = Glass.from_single_transmittance('custom_triple_pane_0.3', 0.3) aperture.properties.radiance.modifier = 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) sum_tree_trans = Trans.from_single_reflectance('SummerLeaves', 0.3, 0.0, 0.1, 0.15, 0.15) win_tree_trans = Trans.from_single_reflectance('WinterLeaves', 0.1, 0.0, 0.1, 0.1, 0.6) summer = RadianceShadeState(sum_tree_trans) winter = RadianceShadeState(win_tree_trans) tree_canopy.properties.radiance.dynamic_group_identifier = 'DeciduousTree' tree_canopy.properties.radiance.states = (summer, winter) ground_geo = Face3D.from_rectangle(10, 10, Plane(o=Point3D(0, -10, 0))) ground = Shade('Ground', ground_geo) grass = Plastic.from_single_reflectance('grass', 0.3) snow = Plastic.from_single_reflectance('snow', 0.7) summer_ground = RadianceShadeState(grass) winter_ground = RadianceShadeState(snow) ground.properties.radiance.dynamic_group_identifier = 'SeasonalGround' ground.properties.radiance.states = (summer_ground, winter_ground) east_face = room[2] east_face.apertures_by_ratio(0.1, 0.01) west_face = garage[4] west_face.apertures_by_ratio(0.1, 0.01) Room.solve_adjacency([room, garage], 0.01) model = Model('Tiny_House', [room, garage], orphaned_shades=[ground, tree_canopy]) model_dict = model.to_dict(included_prop=['radiance']) dest_file = os.path.join(directory, 'model_radiance_dynamic_states.json') with open(dest_file, 'w') as fp: json.dump(model_dict, fp, indent=4)