Пример #1
0
def draw_dome(dome_data, center, dome_name, legend_par):
    """Draw the dome mesh, compass, legend, and title for a sky dome.

    Args:
        dome_data: List of radiation values for the dome data
        center: Point3D for the center of the sun path.
        dome_name: Text for the dome name, which will appear in the title.
        legend_par: Legend parameters to be used for the dome

    Returns:
        dome_mesh: A colored mesh for the dome based on dome_data.
        dome_compass: A compass for the dome.
        dome_legend: A leend for the colored dome mesh.
        dome_title: A title for the dome.
        values: A list of radiation values that align with the dome_mesh faces.
    """
    # create the dome mesh and ensure patch values align with mesh faces
    if len(dome_data) == 145:  # tregenza sky
        lb_mesh = view_sphere.tregenza_dome_mesh_high_res.scale(radius)
        values = []  # high res dome has 3 x 3 faces per patch; we must convert
        tot_i = 0  # track the total number of patches converted
        for patch_i in view_sphere.TREGENZA_PATCHES_PER_ROW:
            row_vals = []
            for val in dome_data[tot_i:tot_i + patch_i]:
                row_vals.extend([val] * 3)
            for i in range(3):
                values.extend(row_vals)
            tot_i += patch_i
        values = values + [dome_data[-1]
                           ] * 18  # last patch has triangular faces
    else:  #reinhart sky
        lb_mesh = view_sphere.reinhart_dome_mesh.scale(radius)
        values = dome_data + [dome_data[-1]
                              ] * 11  # last patch has triangular faces

    # move and/or rotate the mesh as needed
    if north != 0:
        lb_mesh = lb_mesh.rotate_xy(math.radians(north), Point3D())
    if center != Point3D():
        lb_mesh = lb_mesh.move(Vector3D(center.x, center.y, center.z))

    # project the mesh if requested
    if projection_ is not None:
        if projection_.title() == 'Orthographic':
            pts = (Compass.point3d_to_orthographic(pt)
                   for pt in lb_mesh.vertices)
        elif projection_.title() == 'Stereographic':
            pts = (Compass.point3d_to_stereographic(pt, radius, center)
                   for pt in lb_mesh.vertices)
        else:
            raise ValueError(
                'Projection type "{}" is not recognized.'.format(projection_))
        pts3d = tuple(Point3D(pt.x, pt.y, z) for pt in pts)
        lb_mesh = Mesh3D(pts3d, lb_mesh.faces)

    # output the dome visualization, including legend and compass
    move_fac = radius * 0.15
    min_pt = lb_mesh.min.move(Vector3D(-move_fac, -move_fac, 0))
    max_pt = lb_mesh.max.move(Vector3D(move_fac, move_fac, 0))
    graphic = GraphicContainer(values, min_pt, max_pt, legend_par)
    graphic.legend_parameters.title = 'kWh/m2'
    lb_mesh.colors = graphic.value_colors
    dome_mesh = from_mesh3d(lb_mesh)
    dome_legend = legend_objects(graphic.legend)
    dome_compass = compass_objects(
        Compass(radius, Point2D(center.x, center.y), north), z, None,
        projection_, graphic.legend_parameters.font)

    # construct a title from the metadata
    st, end = metadata[2], metadata[3]
    time_str = '{} - {}'.format(st, end) if st != end else st
    title_txt = '{} Radiation\n{}\n{}'.format(
        dome_name, time_str, '\n'.join([dat for dat in metadata[4:]]))
    dome_title = text_objects(title_txt, graphic.lower_title_location,
                              graphic.legend_parameters.text_height,
                              graphic.legend_parameters.font)

    return dome_mesh, dome_compass, dome_legend, dome_title, values
    ori_dict = {'north': 0, 'east': 90, 'south': 180, 'west': 270}
    try:  # first check if it's text for the direction
        orientation_ = ori_dict[orientation_.lower()]
    except KeyError:  # it's a number for the orientation
        orientation_ = float(orientation_)
    direction = Vector3D(0, 1, 0).rotate_xy(-math.radians(orientation_))

# create the dome mesh of the sky and position/project it correctly
sky_mask, view_vecs = view_sphere.dome_radial_patches(az_count, alt_count)
sky_mask = sky_mask.scale(radius)
if center_pt3d != Point3D():
    m_vec = Vector3D(center_pt3d.x, center_pt3d.y, center_pt3d.z)
    sky_mask = sky_mask.move(m_vec)
if projection_ is not None:
    if projection_.title() == 'Orthographic':
        pts = (Compass.point3d_to_orthographic(pt) for pt in sky_mask.vertices)
    elif projection_.title() == 'Stereographic':
        pts = (Compass.point3d_to_stereographic(pt, radius, center_pt3d)
               for pt in sky_mask.vertices)
    else:
        raise ValueError(
            'Projection type "{}" is not recognized.'.format(projection_))
    pts3d = tuple(Point3D(pt.x, pt.y, center_pt3d.z) for pt in pts)
    sky_mask = Mesh3D(pts3d, sky_mask.faces)
sky_pattern = [True] * len(
    view_vecs)  # pattern to be adjusted by the various masks

# account for the orientation and any of the projection strategies
orient_pattern, strategy_pattern = None, None
if direction is not None:
    orient_pattern, dir_angles = view_sphere.orientation_pattern(