예제 #1
0
def test_to_from_dict_with_states():
    """Test the Shade from_dict method with radiance properties."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0,
                                                       3), Point3D(1, 0, 0))
    shd = Shade('TreeTrunk', Face3D(pts))
    shd1 = StateGeometry.from_vertices(
        'tree_foliage1', [[0, 0, 5], [2, 0, 5], [2, 2, 5], [0, 2, 5]])
    shd2 = StateGeometry.from_vertices(
        'tree_foliage2', [[0, 0, 5], [-2, 0, 5], [-2, 2, 5], [0, 2, 5]])

    trans1 = Glass.from_single_transmittance('TreeTrans1', 0.5)
    trans2 = Glass.from_single_transmittance('TreeTrans2', 0.27)
    trans3 = Glass.from_single_transmittance('TreeTrans3', 0.14)
    trans4 = Glass.from_single_transmittance('TreeTrans4', 0.01)

    tr1 = RadianceShadeState(trans1)
    tr2 = RadianceShadeState(trans2)
    tr3 = RadianceShadeState(trans3, [shd1])
    tr4 = RadianceShadeState(trans4, [shd1.duplicate(), shd2])
    states = (tr1, tr2, tr3, tr4)

    shd.properties.radiance.dynamic_group_identifier = 'DeciduousTrees'
    shd.properties.radiance.states = states

    ad = shd.to_dict()
    new_shade = Shade.from_dict(ad)
    assert new_shade.properties.radiance.dynamic_group_identifier == \
        shd.properties.radiance.dynamic_group_identifier
    state_ids1 = [state.modifier for state in states]
    state_ids2 = [
        state.modifier for state in new_shade.properties.radiance.states
    ]
    assert state_ids1 == state_ids2
    assert new_shade.to_dict() == ad
예제 #2
0
def shade_state_abridged_snow(directory):
    snow_mod = Plastic.from_single_reflectance('SnowMaterial', 0.7)
    snow = RadianceShadeState(snow_mod)

    dest_file = os.path.join(directory, 'shade_state_abridged_snow.json')
    with open(dest_file, 'w') as fp:
        json.dump(snow.to_dict(abridged=True), fp, indent=4)
예제 #3
0
def reflect_state_shades():
    """Check to be sure that dynamic shades are reflected with their parent."""
    pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2,
                                                       2), Point3D(1, 2, 2))
    ap = Shade('TestShade', Face3D(pts))
    pts_1 = (Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 2,
                                                         0), Point3D(0, 2, 0))
    shade = StateGeometry('RectangleShade', Face3D(pts_1))

    tint1 = RadianceShadeState(shades=[shade])
    ap.properties.radiance.dynamic_group_identifier = 'DeciduousTrees'
    ap.properties.radiance.states = [tint1]
    tint1.gen_geos_from_tmtx_thickness(0.05)

    new_ap = ap.duplicate()
    origin_1 = Point3D(1, 0, 2)
    normal_1 = Vector3D(1, 0, 0)
    plane_1 = Plane(normal_1, origin_1)
    new_ap.reflect(plane_1)
    new_shd = new_ap.properties.radiance.states[0].shades[0]
    assert new_shd.geometry[-1].x == pytest.approx(1, rel=1e-3)
    assert new_shd.geometry[-1].y == pytest.approx(1, rel=1e-3)
    assert new_shd.geometry[-1].z == pytest.approx(2, rel=1e-3)
    assert new_shd.geometry[1].x == pytest.approx(0, rel=1e-3)
    assert new_shd.geometry[1].y == pytest.approx(2, rel=1e-3)
    assert new_shd.geometry[1].z == pytest.approx(2, rel=1e-3)
예제 #4
0
def shade_state_abridged_tree_foliage(directory):
    shd1 = StateGeometry.from_vertices(
        'tree_foliage1', [[0, 0, 5], [2, 0, 5], [2, 2, 5], [0, 2, 5]])
    shd2 = StateGeometry.from_vertices(
        'tree_foliage2', [[0, 0, 5], [-2, 0, 5], [-2, 2, 5], [0, 2, 5]])
    trans1 = Glass.from_single_transmittance('TreeTrans1', 0.5)
    trans2 = Glass.from_single_transmittance('TreeTrans2', 0.27)
    shd1.modifier = trans1
    shd2.modifier = trans2
    tr4 = RadianceShadeState(shades=[shd1, shd2])

    dest_file = os.path.join(directory, 'shade_state_abridged_tree_foliage.json')
    with open(dest_file, 'w') as fp:
        json.dump(tr4.to_dict(abridged=True), fp, indent=4)
예제 #5
0
def move_state_shades():
    """Check to be sure that dynamic shades are moved with their parent."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0,
                                                       3), Point3D(1, 0, 0))
    ap = Shade('TestShade', Face3D(pts))
    pts_1 = (Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 2,
                                                         0), Point3D(0, 2, 0))
    shade = StateGeometry('RectangleShade', Face3D(pts_1))

    tint1 = RadianceShadeState(shades=[shade])
    ap.properties.radiance.dynamic_group_identifier = 'DeciduousTrees'
    ap.properties.radiance.states = [tint1]
    tint1.gen_geos_from_tmtx_thickness(0.05)

    vec_1 = Vector3D(2, 2, 2)
    new_ap = ap.duplicate()
    new_ap.move(vec_1)
    new_shd = new_ap.properties.radiance.states[0].shades[0]
    assert new_shd.geometry[0] == Point3D(2, 2, 2)
    assert new_shd.geometry[1] == Point3D(4, 2, 2)
    assert new_shd.geometry[2] == Point3D(4, 4, 2)
    assert new_shd.geometry[3] == Point3D(2, 4, 2)
