Exemplo n.º 1
0
        stroke_length_csv = np.max(short_pos_csv)-np.min(short_pos_csv)


        v_hdf5 = [x / 6.2 * 5.3 for x in v_hdf5]
        commanded_vel_csv = [x / 6.2 * 5.3 for x in commanded_vel_csv]
        pos_csv = [x / 6.2 * 5.3 for x in pos_csv]
        y_pos_hdf5 = [x / 6.2 * 5.3 for x in y_pos_hdf5]
        #v_hdf5 = np.roll(v_hdf5, int(len(v_hdf5)*0.236))
        #time_csv = [x + 0.207 for x in time_csv]
        vel_csv = [x / 6.2 * 5.3 for x in vel_csv]
        #vel_csv = np.roll(vel_csv, int(len(vel_csv) * 0.237))
        # Position Plot
        fig1, ax1 = graph.plot(time_csv, commanded_pos_csv, label='Commanded position (software outputs)', fignum=1, subplot=211, figsize=(12, 8))
        fig1, ax1 = graph.plot(time_csv, pos_csv, label='Actual position (software outputs)', fignum=1, subplot=211, figsize=(12, 8))
        #fig1, ax1 = graph.plot(time_hdf5, y_pos_hdf5, label='Actual position (tracking result)', fignum=1, subplot=211, figsize=(12, 8))
        fig1, ax1, color_patch1 = graph.errorfill(time_hdf5, y_pos_hdf5, fx, label='Actual position (tracking result)', fignum=1, subplot=211,
                               figsize=(12, 8), color='C2')

        # Velocity Plot
        fig1, ax2 = graph.plot(time_csv, commanded_vel_csv, label='Commanded velocity (software outputs)', fignum=1, subplot=212,
                               figsize=(12, 8))
        fig1, ax2 = graph.plot(time_csv, vel_csv, label='Actual velocity (software outputs)', fignum=1, subplot=212, figsize=(12, 8))
        fig1, ax2 = graph.plot(time_hdf5, v_hdf5, label='Actual velocity (tracking result)', fignum=1, subplot=212, figsize=(12, 8))
        graph.setaxes(ax1, tmin, tmax, -0.2, span * 1.3)
        graph.setaxes(ax2, tmin, tmax, -480, 150)
        graph.legend(ax1, loc=1)
        graph.legend(ax2, loc=4)
        graph.addtext(ax1, 'Actual stroke length(tracking code): %.2f + %.2f mm' % (stroke_length_hdf5, 2*fx), option='bl', fontsize=10)
        graph.addtext(ax1, 'Actual stroke length(software): %.2f mm' % stroke_length_csv, option='bl2', fontsize=10)
        graph.labelaxes(ax1,'Time [s]', 'Position y [mm]')
        graph.labelaxes(ax2, 'Time [s]', 'Velocity [mm/s]')
        graph.suptitle(data_tracking_dir_tail)
for ind in range(4):
    fit_data = zip(iw_all[ind], deltat_all[ind], gamma_all[ind], chi_all[ind],
                   fit_err_all[ind], r2s[ind])
    for iw in iws:
        fit_data_W = search_tuple(fit_data, 'W%d' % iw)
        iw_list, deltat_list, gamma_list, chi_list, fit_err_test, r2_list = zip(
            *fit_data_W)
        if iw > 16:
            indices = [rr > 0.9 for rr in r2_list]
            indices = [True, True, True, True, True, True, False, False, False]
        else:
            indices = [rr > 0.0 for rr in r2_list]
        fig_temp1, ax_temp1, cp = graph.errorfill(
            np.array(deltat_list)[indices] * dt_sim * dt_spacing / tau,
            np.abs(np.array(gamma_list)[indices]),
            yerr=np.array(fit_err_test)[indices][:, 1],
            fignum=5 + ind,
            subplot=121,
            label=r'$W=%d$ px' % iw,
            lw=lw)
        fig_temp1, ax_temp2, cp = graph.errorfill(
            np.array(deltat_list)[indices] * dt_sim * dt_spacing / tau,
            np.array(chi_list)[indices],
            yerr=np.array(fit_err_test)[indices][:, 0],
            fignum=5 + ind,
            subplot=122,
            label=r'$W=%d$ px' % iw,
            lw=lw,
            figsize=(16, 8))
    ax_temp1.legend()
    ax_temp1_2 = ax_temp1.twiny()
    ax_temp1.set_xlim(0, 1)
