def draw_trajectory(data_dict, show=True): fig3, ax31 = graph.set_fig(fignum=3, subplot=111, figsize=(16, 10)) for domain_num in range(1, 5): # these are lists of core positions cxmax = data_dict["domain{0}".format(domain_num)]["cxmaxlist"] cymax = data_dict["domain{0}".format(domain_num)]["cymaxlist"] cxmin = data_dict["domain{0}".format(domain_num)]["cxminlist"] cymin = data_dict["domain{0}".format(domain_num)]["cyminlist"] core_positions = [[cxmax, cymax], [cxmin, cymin]] # For plot marker = ['v', '^', 's', 'o'] # makers corresponding to domains fillstyle = ['full', 'none'] # Positive core: fill, Negative core: no fill colors = graph.get_first_n_colors_from_color_cycle(4) for j, core_position in enumerate(core_positions): print core_position cx, cy = core_position[0], core_position[1] ax31.plot(cx, cy, color=colors[domain_num - 1], marker=marker[domain_num - 1], alpha=0.7, fillstyle=fillstyle[j]) graph.setaxes(ax31, 0, imsize[1] * scale, 0, imsize[0] * scale) graph.labelaxes(ax31, 'x [mm]', 'y [mm]') ax31.invert_yaxis() if show: graph.show()
#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) # Draw a line where the two data were aligned # graph.axvline(ax1, x=time_csv[vel_csv_right_ind], linestyle='--', color='k') # graph.axvline(ax2, x=time_csv[vel_csv_right_ind], linestyle='--', color='k') # Scatter plot where the two data (tracking code results and software outputs) were aligned # if v_hdf5_left_ind+shift_arg >= time_hdf5.shape[0]: # fig1, ax1 = graph.scatter([time_hdf5[v_hdf5_right_ind + shift_arg - time_hdf5.shape[0]]], [v_hdf5[v_hdf5_right_ind + shift_arg - time_hdf5.shape[0]]], fignum=1, subplot=212, # marker='x', color='C2', figsize=(12,8)) # else: # fig1, ax1 = graph.scatter(time_hdf5[v_hdf5_right_ind+shift_arg], v_hdf5[v_hdf5_right_ind+shift_arg], fignum=1, subplot=212, # marker='x', color='C2', figsize=(12,8)) # fig1, ax1 = graph.scatter(time_csv[vel_csv_right_ind], vel_csv[vel_csv_right_ind], fignum=1, subplot=212,
color='red', transform=ax.transAxes) savedir = resultsdir + '/time_evolution/' filename = 'No_vortex_ring_detected' graph.save(savedir + filename, ext='png', close=True) continue # Plot circulation, ring velocity, and diameter #fig8, ax8 = graph.scatter(trForGammar, gammar, fignum=2, subplot=131,figsize=(20, 5)) fig8, ax8 = graph.errorbar(trForGammar, gammar, yerr=gammar_err, fignum=2, subplot=131, figsize=(20, 5)) graph.labelaxes(ax8, 'Time ($s$)', 'Circulation ($mm^2/s$)') if gammar_avg * 1.3 > np.max(gammar): graph.setaxes(ax8, 0, time[-1], 0, gammar_avg * 1.3) else: graph.setaxes(ax8, 0, time[-1], 0, np.max(gammar)) text = 'Average $\Gamma$: %.1f' % gammar_avg + '$mm^2/s$' graph.addtext(ax8, x=(time[-1]) / 10., y=gammar_avg * 1.3 / 4. * 2, text=text) text = 'Std.: %.1f' % gammar_std + '$mm^2/s$' graph.addtext(ax8, x=(time[-1]) / 10., y=gammar_avg * 1.3 / 4., text=text)
subplot=121, figsize=(16, 8)) fig1, ax12, cc12 = graph.color_plot(xgrid, ygrid, vgrid, fignum=1, subplot=122, figsize=(16, 8)) fig2, ax2, cc2 = graph.color_plot(xgrid, ygrid, omega, fignum=2) # print np.nansum(omega), gamma / np.nansum(omega) graph.add_colorbar(cc11, ax=ax11, label=r'$U_x$ (px/frame)') graph.add_colorbar(cc12, ax=ax12, label=r'$U_y$ (px/frame)') graph.add_colorbar(cc2, ax=ax2, label=r'$\omega_z$ (1/frame)') graph.labelaxes(ax11, r'$X$', r'$Y$') graph.labelaxes(ax12, r'$X$', r'$Y$') graph.labelaxes(ax2, r'$X$', r'$Y$') fig1.tight_layout() fig2.tight_layout() fig3, ax31 = graph.pdf(ugrid, nbins=200, fignum=3, subplot=121, figsize=(16, 8)) fig3, ax32 = graph.pdf(vgrid, nbins=200, fignum=3, subplot=122, figsize=(16, 8))
lorentz_peaks_uy_err.append(np.sqrt(np.diag(pcov))[0]) gammas_uy_err.append(np.sqrt(np.diag(pcov))[1]) except: lorentz_peaks_uy.append(np.nan) gammas_uy.append(np.nan) lorentz_peaks_uy_err.append(np.nan) gammas_uy_err.append(np.nan) pass # Plotting stuff axes = [ax11, ax12] xlabels, ylabel = [r'$\Delta U_x$ (px/frame)', r'$\Delta U_y$ (px/frame)'], r'Probability density' title = r'W=%dpx, $v$=%.1f px/frame (PIVLab, Original, Diff.)' % (iw, mag) for ax, xlabel in zip(axes, xlabels): graph.labelaxes(ax, xlabel, ylabel) graph.setaxes(ax, -0.2, 0.2, 0, 80) ax.legend() graph.suptitle(title, fignum=1) # fig1.tight_layout() # Close hdf5 files pivdata.close() fdata.close() figname = '/noisedist/pivlab_fakedata_comp_W%d_v%spxframe_multiple_passes' % (iw, mag_str_2) graph.save(resultdir + figname) # plt.show() plt.close() break # elif args.mode == 'gradient':
# veff and vring veff_list_for_vring, vr_list2 = fa.sort_two_arrays_using_order_of_first_array( veff_list, vr_list) # veff and vring_err veff_list_for_vring, vr_err_list2 = fa.sort_two_arrays_using_order_of_first_array( veff_list, vr_err_list) # Circulation vs veff fig1, ax1 = graph.errorbar(veff_list_for_gammar, gammar_list1, yerr=gammar_err_list, fignum=1, label=label, fmt=fmt) graph.labelaxes( ax1, '|$\overline{v^2_p} / \overline{v_p} \alpha $| [mm/s]', '$\Gamma [mm^2/s]$ ') ax1.legend() graph.setaxes(ax1, 0, 300, 0, 15000) graph.save(base_dir + 'gamma_vs_Veff') # Stroke length fig2, ax2 = graph.plot(veff_list_for_actual_span, actual_span_ratio_list1, fignum=2, marker=fmt, label=label) graph.labelaxes(ax2, '|$\overline{v^2_p} / \overline{v_p}$| [mm/s]', '$L/ L_c[mm^2/s]$ ') ax2.legend()
for i in range(tdim): print '%d / %d' % (i+1, tdim) uz, uy, ux = fyle[vel_keys[i]][zpos, ..., 0], fyle[vel_keys[i]][zpos, ..., 1], fyle[vel_keys[i]][zpos, ..., 2] # unit length / unit time uz = uz / fx # px/unit time uy = uy / fx # px/unit time ux = ux / fx # px/unit time fig1, ax11, cc11 = graph.color_plot(x, y, ux, vmin=-vmax, vmax=vmax, cmap=cmap, subplot=131, figsize=(20, 6)) fig1, ax12, cc12 = graph.color_plot(x, y, uy, vmin=-vmax, vmax=vmax, cmap=cmap, subplot=132, figsize=(20, 6)) fig1, ax13, cc13 = graph.color_plot(x, y, uz, vmin=-vmax, vmax=vmax, cmap=cmap, subplot=133, figsize=(20, 6)) axes = [ax11, ax12, ax13] ccs = [cc11, cc12, cc13] clabels = ['$u_x$ (px/unit time)', '$u_y$ (px/unit time)', '$u_z$ (px/unit time)'] for ax, cc, clabel in zip(axes, ccs, clabels): graph.add_colorbar(cc, ax=ax, label=clabel) graph.labelaxes(ax, '$X$ (px)', '$Y$ (px)') graph.suptitle(r't= %.1f $ \tau_\eta$ = %.2f (unit time)' % (float(vel_keys[i][1:]) * dt / tau_eta, float(vel_keys[i][1:]) * dt), fignum=1) # fig2, ax2 = graph.pdf(ux, nbins=int(np.sqrt(ydim * xdim)), fignum=2, label='$u_x$ (px/unit time)') fig2, ax2 = graph.pdf(uy, nbins=int(np.sqrt(ydim * xdim)), fignum=2, label='$u_y$ (px/unit time)') fig2, ax2 = graph.pdf(uz, nbins=int(np.sqrt(ydim * xdim)), fignum=2, label='$u_z$ (px/unit time)') graph.setaxes(ax2, -vmax, vmax, -0.05/100., 0.006) graph.labelaxes(ax2, '$u_i$ (px/unit time)', 'Probability density') graph.suptitle(r't= %.1f $ \tau_\eta$ = %.2f (unit time)' % (float(vel_keys[i][1:]) * dt / tau_eta, float(vel_keys[i][1:]) * dt), fignum=2) ax2.legend() filename1 = 'vel_field_t' + vel_keys[i][1:] filename2 = 'pdf_vel_field_t' + vel_keys[i][1:] graph.save(resultdir + filename1, fignum=1, ext='png') graph.save(resultdir + filename2, fignum=2, ext='png')
x, y, z = x / data_spacing, y / data_spacing, z / data_spacing e = (ux**2 + uy**2) / 2. for i in range(x.shape[2]): print i, np.min(z[..., i]), np.max(z[..., i]), np.mean(z[..., i]) fig, ax, cc = graph.color_plot(x[..., i], y[..., i], e[..., i], cmap='plasma', vmin=vmin, vmax=vmax) graph.add_colorbar( cc, label=r'$\bar{E}_{2D}=\frac{1}{2}(\bar{U_x}^2)$', option='scientific') graph.labelaxes(ax, 'X (px)', 'Y (px)') graph.title(ax, '<z>=%.2f px' % np.mean(z[..., i])) fig.tight_layout() filename = '/time_avg_energy_raw_%s/zm%03d' % (args.mode, i) graph.save(args.dir + filename, ext='png', close=True, verbose=True) print x.shape, ux.shape xmin, xmax, ymin, ymax, zmin, zmax = np.min(x), np.max(x), np.min( y), np.max(y), np.min(z), np.max(z) points = zip(np.ravel(x), np.ravel(y), np.ravel(z)) # px after piv processing # values = np.ravel(ux)*scale*frame_rate #mm/s
normalize = mpl.colors.Normalize(vmin=-100, vmax=100) for iw in range(fitdata_arr.shape[3]): fig9, ax9 = plt.subplots(nrows=1, ncols=1) for j in range(0, ux_points.shape[0], 10): ind = np.abs(fitdata_arr[j, :, 0, iw]) < 300 ax9.plot(deltat_points[j, ind], fitdata_arr[j, ind, 0, iw], label='$U_{x}^{true} [%.f, %.f)$' % (ux_points[j, 0] - 5, ux_points[j, 0] + 5), color=cmap3(normalize(ux_points[j, 0])), linewidth=6) ax9.set_xlim(0, 0.2) ax9.set_ylim(-100, 100) ax9.legend(loc=2) graph.labelaxes(ax9, '$ \Delta t$ (a.u.)', '$\chi$ (px/unit time)') graph.save(dir + '/results/err_dist_nouz/_w%dpx' % iw, ext='png') plt.close() import sys sys.exit() # # setting up fitparams for manipulation # plotting preparation grid_deltat, grid_ux = np.mgrid[0.0:0.2:200j, -300:300:1001j] ind = ~np.isnan(np.ravel(fitdata_arr[..., 0, 0])) points = np.array(zip(np.ravel(deltat_points)[ind], np.ravel(ux_points)[ind])) fitparams = np.zeros( (fitdata_arr.shape[0], fitdata_arr.shape[1], fitdata_arr.shape[2]))
# graph.setaxes(ax1, tmin, tmax, -0.2, span * 1.3) # graph.setaxes(ax2, tmin, tmax, -500, 100) 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, alpha=0.5) graph.labelaxes(ax1, 'Time [s]', 'Position y [mm]') graph.labelaxes(ax2, 'Time [s]', 'Velocity [mm/s]') graph.suptitle(data_tracking_dir_tail) graph.setaxes(ax1, 0.15, 0.8, -0.5, 13) graph.setaxes(ax2, 0.15, 0.8, -550, 200) # Draw a line where the two data were aligned # graph.axvline(ax1, x=time_csv[vel_csv_right_ind], linestyle='--', color='k') # graph.axvline(ax2, x=time_csv[vel_csv_right_ind], linestyle='--', color='k') # Scatter plot where the two data (tracking code results and software outputs) were aligned # if v_hdf5_left_ind+shift_arg >= time_hdf5.shape[0]: # fig1, ax1 = graph.scatter([time_hdf5[v_hdf5_right_ind + shift_arg - time_hdf5.shape[0]]], [v_hdf5[v_hdf5_right_ind + shift_arg - time_hdf5.shape[0]]], fignum=1, subplot=212, # marker='x', color='C2', figsize=(12,8)) # else: # fig1, ax1 = graph.scatter(time_hdf5[v_hdf5_right_ind+shift_arg], v_hdf5[v_hdf5_right_ind+shift_arg], fignum=1, subplot=212, # marker='x', color='C2', figsize=(12,8))
# Piston tracking plot: x, y, u, v vs time title = os.path.split(fn_noext)[1] fig3, ax1 = graph.plot(time, x_pos, fignum=3, subplot=221, figsize=(12, 8)) fig3, ax2 = graph.plot(time, y_pos, fignum=3, subplot=222, figsize=(12, 8)) fig3, ax3 = graph.plot(time, u, fignum=3, subplot=223, figsize=(12, 8)) fig3, ax4 = graph.plot(time, v, fignum=3, subplot=224, figsize=(12, 8)) plt.suptitle(title) graph.labelaxes(ax1, 'Time [s]', 'X [mm]', fontsize=8) graph.labelaxes(ax2, 'Time [s]', 'Y [mm]', fontsize=8) graph.labelaxes(ax3, 'Time [s]', 'u [mm/s]', fontsize=8) graph.labelaxes(ax4, 'Time [s]', 'v [mm/s]', fontsize=8) plotfilename = os.path.join(fn_noext, 'plots/position_time') graph.save(plotfilename, verbose=True) # Piston tracking: average over multiple cycles print 'file name:' + fn_noext if not args.end == 0: x_pos = x_pos[args.start:-args.end] y_pos = y_pos[args.start:-args.end] u = u[args.start:-args.end] v = v[args.start:-args.end] print 'Number of frames in cine: %d' % len(time) time = time[args.start:-args.end]
xx, yy, n_bins, option=option) else: _, DLL = compute_struc_func(ux0, ux0_noise, xx, yy, n_bins, option=option) rr_scaled = rr / eta Dxx_scaled = DLL / ((epsilon * rr)**(2. / 3)) fig, ax = graph.plot(rr_scaled, Dxx_scaled, label=labels[i], alpha=0.9) fig, ax = graph.scatter(rr_scaled, Dxx_scaled, alpha=0.9) data['rr_scaled_' + option] = rr_scaled data['Dxx_scaled_' + option] = Dxx_scaled data['rr_' + option] = rr data['Dxx_' + option] = DLL graph.tosemilogx(ax) ax.legend(loc=2) graph.labelaxes(ax, '$r/\eta$', r'$D_{xx}/(\epsilon r)^{2/3}$') #graph.setaxes(ax, 1, 5000, -0.2, 4) graph.axhband(ax, 2 * 0.85, 2 * 1.15, 1, 5000) graph.save(savedir + 'jhtd_struc_func_scaled_white_noise_budget_test') # graph.show() datafile = 'jhtd_struc_func_scaled_white_noise_budget_test_data' rw.write_hdf5_dict(savedir + datafile, data)
yy_coarse = fa.coarse_grain_2darr_overwrap(yy, nrows_sub, ncolumns_sub, overwrap=0.5) ux0_coarse = fa.coarse_grain_2darr_overwrap(ux0, nrows_sub, ncolumns_sub, overwrap=0.5) uy0_coarse = fa.coarse_grain_2darr_overwrap(uy0, nrows_sub, ncolumns_sub, overwrap=0.5) fig1, ax11, cc11 = graph.color_plot(xx, yy, ux0, cmap=cmap, vmin=-2, vmax=2, fignum=1, subplot=221) fig1, ax12, cc12 = graph.color_plot(xx_coarse, yy_coarse, ux0_coarse, cmap=cmap, vmin=-2, vmax=2, fignum=1, subplot=222) fig1, ax13, cc13 = graph.color_plot(xx, yy, uy0, cmap=cmap, vmin=-2, vmax=2, fignum=1, subplot=223) fig1, ax14, cc14 = graph.color_plot(xx_coarse, yy_coarse, uy0_coarse, cmap=cmap, vmin=-2, vmax=2, fignum=1, subplot=224, figsize=(18, 14)) axes1 = [ax11, ax12, ax13, ax14] ccs1 = [cc11, cc12, cc13, cc14] titles1 = ['Original $U_x$', 'Coarse-grained $U_x$', 'Original $U_y$', 'Coarse-grained $U_y$'] for ax, cc, title in zip(axes1, ccs1, titles1): graph.add_colorbar(cc, ax=ax, ticklabelsize=10) graph.title(ax, title) # graph.setaxes(ax, 0, 2*np.pi, 0, 2*np.pi) graph.labelaxes(ax, '$X$ (a.u.)', '$Y$ (a.u.)') if cmap == 'RdBu': ax.set_facecolor('k') graph.suptitle('Fake data') filename = 'fake_data_vel_fields_%s' %cmap graph.save(resultdir + filename) plt.close() ################ # PIV-processed data ################ # data architecture pivlab_outputs = glob.glob(pivdatadir + '/PIV*') pivlab_output_names = [os.path.split(filename)[1] for filename in pivlab_outputs] titles2 = ['No. of particles: %s' % filename[-8:-3] for filename in pivlab_output_names]
cmap=cmap, vmin=-2, vmax=2, fignum=1, subplot=224) axes1 = [ax11, ax12, ax13, ax14] ccs1 = [cc11, cc12, cc13, cc14] titles1 = [ 'Original $U_x$', 'Coarse-grained $U_x$', 'Coarse-grained $U_y$', 'Coarse-grained $U_z$' ] for ax, cc, title in zip(axes1, ccs1, titles1): graph.add_colorbar(cc, ax=ax) graph.title(ax, title) graph.setaxes(ax, 0, 2 * np.pi, 0, 2 * np.pi) graph.labelaxes(ax, '$X$ (a.u.)', '$Y$ (a.u.)') if cmap == 'RdBu': ax.set_facecolor('k') graph.suptitle('JHTD') filename = 'jhtd_vel_fields_%s' % cmap graph.save(resultdir + filename) plt.close() ################ # PIV-processed data ################ # data architecture pivlab_outputs = glob.glob(pivdatadir + '/*') pivlab_output_names = [ os.path.split(filename)[1] for filename in pivlab_outputs ]
basedir = "/Volumes/labshared3-1/takumi/2018_05_13_mid/freq1Hz/PIV_AnalysisResults/PIV_sv_vp_left_macro55mm_fps2000_D25p6mm_piston13p1mm_freq1Hz_v100mms_fx0p1259mmpx_setting1/time_evolution/" marker = ['v', '^', 's', 'o'] # makers corresponding to domains fillstyle = ['full', 'none'] # Positive core: fill, Negative core: no fill colors = graph.get_first_n_colors_from_color_cycle(4) for domain_num in range(1, 5): filename = "time_evolution_data_domain{0}_before_collision.json".format( domain_num) filepath = basedir + filename data = rw.read_json(filepath) cx_max, cy_max = data["cxmaxlist"], data["cymaxlist"] cx_min, cy_min = data["cxminlist"], data["cyminlist"] core_positions = [[cx_max, cy_max], [cx_min, cy_min]] fig, ax = graph.set_fig(fignum=3, subplot=111, figsize=(16, 10)) for j, core_position in enumerate(core_positions): cx, cy = core_position[0], core_position[1] ax.plot(cx, cy, color=colors[domain_num - 1], marker=marker[domain_num - 1], alpha=0.7, fillstyle=fillstyle[j]) graph.setaxes(ax, 0, 127, 0, 90) graph.labelaxes(ax, 'x [mm]', 'y [mm]') ax.invert_yaxis() filename = 'trajectories_1' graph.save(basedir + filename) graph.show()