コード例 #1
0
def create_rhino_mesh(_graphic, _lb_mesh):
    """Copied from Ladybug 'IncidentRadiation' Component 
    
    Arguments:
        _graphic: (ladybug.graphic.GraphicContainer) The Laybug Graphic object
        _lb_mesh: (Ladybug Mesh) A single joined mesh of the entire scene
    Returns: (tuple)
        mesh: (_)
        legend: (_)
    """

    # Create all of the visual outputs

    _lb_mesh.colors = _graphic.value_colors
    mesh = from_mesh3d(_lb_mesh)
    legend = legend_objects(_graphic.legend)

    return mesh, legend
コード例 #2
0
                     for ival, ang in zip(int_vals, angles))
            weight_result = sum(r * w for r, w in zip(w_res, patch_wghts))
            results.append(weight_result * 100 / vec_count)
    else:
        if patch_wghts:
            for int_list in int_matrix:
                weight_result = sum(r * w
                                    for r, w in zip(int_list, patch_wghts))
                results.append(weight_result * 100 / vec_count)
        else:
            results = [
                sum(int_list) * 100 / vec_count for int_list in int_matrix
            ]

    # create the mesh and legend outputs
    graphic = GraphicContainer(results, study_mesh.min, study_mesh.max,
                               legend_par_)
    graphic.legend_parameters.title = '%'
    if legend_par_ is None or legend_par_.are_colors_default:
        graphic.legend_parameters.colors = Colorset.view_study()
    title_txt = vt_str if vt_str in ('Sky Exposure', 'Sky View') else \
        '{} View'.format(vt_str)
    title = text_objects(title_txt, graphic.lower_title_location,
                         graphic.legend_parameters.text_height * 1.5,
                         graphic.legend_parameters.font)

    # create all of the visual outputs
    study_mesh.colors = graphic.value_colors
    mesh = from_mesh3d(study_mesh)
    legend = legend_objects(graphic.legend)
コード例 #3
0
        windrose.show_freq = _show_freq_

        calm_text = ''
        if isinstance(speed_data.header.data_type, Speed):
            windrose.show_zeros = _show_calmrose_
            calm_text = '\nCalm for {}% of the time = {} hours.'.format(
                round(
                    windrose._zero_count / len(windrose.analysis_values) *
                    100.0, 2), windrose._zero_count)
        windrose.base_point = Point2D(center_pt_2d.x, center_pt_2d.y)

        # Make the mesh
        mesh = from_mesh2d(windrose.colored_mesh, _center_pt_.z)

        # Make the graphic outputs
        legend = legend_objects(windrose.legend)
        freq_per = windrose._frequency_hours / \
            len([b for a in windrose.histogram_data for b in a])
        freq_text = '\nEach closed polyline shows frequency of {}% = {} hours.'.format(
            round(freq_per * 100, 1), windrose._frequency_hours)
        title = text_objects(
            title_text(speed_data) + calm_text + freq_text,
            windrose.container.lower_title_location,
            windrose.legend_parameters.text_height,
            windrose.legend_parameters.font)
        compass = compass_objects(windrose.compass, _center_pt_.z, None)
        orient_line = [
            from_linesegment2d(seg, _center_pt_.z)
            for seg in windrose.orientation_lines
        ]
        freq_line = [from_polygon2d(poly) for poly in windrose.frequency_lines]