Exemplo n.º 3
0
            # Shift the data array for plotting sake
            y_pos_chunk = np.roll(y_pos_chunk,
                                  int(len(y_pos_chunk) * args.shiftper))
            y_pos_2d.append(y_pos_chunk)  #<- this is a list of lists

        y_pos_2d = np.concatenate(np.transpose(y_pos_2d)).ravel().reshape(
            len(y_pos_chunk), numcycles)  #<- Now, this is 2d array.

        # Calculate average and std for position
        y_pos_mean = np.nanmean(y_pos_2d, axis=1)
        y_pos_std = np.nanstd(y_pos_2d, axis=1)

        # Plot y vs time
        fig4, ax5, color_patch5 = graph.errorfill(time_short,
                                                  y_pos_mean,
                                                  y_pos_std,
                                                  fignum=4,
                                                  subplot=211,
                                                  color='b')
        #        fig4, ax5, color_patch6 = graph.errorfill(time_short, y_pos, args.fx, fmt='x', fignum=4, color='C2', subplot=211)

        # Output actual stroke length and its error
        actual_span = np.max(y_pos_mean) - np.min(y_pos_mean)
        y_pos_std_at_max, y_pos_std_at_min = y_pos_std[np.argmax(
            y_pos_mean)], y_pos_std[np.argmin(y_pos_mean)]
        actual_span_err = np.sqrt(y_pos_std_at_max**2 +
                                  y_pos_std_at_min**2)  # propagation of error
        # Add text
        text = 'Average stroke length = %.2f $\pm$ %.2f mm' % (actual_span,
                                                               actual_span_err)
        graph.addtext(ax5, text=text, subplot=211, option='bl', fontsize=10)
        graph.labelaxes(ax5, 'Time [s]', 'Piston position [mm]')
graph.setaxes(ax9, -4, 4, -0.1, 2)
graph.labelaxes(ax9, r'$\Delta U_x(\vec{r}) / U_x(\vec{r}) $', 'Prob. density')
filename = 'pivlab_scaled_noise_ux_varying_density'
graph.save(resultdir + filename)

plt.figure(12)
ax12.legend(loc=1)
ax12.set_xlim(-4, 4)
graph.setaxes(ax12, -4, 4, -0.1, 2)
graph.labelaxes(ax12, r'$\Delta U_y(\vec{r}) / U_y(\vec{r}) $', 'Prob. density')
filename = 'pivlab_scaled_noise_uy_varying_density'
graph.save(resultdir + filename)


# Width of Lorentzian curve as a function of number of tracer particles
fig15, ax15, _ = graph.errorfill(ntps, gammas_ux, ux0_fit_errs[1], label='$U_x$',fignum=15)
fig15, ax15, _ = graph.errorfill(ntps, gammas_uy, uy0_fit_errs[1], label='$U_y$', fignum=15)
graph.labelaxes(ax15, r'No. of tracer particles in (%d px, %d px)' % (imsize[0], imsize[1]), '$\gamma$ (a.u.)')
graph.setaxes(ax15, 0, 11000, 0, 0.5)
ax15.legend(loc=1, fontsize=18)
filename = 'lorentzian_fit_gammas_scaled_noise'
graph.save(resultdir + filename)

plt.figure(16)
ax16.legend(loc=1)
graph.setaxes(ax16, -4, 4, -0.1, 3.5)
graph.labelaxes(ax16, r'$\Delta U_x $ (a.u.)', 'Prob. density')
filename = 'pivlab_noise_ux_varying_density'
graph.save(resultdir + filename)

plt.figure(17)