def plot_circles(ax, circles, configuration):
    from matplotlib.patches import Circle
    for (center, radius) in circles:
        circle = Circle(center, radius)
        circle.fill = False
        ax.add_artist(circle)

    ax.set_xlim(0, configuration.width * configuration.mmPerPixel)
    ax.set_ylim(0, configuration.height * configuration.mmPerPixel)
    ax.set_title('Circles')
    ax.set_aspect(1.0)
Пример #2
0
def plotPackedBeam2(coordinates,
                    angle,
                    axis1,
                    axis2,
                    boresight,
                    equaltorial_range,
                    pixel_range,
                    tiling_meta,
                    fileName='pack.png',
                    scope=1.,
                    show_axis=True,
                    extra_coordinates=[],
                    extra_coordinates_text=[],
                    subGroup=[],
                    transparency=1.,
                    edge=True,
                    index=False,
                    HD=True,
                    raw=False):
    #angle = 180 - angle
    # print("tiling angle: %.2f" % angle)
    # angle = angle - 90
    thisDpi = 96
    matplotlib.rcParams.update({'font.size': 8})
    plt.clf()
    if HD == True:
        fig = plt.figure(figsize=(1600. / thisDpi, 1600. / thisDpi),
                         dpi=thisDpi)
    else:
        fig = plt.figure(figsize=(400. / thisDpi, 400. / thisDpi), dpi=thisDpi)
    # plt.axes().set_aspect('equal', 'datalim')
    axis = fig.add_subplot(111, aspect='equal')
    center = coordinates[0]
    for idx in range(len(coordinates)):
        coord = coordinates[idx]
        ellipse = Ellipse(xy=coord,
                          width=2 * axis1,
                          height=2 * axis2,
                          angle=angle,
                          alpha=transparency)
        ellipse.fill = False
        axis.add_artist(ellipse)
        if index == True:
            axis.text(coord[0],
                      coord[1],
                      idx,
                      size=6,
                      ha='center',
                      va='center')

    for group in subGroup:
        subCoordinates, subAngle, subAxis1, subAxis2 = group
        for idx in range(len(subCoordinates)):
            coord = subCoordinates[idx]
            ellipse = Ellipse(xy=coord,
                              width=2 * subAxis1,
                              height=2 * subAxis2,
                              angle=subAngle,
                              alpha=transparency)
            ellipse.fill = False
            axis.add_artist(ellipse)

    for idx in range(len(extra_coordinates)):
        coord = extra_coordinates[idx]
        circle = Circle(xy=coord, radius=0.0006)
        axis.add_artist(circle)
        if extra_coordinates_text != []:
            axis.text(coord[0],
                      coord[1],
                      extra_coordinates_text[idx],
                      size=5,
                      ha='center',
                      va='center')

    gridCenter = [0, 0]
    tilingScale = tiling_meta["scale"]
    if edge == True:
        shape = tiling_meta["shape"]
        if shape == "circle":
            edge = Circle(xy=gridCenter,
                          radius=tilingScale,
                          alpha=0.1,
                          linewidth=3)
        elif shape == "ellipse":
            a, b, angle = tiling_meta["parameter"]
            edge = Ellipse(xy=gridCenter,
                           width=2 * a,
                           height=2 * b,
                           angle=angle,
                           alpha=0.1,
                           linewidth=3)
        elif shape == "hexagon":
            angle = tiling_meta["parameter"][1]
            edge = RegularPolygon(xy=gridCenter,
                                  numVertices=6,
                                  radius=tilingScale,
                                  orientation=angle,
                                  alpha=0.1,
                                  linewidth=3)
        elif shape == "polygon":
            vertices = tiling_meta["parameter"]
            edge = Polygon(xy=vertices, closed=True, alpha=0.1, linewidth=3)

        if shape == "annulus":
            for annulus in tiling_meta["parameter"]:
                annulus_type = annulus[0]
                if annulus_type == "polygon":
                    vertices = annulus[1]
                    edge = Polygon(xy=vertices,
                                   closed=True,
                                   alpha=0.1,
                                   linewidth=3)
                elif annulus_type == "ellipse":
                    a, b, angle = annulus[1]
                    edge = Ellipse(xy=gridCenter,
                                   width=2 * a,
                                   height=2 * b,
                                   angle=angle,
                                   alpha=0.1,
                                   linewidth=3)
                edge.fill = False
                axis.add_artist(edge)
        else:
            edge.fill = False
            axis.add_artist(edge)

    margin = tilingScale * 1.3 * scope
    axis.set_xlim(gridCenter[0] - margin, gridCenter[0] + margin)
    axis.set_ylim(gridCenter[1] - margin, gridCenter[1] + margin)
    beamNum = len(coordinates)

    if show_axis != True:
        plt.xticks([])
        plt.yticks([])
    else:
        xTicks = FixedLocator([pixel_range[0], 0, pixel_range[1]])
        xTicksLabel = FixedFormatter([
            "{:.2f}".format(equaltorial_range[0]),
            "{:.2f}".format(boresight[0]),
            "{:.2f}".format(equaltorial_range[1])
        ])
        axis.xaxis.set_major_locator(xTicks)
        axis.xaxis.set_major_formatter(xTicksLabel)
        axis.xaxis.set_tick_params(tickdir="out", tick2On=False)
        axis.set_xlabel("RA", size=20)
        plt.xticks(axis.get_xticks(), visible=True, size=20)

        yTicks = FixedLocator([pixel_range[2], 0, pixel_range[3]])
        yTicksLabel = FixedFormatter([
            "{:.2f}".format(equaltorial_range[2]),
            "{:.2f}".format(boresight[1]),
            "{:.2f}".format(equaltorial_range[3])
        ])
        axis.yaxis.set_major_locator(yTicks)
        axis.yaxis.set_major_formatter(yTicksLabel)
        axis.yaxis.set_tick_params(tickdir="out", tick2On=False)
        axis.set_ylabel("DEC", size=20)
        plt.yticks(axis.get_yticks(),
                   visible=True,
                   rotation="vertical",
                   size=20)

    fig.tight_layout()

    plt.savefig(fileName, dpi=thisDpi)

    plt.close()