コード例 #4
0
        if legend_par_[1].min is not None:
            month_chart.set_minimum_by_index(legend_par_[1].min, 1)
        if legend_par_[1].max is not None:
            month_chart.set_maximum_by_index(legend_par_[1].max, 1)

    #  get the main pieces of geometry
    d_meshes = month_chart.data_meshes
    if d_meshes is not None:
        data_mesh = [from_mesh2d(msh, z_val_tol) for msh in d_meshes]
    d_lines = month_chart.data_polylines
    if d_lines is not None:
        data_lines = [from_polyline2d(lin, z_val_tol) for lin in d_lines]
    borders = [from_polyline2d(month_chart.chart_border, z_val)] + \
            [from_linesegment2d(line, z_val) for line in month_chart.y_axis_lines] + \
            [from_linesegment2d(line, z_val_tol) for line in month_chart.month_lines]
    legend = legend_objects(month_chart.legend)

    # process all of the text-related outputs
    title_txt = month_chart.title_text if global_title_ is None else global_title_
    txt_hgt = month_chart.legend_parameters.text_height
    font = month_chart.legend_parameters.font
    title = text_objects(title_txt, month_chart.lower_title_location, txt_hgt,
                         font)

    # process the first y axis
    y1_txt = month_chart.y_axis_title_text1 if len(
        y_axis_title_) == 0 else y_axis_title_[0]
    y_title = text_objects(y1_txt, month_chart.y_axis_title_location1, txt_hgt,
                           font)
    label1 = [
        text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_hgt, font,
コード例 #5
0
            center_pt_i = Point2D(center_pt.x + fac, center_pt.y)
            center_pt3d_i = Point3D(center_pt3d.x + fac, center_pt3d.y,
                                    center_pt3d.z)

            # create the ladybug compass object
            lb_compass = Compass(radius, center_pt_i, north_)

            # create a graphic container to generate colors and legends
            n_data = data.filter_by_moys(
                moys)  # filter data collection by sun-up hours
            graphic = GraphicContainer(n_data.values,
                                       lb_compass.min_point3d(z),
                                       lb_compass.max_point3d(z), lpar,
                                       n_data.header.data_type,
                                       n_data.header.unit)
            all_legends.append(legend_objects(graphic.legend))
            title.append(
                text_objects(title_text(n_data), graphic.lower_title_location,
                             graphic.legend_parameters.text_height,
                             graphic.legend_parameters.font))

            # create points, analemmas, daily arcs, and compass geometry
            sun_pts_init = draw_sun_positions(suns, radius, center_pt3d_i)
            analemma_i, daily_i = draw_analemma_and_arcs(
                sp, datetimes, radius, center_pt3d_i)
            compass_i = compass_objects(lb_compass, z, None, projection_,
                                        graphic.legend_parameters.font)
            all_analemma.append(analemma_i)
            all_daily.append(daily_i)
            all_compass.append(compass_i)
コード例 #6
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
コード例 #7
0
        else:
            title_items = ['Psychrometric Chart']
        title[j + j * len(data_)].append(
            text_objects('\n'.join(title_items),
                         psy_chart.container.upper_title_location,
                         psy_chart.legend_parameters.text_height * 1.5,
                         psy_chart.legend_parameters.font, 0, 0))
        psych_chart.append(psy_chart)

        # plot the data on the chart
        lb_points = psy_chart.data_points
        points.append([from_point2d(pt) for pt in lb_points])
        if len(lb_points) != 1:  # hide the points and just display the mesh
            hide_output(ghenv.Component, 8)
            mesh.append(from_mesh2d(psy_chart.colored_mesh, z))
            legend.append(legend_objects(psy_chart.legend))
        else:  # show the single point on the chart
            show_output(ghenv.Component, 8)

        # process any of the connected data into a legend and colors
        if len(data_) != 0:
            data_colls.append(all_data[:-2])
            move_dist = x_dim * (psy_chart.max_temperature -
                                 psy_chart.min_temperature + 20)
            for i, d in enumerate(all_data[:-2]):
                # create a new psychrometric chart offset from the original
                new_pt = Point2D(base_pt.x + move_dist * (i + 1), base_pt.y)
                psy_chart = PsychrometricChart(all_data[-2],
                                               all_data[-1],
                                               pressure,
                                               leg_par_by_index(0),
コード例 #8
0
        try:  # sense when several legend parameters are connected
            lpar = legend_par_[i]
        except IndexError:
            lpar = None if len(legend_par_) == 0 else legend_par_[-1]

        # create the hourly plot object and get the main pieces of geometry
        hour_plot = HourlyPlot(data_coll, lpar, _base_pt_, _x_dim_, _y_dim_,
                               _z_dim_, reverse_y_)
        msh = from_mesh2d(hour_plot.colored_mesh2d, _base_pt_.z) if _z_dim_ == 0 else \
            from_mesh3d(hour_plot.colored_mesh3d)
        mesh.append(msh)
        border = [from_polyline2d(hour_plot.chart_border2d, _base_pt_.z)] + \
            [from_linesegment2d(line, _base_pt_.z) for line in hour_plot.hour_lines2d] + \
            [from_linesegment2d(line, _base_pt_.z) for line in hour_plot.month_lines2d]
        all_borders.append(border)
        legnd = legend_objects(hour_plot.legend)
        all_legends.append(legnd)
        tit_txt = text_objects(hour_plot.title_text,
                               hour_plot.lower_title_location,
                               hour_plot.legend_parameters.text_height,
                               hour_plot.legend_parameters.font)
        title.append(tit_txt)

        # create the text label objects
        label1 = [
            text_objects(txt, Plane(o=Point3D(pt.x, pt.y, _base_pt_.z)),
                         hour_plot.legend_parameters.text_height,
                         hour_plot.legend_parameters.font, 2, 3) for txt, pt in
            zip(hour_plot.hour_labels, hour_plot.hour_label_points2d)
        ]
        label2 = [
コード例 #9
0
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.togeometry import to_plane
    from ladybug_rhino.fromobjects import legend_objects
    from ladybug_rhino.color import color_to_color
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
    # set default values
    legend_par_ = legend_par_.duplicate() if legend_par_ is not None else \
        LegendParameters()
    if _base_plane_:
        legend_par_.base_plane = to_plane(_base_plane_)
    legend_par_.title = title_

    # create the legend
    legend = Legend(_values, legend_par_)

    # separate all of the outputs from this component
    rhino_objs = legend_objects(legend)
    mesh = rhino_objs[0]
    title_obj = rhino_objs[1]
    label_objs = rhino_objs[2:]
    label_text = legend.segment_text
    colors = [color_to_color(col) for col in legend.value_colors]