Esempio n. 1
0
def test_patch_weights():
    """Test the various patch_weights methods."""
    horiz_weights = view_sphere.horizontal_radial_patch_weights(30, 2)
    assert len(horiz_weights) == 576
    assert sum(horiz_weights) / len(horiz_weights) == pytest.approx(1, rel=1e-3)

    dome_weights = view_sphere.dome_patch_weights()
    assert len(dome_weights) == 145
    assert sum(dome_weights) / len(dome_weights) == pytest.approx(1, rel=1e-3)

    sphere_weights = view_sphere.sphere_patch_weights()
    assert len(sphere_weights) == 290
    assert sum(sphere_weights) / len(sphere_weights) == pytest.approx(1, rel=1e-3)
Esempio n. 2
0
    # get the view vectors based on the view type
    patch_wghts = None
    if vt_str == 'Horizontal Radial':
        lb_vecs = view_sphere.horizontal_radial_vectors(30 * _resolution_)
    elif vt_str == 'Horizontal 30-Degree Offset':
        patch_mesh, lb_vecs = view_sphere.horizontal_radial_patches(
            30, _resolution_)
        patch_wghts = view_sphere.horizontal_radial_patch_weights(
            30, _resolution_)
    elif vt_str == 'Spherical':
        patch_mesh, lb_vecs = view_sphere.sphere_patches(_resolution_)
        patch_wghts = view_sphere.sphere_patch_weights(_resolution_)
    else:
        patch_mesh, lb_vecs = view_sphere.dome_patches(_resolution_)
        patch_wghts = view_sphere.dome_patch_weights(_resolution_)
    view_vecs = [from_vector3d(pt) for pt in lb_vecs]

    # mesh the geometry and context
    shade_mesh = join_geometry_to_mesh(_geometry + context_) if _geo_block_ \
        else join_geometry_to_mesh(context_)

    # intersect the rays with the mesh
    if vt_str == 'Sky View':  # account for the normals of the surface
        normals = [from_vector3d(vec) for vec in study_mesh.face_normals]
        int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                                 points,
                                                 view_vecs,
                                                 normals,
                                                 parallel=parallel_)
    else:
            if sun.is_during_day:
                sun_vecs.append(from_vector3d(sun.sun_vector_reversed))

        # intersect the sun vectors with the context and compute fraction exposed
        sun_int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                                     human_points,
                                                     sun_vecs,
                                                     cpu_count=workers)
        fract_body_exp = []
        for i in range(0, len(human_points), _pt_count_):
            fract_body_exp.append(
                fract_exposed_from_mtx(sun_int_matrix[i:i + _pt_count_],
                                       day_pattern))

        # generate the vectors and weights for sky exposure
        sky_vecs = [
            from_vector3d(vec) for vec in view_sphere.tregenza_dome_vectors
        ]
        patch_wghts = view_sphere.dome_patch_weights(1)

        # compute the sky exposure
        sky_int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                                     human_points,
                                                     sky_vecs,
                                                     cpu_count=workers)
        sky_exposure = []
        for i in range(0, len(human_points), _pt_count_):
            sky_exposure.append(
                sky_exposure_from_mtx(sky_int_matrix[i:i + _pt_count_],
                                      patch_wghts))