Пример #3
0
def plot(B):
    plt.style.use("classic")
    fig, ax = plt.subplots()
    ax.grid()
    plt.subplots_adjust(bottom=0.3)
    plt.title("Bezier Curve")
    plt.xlabel("X [position]")
    plt.ylabel("Y [Position]")
    ax.set_aspect("equal")
    
    bezier_main_path, = plt.plot([], [], color ='black', linestyle="dashed")
    points, = plt.plot([], [], color='gray', marker='x', linestyle="dashed")
    left_trajectory, = plt.plot([], [], color="red")
    right_trajectory, = plt.plot([], [], color="red")
    curvature_circle = Circle((0,0), 0)
    curvature_circle.fill = False
    curvature_circle.set_visible(False)
    ax.add_artist(curvature_circle)

    B.load_control_points_from_file("control_points.txt")
    waypoints = B.get_points()
    x_points = [point[0] for point in waypoints]
    y_points = [point[1] for point in waypoints]

    points.set_data(x_points, y_points)

    ax.set_xlim(min(x_points)-1, max(x_points)+1)
    ax.set_ylim(min(y_points)-1, max(y_points)+1)
    ax.set_aspect("equal")

    def hide_curvature(label):
        curvature_circle.set_visible(not curvature_circle.get_visible())
        plt.draw()

    def update(t):
        B.load_control_points_from_file("control_points.txt")
        waypoints = B.get_points()
        x_points = [point[0] for point in waypoints]
        y_points = [point[1] for point in waypoints]

        points.set_data(x_points, y_points)
        
        ax.set_xlim(min(x_points)-1, max(x_points)+1)
        ax.set_ylim(min(y_points)-1, max(y_points)+1)
        ax.set_aspect("equal")
       
        if (t != 0):
            set_size = B.get_t().size
            bezier_main_path.set_data(B.x[:int(t*set_size-1)], B.y[:int(t*set_size-1)])

            trajectory_points = B.get_normal_points()[:int(t*set_size-1)]
            trajectory_x_points = [point[0] for point in trajectory_points]
            trajectory_y_points = [point[1] for point in trajectory_points]
            
            left_trajectory_x_points = [B.x[i] + (trackwidth/2)*trajectory_x_points[i] for i in range(len(trajectory_x_points))]
            left_trajectory_y_points = [B.y[i] + (trackwidth/2)*trajectory_y_points[i] for i in range(len(trajectory_y_points))]
            left_trajectory.set_data(left_trajectory_x_points, left_trajectory_y_points)

            right_trajectory_x_points = [B.x[i] - (trackwidth/2)*trajectory_x_points[i] for i in range(len(trajectory_x_points))]
            right_trajectory_y_points = [B.y[i] - (trackwidth/2)*trajectory_y_points[i] for i in range(len(trajectory_y_points))]
            right_trajectory.set_data(right_trajectory_x_points, right_trajectory_y_points)

            if B.get_curvature_at_t(t):
                radius = 1/(B.get_curvature_at_t(t))
            else:
                radius = 0
            
            if trajectory_x_points:
                curvature_center_x = B.x[int(t*set_size-1)] + trajectory_x_points[-1]*radius
                curvature_center_y = B.y[int(t*set_size-1)] + trajectory_y_points[-1]*radius
                curvature_circle.center = curvature_center_x, curvature_center_y
                curvature_circle.radius = radius
            else:
                curvature_circle.center = 0, 0
                curvature_circle.radius = 0
            
            B.get_headings()

            fig.canvas.update()
        else:
            bezier_main_path.set_data([], [])
            left_trajectory.set_data([], [])
            right_trajectory.set_data([], [])
            curvature_circle.center = 0, 0
            curvature_circle.radius = 0
            ax.add_artist(curvature_circle)

    t_slider = plt.axes([0.25, 0.15, 0.50, 0.02])
    time_slider = Slider(t_slider, "t", 0, 1, 0)
    time_slider.on_changed(update)

    button_ax = plt.axes([0.45, 0.04, 0.1, 0.1])
    labels = ["Curvature"]
    button = CheckButtons(button_ax, labels)
    button.on_clicked(hide_curvature)

    plt.show()