예제 #6
0
def scale_state_shades():
    """Check to be sure that dynamic shades are scaled with their parent."""
    pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2,
                                                       2), Point3D(1, 2, 2))
    ap = Shade('TestShade', Face3D(pts))
    pts_1 = (Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 2,
                                                         0), Point3D(0, 2, 0))
    shade = StateGeometry('RectangleShade', Face3D(pts_1))

    tint1 = RadianceShadeState(shades=[shade])
    ap.properties.radiance.dynamic_group_identifier = 'DeciduousTrees'
    ap.properties.radiance.states = [tint1]
    tint1.gen_geo_from_vmtx_offset(0.05)
    tint1.gen_geo_from_dmtx_offset(0.1)

    new_ap = ap.duplicate()
    new_ap.scale(2)
    new_shd = new_ap.properties.radiance.states[0].shades[0]
    assert new_shd.geometry[0] == Point3D(2, 2, 4)
    assert new_shd.geometry[1] == Point3D(4, 2, 4)
    assert new_shd.geometry[2] == Point3D(4, 4, 4)
    assert new_shd.geometry[3] == Point3D(2, 4, 4)
예제 #7
0
def test_set_states():
    """Test the setting of states on a Shade."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0,
                                                       3), Point3D(1, 0, 0))
    shd = Shade('TreeTrunk', Face3D(pts))
    shd1 = StateGeometry.from_vertices(
        'tree_foliage1', [[0, 0, 5], [2, 0, 5], [2, 2, 5], [0, 2, 5]])
    shd2 = StateGeometry.from_vertices(
        'tree_foliage2', [[0, 0, 5], [-2, 0, 5], [-2, 2, 5], [0, 2, 5]])

    trans1 = Glass.from_single_transmittance('TreeTrans1', 0.5)
    trans2 = Glass.from_single_transmittance('TreeTrans2', 0.27)
    trans3 = Glass.from_single_transmittance('TreeTrans3', 0.14)
    trans4 = Glass.from_single_transmittance('TreeTrans4', 0.01)

    tr1 = RadianceShadeState(trans1)
    tr2 = RadianceShadeState(trans2)
    tr3 = RadianceShadeState(trans3)
    tr4 = RadianceShadeState(trans4)
    states = (tr1, tr2, tr3, tr4)

    tr3.add_shade(shd1)
    with pytest.raises(AssertionError):
        tr4.add_shades([shd1, shd2])
    tr4.add_shades([shd1.duplicate(), shd2])

    with pytest.raises(AssertionError):
        shd.properties.radiance.states = states
    shd.properties.radiance.dynamic_group_identifier = 'DeciduousTrees'
    shd.properties.radiance.states = states

    for state in shd.properties.radiance.states:
        assert state.parent.identifier == 'TreeTrunk'

    new_shd = shd.duplicate()

    assert shd.properties.radiance.dynamic_group_identifier == \
        new_shd.properties.radiance.dynamic_group_identifier == 'DeciduousTrees'
    assert len(new_shd.properties.radiance.states) == 4
    for i, state in enumerate(new_shd.properties.radiance.states):
        assert state.modifier.identifier == 'TreeTrans{}'.format(i + 1)
    assert len(new_shd.properties.radiance.states[2].shades) == 1
    assert len(new_shd.properties.radiance.states[3].shades) == 2
예제 #8
0
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)
예제 #9
0
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)
    for shd in _shades:
        assert isinstance(shd, Shade), 'Expected Shade ' \
            'for dynamic shade group. Got {}.'.format(type(shd))
        group_shds.append(shd.duplicate())

    # set the name of the dynamic group
    name = clean_and_id_rad_string(_name_) if _name_ is not None else str(
        uuid.uuid4())
    for shd in group_shds:
        shd.properties.radiance.dynamic_group_identifier = name

    # assign any states if they are connected
    if len(states_) != 0:
        # convert the sub-face states to shade states
        shd_states = [
            RadianceShadeState(st.modifier, st.shades) for st in states_
        ]
        # assign states (including shades) to the first shade
        group_shds[0].properties.radiance.states = [
            state.duplicate() for state in shd_states
        ]

        # remove shades from following shades to ensure they aren't double-counted
        states_wo_shades = []
        for state in shd_states:
            new_state = state.duplicate()
            new_state.remove_shades()
            states_wo_shades.append(new_state)
        for shd in group_shds[1:]:
            shd.properties.radiance.states = \
                [state.duplicate() for state in states_wo_shades]