Пример #1
0
def draw_psych_chart(psy_chart):
    """Draw a given psychrometric chart object into Rhino geometry.

    This will NOT translate any colored meshes or data points.
    """
    # output all of the lines/polylines for the various axes
    title_i = [from_polyline2d(psy_chart.chart_border, z)]
    temp_lines_i = [
        from_linesegment2d(tl, z) for tl in psy_chart.temperature_lines
    ]
    rh_lines_i = [from_polyline2d(rhl, z) for rhl in psy_chart.rh_lines]
    hr_lines_i = [from_linesegment2d(hrl, z) for hrl in psy_chart.hr_lines]

    # add the text to the various lines
    title_i.append(
        text_objects(psy_chart.x_axis_text,
                     plane_from_point(psy_chart.x_axis_location),
                     psy_chart.legend_parameters.text_height * 1.5,
                     psy_chart.legend_parameters.font, 0, 0))
    title_i.append(
        text_objects(
            psy_chart.y_axis_text,
            plane_from_point(psy_chart.y_axis_location, Vector3D(0, 1)),
            psy_chart.legend_parameters.text_height * 1.5,
            psy_chart.legend_parameters.font, 2, 0))
    temp_lines_i = temp_lines_i + small_labels(
        psy_chart, psy_chart.temperature_labels,
        psy_chart.temperature_label_points, 1, 0)
    rh_lines_i = rh_lines_i + small_labels(psy_chart, psy_chart.rh_labels[:-1],
                                           psy_chart.rh_label_points[:-1], 2,
                                           3, 0.8)
    hr_lines_i = hr_lines_i + small_labels(psy_chart, psy_chart.hr_labels,
                                           psy_chart.hr_label_points, 0, 3)

    # add enthalpy or wet bulb lines
    if plot_wet_bulb_:
        enth_wb_lines_i = [
            from_linesegment2d(el, z) for el in psy_chart.wb_lines
        ]
        enth_wb_lines_i = enth_wb_lines_i + small_labels(
            psy_chart, psy_chart.wb_labels, psy_chart.wb_label_points, 2, 3)
    else:
        enth_wb_lines_i = [
            from_linesegment2d(el, z) for el in psy_chart.enthalpy_lines
        ]
        enth_wb_lines_i = enth_wb_lines_i + small_labels(
            psy_chart, psy_chart.enthalpy_labels,
            psy_chart.enthalpy_label_points, 2, 3)

    # add all of the objects to the bse list
    title.append(title_i)
    temp_lines.append(temp_lines_i)
    rh_lines.append(rh_lines_i)
    hr_lines.append(hr_lines_i)
    enth_wb_lines.append(enth_wb_lines_i)
def translate_compass(compass, z=0, font='Arial'):
    """Translate a Ladybug Compass object into Grasshopper geometry.

    Args:
        compass: A Ladybug Compass object to be converted to Rhino geometry.
        z: A number for the Z-coordinate to be used in translation. (Default: 0)
        font: Optional text for the font to be used in creating the text.
            (Default: 'Arial')

    Returns:
        A list of Rhino geometries in the following order.
        -   all_boundary_circles -- Three Circle objects for the compass boundary.
        -   major_azimuth_ticks -- Line objects for the major azimuth labels.
        -   major_azimuth_text -- Bake-able text objects for the major azimuth labels.
     """
    # set default variables based on the compass properties
    maj_txt = compass.radius / 2.5
    xaxis = Vector3D(1, 0, 0).rotate_xy(math.radians(compass.north_angle))
    result = []  # list to hold all of the returned objects

    # create the boundary circles
    for circle in compass.all_boundary_circles:
        result.append(from_arc2d(circle, z))

    # generate the labels and tick marks for the azimuths
    for line in compass.major_azimuth_ticks:
        result.append(from_linesegment2d(line, z))
    for txt, pt in zip(compass.MAJOR_TEXT, compass.major_azimuth_points):
        result.append(
            text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z), x=xaxis),
                         maj_txt, font, 1, 3))
    return result