Пример #4
0
def plotPackedBeam(coordinates,
                   angle,
                   axis1,
                   axis2,
                   boresight,
                   tiling_meta,
                   fileName='pack.png',
                   scope=1.,
                   show_axis=True,
                   extra_coordinates=[],
                   extra_coordinates_text=[],
                   subGroup=[],
                   transparency=1.,
                   edge=True,
                   index=False,
                   HD=True,
                   raw=False):

    step = 1 / 10000000000.
    wcs_properties = wcs.WCS(naxis=2)
    wcs_properties.wcs.crpix = [0, 0]
    wcs_properties.wcs.cdelt = [-step, step]
    wcs_properties.wcs.crval = boresight
    wcs_properties.wcs.ctype = ["RA---TAN", "DEC--TAN"]

    center = boresight
    resolution = step

    thisDpi = 96
    matplotlib.rcParams.update({'font.size': 8})
    plt.clf()
    if HD == True:
        fig = plt.figure(figsize=(1600. / thisDpi, 1600. / thisDpi),
                         dpi=thisDpi)
    else:
        fig = plt.figure(figsize=(400. / thisDpi, 400. / thisDpi), dpi=thisDpi)
    axis = fig.add_subplot(111, aspect='equal', projection=wcs_properties)

    beam_coordinate = np.array(coordinates) / resolution
    # beam_coordinate += [center[0] - 1, 0]
    # beam_coordinate = [0, center[1] - 1] + [1, -1]*beam_coordinate

    for idx in range(len(beam_coordinate)):
        coord = beam_coordinate[idx]
        ellipse = Ellipse(xy=coord,
                          width=2. * axis1 / resolution,
                          height=2. * axis2 / resolution,
                          angle=angle,
                          alpha=transparency)
        ellipse.fill = False
        axis.add_artist(ellipse)
        if index == True:
            axis.text(coord[0],
                      coord[1],
                      idx,
                      size=6,
                      ha='center',
                      va='center')

    for group in subGroup:
        subCoordinates, subAngle, subAxis1, subAxis2 = group
        for idx in range(len(subCoordinates)):
            coord = subCoordinates[idx] / resolution
            ellipse = Ellipse(xy=coord,
                              width=2 * subAxis1 / resolution,
                              height=2 * subAxis2 / resolution,
                              angle=subAngle,
                              alpha=transparency)
            ellipse.fill = False
            axis.add_artist(ellipse)

    for idx in range(len(extra_coordinates)):
        coord = extra_coordinates[idx] / resolution
        circle = Circle(xy=coord, radius=0.0006)
        axis.add_artist(circle)
        if extra_coordinates_text != []:
            axis.text(coord[0],
                      coord[1],
                      extra_coordinates_text[idx],
                      size=5,
                      ha='center',
                      va='center')

    gridCenter = center
    tilingScale = tiling_meta["scale"]
    if edge == True:
        shape = tiling_meta["shape"]
        if shape == "circle":
            edge = Circle(xy=gridCenter,
                          radius=tilingScale / resolution,
                          alpha=0.1,
                          linewidth=3)
        elif shape == "ellipse":
            a, b, angle = tiling_meta["parameter"]
            edge = Ellipse(xy=gridCenter,
                           width=2 * a / resolution,
                           height=2 * b / resolution,
                           angle=angle,
                           alpha=0.1,
                           linewidth=3)
        elif shape == "hexagon":
            if tiling_meta["parameter"] is not None:
                angle = tiling_meta["parameter"][1]
            else:
                angle = 0
            edge = RegularPolygon(xy=gridCenter,
                                  numVertices=6,
                                  radius=tilingScale / resolution,
                                  orientation=np.deg2rad(60. - angle),
                                  alpha=0.1,
                                  linewidth=3)
        elif shape == "polygon":
            vertices = tiling_meta["parameter"]
            edge = Polygon(xy=np.array(vertices) / resolution,
                           closed=True,
                           alpha=0.1,
                           linewidth=3)

        if shape == "annulus":
            for annulus in tiling_meta["parameter"]:
                annulus_type = annulus[0]
                if annulus_type == "polygon":
                    vertices = annulus[1]
                    edge = Polygon(xy=np.array(vertices) / resolution,
                                   closed=True,
                                   alpha=0.1,
                                   linewidth=3)
                elif annulus_type == "ellipse":
                    a, b, angle = annulus[1]
                    edge = Ellipse(xy=gridCenter,
                                   width=2 * a / resolution,
                                   height=2 * b / resolution,
                                   angle=angle,
                                   alpha=0.1,
                                   linewidth=3)
                edge.fill = False
                axis.add_artist(edge)
        else:
            edge.fill = False
            axis.add_artist(edge)

    margin = tilingScale / step * 1.3 * scope
    axis.set_xlim(gridCenter[0] - margin, gridCenter[0] + margin)
    axis.set_ylim(gridCenter[1] - margin, gridCenter[1] + margin)

    fig.tight_layout()

    if show_axis != True:
        plt.xticks([])
        plt.yticks([])
    else:
        ra = axis.coords[0]
        dec = axis.coords[1]
        ra.set_ticklabel(size=20)
        dec.set_ticklabel(size=20, rotation="vertical")
        dec.set_ticks_position('l')
        ra.set_major_formatter('hh:mm:ss')
        ra.set_ticks_position('b')
        ra.set_axislabel("RA", size=20)
        dec.set_major_formatter('dd:mm:ss')
        dec.set_axislabel("DEC", size=20)
        plt.subplots_adjust(left=0.04,
                            bottom=0.05,
                            right=0.98,
                            top=0.96,
                            wspace=0,
                            hspace=0)

    plt.savefig(fileName, dpi=thisDpi)

    plt.close()