Пример #1
0
def show_plot(data, args, image):
    min_corner = args['c'][:2]
    max_corner = args['c'][2:4]
    max_corner = data.shape[:2][0] - max_corner[0], data.shape[:2][
        1] - max_corner[1]
    x_min, y_min = min_corner
    x_max, y_max = max_corner
    matrix = np.zeros((data.shape[:2]) + (1, ))
    matrix[:, :, 0] = image[0:data.shape[:2][0], 0:data.shape[:2][1]]
    max_corner = x_max - 1, y_max - 1

    amplitudes_x_fig = plt.figure('Amplitudes X')
    plt.title('Amplitudes X')
    Plot.scalar_heat_map(matrix,
                         min_corner,
                         max_corner,
                         0,
                         data[x_min:x_max, y_min:y_max, 0],
                         alpha=0.3)

    amplitudes_y_fig = plt.figure('Amplitudes Y')
    plt.title('Amplitudes Y')
    Plot.scalar_heat_map(matrix,
                         min_corner,
                         max_corner,
                         0,
                         data[x_min:x_max, y_min:y_max, 1],
                         alpha=0.3)

    phases_x_fig = plt.figure('Phases X')
    plt.title('Phases X')
    Plot.phase_heat_map(matrix,
                        min_corner,
                        max_corner,
                        0,
                        data[x_min:x_max, y_min:y_max, 2],
                        alpha=0.3)

    phases_y_fig = plt.figure('Phases Y')
    plt.title('Phases Y')
    Plot.phase_heat_map(matrix,
                        min_corner,
                        max_corner,
                        0,
                        data[x_min:x_max, y_min:y_max, 3],
                        alpha=0.3)

    plt.show()
Пример #2
0
def plot_data(args):
    root = args["root"]
    video = args["video"]
    data = args["data"]
    min_corner = args["min_corner"]
    max_corner = args["max_corner"]
    thr_x, thr_y = args["t"]

    arrows_plot = args["a"]
    save_plots = args["s"]
    show_plots = args["p"]
    wave = args["w"] is not None
    arrows_8 = args["a8"]

    cumulative_displacements = args["cumulative_displacements"]

    amplitudes_x = np.array(data[:, :, 0])
    amplitudes_y = np.array(data[:, :, 1])
    phases_x = np.array(data[:, :, 2])
    phases_y = np.array(data[:, :, 3])

    phases_x[amplitudes_x < thr_x] = float('nan')
    amplitudes_x[amplitudes_x < thr_x] = float('nan')

    phases_y[amplitudes_y < thr_y] = float('nan')
    amplitudes_y[amplitudes_y < thr_y] = float('nan')

    if arrows_plot:
        amplitudes = plt.figure()
        k, scale = args["a"]
        Plot.plot(video,
                  data[:, :, :2],
                  min_corner,
                  max_corner,
                  0,
                  k=int(k),
                  scale=1 / scale,
                  color='red')

    else:
        amplitudes_x_fig = plt.figure('Amplitudes X')
        plt.title('Amplitudes X')
        Plot.scalar_heat_map(video,
                             min_corner,
                             max_corner,
                             0,
                             amplitudes_x,
                             alpha=0.3)

        amplitudes_y_fig = plt.figure('Amplitudes Y')
        plt.title('Amplitudes Y')
        Plot.scalar_heat_map(video,
                             min_corner,
                             max_corner,
                             0,
                             amplitudes_y,
                             alpha=0.3)

        phases_x_fig = plt.figure('Phases X')
        plt.title('Phases X')
        Plot.phase_heat_map(video,
                            min_corner,
                            max_corner,
                            0,
                            phases_x,
                            alpha=0.3)

        phases_y_fig = plt.figure('Phases Y')
        plt.title('Phases Y')
        Plot.phase_heat_map(video,
                            min_corner,
                            max_corner,
                            0,
                            phases_y,
                            alpha=0.3)

    if wave:
        wave_data = args["wave_data"]
        frequency = args["frequency"]
        pixel_size = args["pixel_size"]
        wave_width, wave_height = wave_data.shape[:2]

        x = np.arange(wave_width)
        y = np.arange(wave_height)
        Ax = np.log(
            np.array(
                [np.average(wave_data[:, j, 0]) for j in range(wave_height)]))
        Ay = np.log(
            np.array(
                [np.average(wave_data[i, :, 1]) for i in range(wave_width)]))
        Px = np.unwrap(wave_data[wave_width // 2, :, 2])
        Py = np.unwrap(wave_data[:, wave_height // 2, 3])

        for (xi, yi, name, dimension) in [(x, Ay, "decay constant x", "1/nm"),
                                          (y, Ax, "decay constant y", "1/nm"),
                                          (x, Py, "wave speed x", "m/s"),
                                          (y, Px, "wave speed y", "m/s")]:
            plt.figure()
            plt.plot(xi, yi)
            a, b = np.polyfit(xi, yi, 1)
            plt.plot(xi, a * xi + b * np.ones((len(xi))))
            if dimension == "m/s":
                a = 2 * np.pi * frequency / (1e9 * a / pixel_size)
            else:
                a = a / pixel_size

            print(name + ": " + str(abs(a)) + " " + dimension)

    if save_plots:
        if arrows_plot:
            amplitudes.savefig(root + "amplitudes_vector_field.png")
        else:
            amplitudes_x_fig.savefig(root + "amplitudes_x" + ".png")
            amplitudes_y_fig.savefig(root + "amplitudes_y" + ".png")
            phases_x_fig.savefig(root + "phases_x" + ".png")
            phases_y_fig.savefig(root + "phases_y" + ".png")

        if arrows_8:
            k8, scale8 = arrows_8
            displacements = get_displacements_frame_to_frame(
                cumulative_displacements)
            for time in range(len(displacements)):
                optical_flow = plt.figure()
                Plot.plot(video,
                          displacements[time],
                          min_corner,
                          max_corner,
                          time,
                          k=int(k8),
                          scale=1 / scale8,
                          color="red")
                optical_flow.savefig(root + "displacements_vector_field_" +
                                     str(time) + ".png")
                plt.close(optical_flow)

    if show_plots:
        plt.show()