Пример #3
0
        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]
        windrose_lines = [
            from_polygon2d(poly) for poly in windrose.windrose_lines
        ]
        fac = (i + 1) * windrose.compass_radius * 3
        center_pt_2d = Point2D(_center_pt_.x + fac, _center_pt_.y)

        # Add histogram
        hist_mtx = objectify_output('WindRose {}'.format(i),
                                    windrose.histogram_data)

        all_mesh.append(mesh)
        all_compass.append(compass)
        # Make the mesh
        msh = from_mesh2d(windrose.colored_mesh, _center_pt_.z)

        # Make the other 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)
        titl = 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, _center_pt_.z) for poly in windrose.frequency_lines]
        windrose_lines = [from_polygon2d(poly, _center_pt_.z) for poly in windrose.windrose_lines]
        fac = (i + 1) * windrose.compass_radius * 3
        center_pt_2d = Point2D(_center_pt_.x + fac, _center_pt_.y)

        # collect everything to be output
        mesh.append(msh)
        all_compass.append(compass)
        all_orient_line.append(orient_line)
        all_freq_line.append(freq_line)
        all_windrose_lines.append(windrose_lines)
        all_legends.append(legend)
        title.append(titl)
        calm = windrose.zero_count if isinstance(speed_data.header.data_type, Speed) else None
                               stack_, percentile_)
    if len(legend_par_) > 1:
        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)
Пример #6
0
    all_labels = []

    for i, data_coll in enumerate(_data):
        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
Пример #7
0
        if boundary.is_clockwise:
            boundary = boundary.reverse()
        holes, z_height = None, face[0].z
        if face.has_holes:
            holes = []
            for hole in face.holes:
                h_poly = Polygon2D.from_array([(pt.x, pt.y) for pt in hole])
                if not h_poly.is_clockwise:
                    h_poly = h_poly.reverse()
                holes.append(h_poly)
        boundaries.append(boundary)
        hole_polygons.append(holes)
        # compute the skeleton and convert to line segments
        skel_lines = skeleton_as_edge_list(boundary, holes, tolerance)
        skel_lines_rh = [
            from_linesegment2d(LineSegment2D.from_array(line), z_height)
            for line in skel_lines
        ]
        polyskel.append(skel_lines_rh)

    # try to compute core/perimeter polygons if an offset_ is input
    if offset_:
        perim_poly, core_poly = [], []
        for bound, holes in zip(boundaries, hole_polygons):
            try:
                perim, core = perimeter_core_subpolygons(
                    bound, offset_, holes, tolerance)
                perim_poly.append(
                    [polygon_to_brep(p, z_height) for p in perim])
                core_poly.append([polygon_to_brep(p, z_height) for p in core])
            except RuntimeError as e:
Пример #8
0
        if not all_to_bldg:  # exclude anything with a Building key
            geo_data = [
                geo for geo in geo_data if 'type' not in geo['properties']
                or geo['properties']['type'] != 'Building'
            ]

        # convert all of the geoJSON data into Rhino geometry
        other_geo = []
        for geo_dat in geo_data:
            if geo_dat['geometry']['type'] == 'LineString':
                coords = lon_lat_to_polygon(geo_dat['geometry']['coordinates'],
                                            origin_lon_lat, convert_facs)
                pts = tuple(Point2D.from_array(pt) for pt in coords)
                line = LineSegment2D.from_end_points(pts[0], pts[1]) \
                    if len(pts) == 2 else Polyline2D(pts)
                if con_fac != 1:
                    line = line.scale(con_fac, pt)
                if len(pts) == 2:
                    other_geo.append(from_linesegment2d(line))
                else:
                    other_geo.append(from_polyline2d(line))
            else:  # is's a polygon
                coords = lon_lat_to_polygon(
                    geo_dat['geometry']['coordinates'][0], origin_lon_lat,
                    convert_facs)
                pts = tuple(Point2D.from_array(pt) for pt in coords)
                poly = Polyline2D(pts)
                if con_fac != 1:
                    poly = poly.scale(con_fac, pt)
                other_geo.append(from_polyline2d(poly))