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()
#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) # 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]:
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) fig9, ax9 = graph.scatter(trForVr, vr,
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': # max = fs.get_float_from_str(pivdatum_loc, 'max', '_min') # max velocity
subplot=236) # Plotting stuff axes = [ax11, ax12, ax13, ax14, ax15, ax16] ccs = [cc11, cc12, cc13, cc14, cc15, cc16] cblabels = [ r'$U_x$', r'$U_x$', r'$U_x$', r'$U_y$', r'$U_y$', r'$U_y$' ] xlabel, ylabel = r'$X$ (px)', r'$Y$ (px)' title = r'W=%dpx, $v$=%.1f px/frame (PIVLab, Original, Diff.)' % ( iw, mag) for ax, cc, cblabel in zip(axes, ccs, cblabels): graph.add_colorbar(cc, ax=ax, label=cblabel) graph.labelaxes(ax, xlabel, ylabel) graph.setaxes(ax, 0, xx0.shape[1], 0, xx0.shape[0]) graph.suptitle(title, fignum=1) fig1.tight_layout() pivdata.close() fdata.close() figname = '/pivlab_fakedata_comp_W%d_v%spxframe_multiple_passes' % ( iw, mag_str_2) graph.save(resultdir + figname, ext='png') plt.close() break elif args.mode == 'gradient': max = fs.get_float_from_str(pivdatum_loc, 'max', '_min') # max velocity min = fs.get_float_from_str(pivdatum_loc, 'min',
# 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() graph.setaxes(ax2, 0, 300, 0, 1.5) graph.axhline(ax2, 1) graph.save(base_dir + 'strokelength')
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') plt.close('all') fyle.close() # # make movies # movie.make_movie(resultdir + 'vel_field_t', resultdir + 'movie_vel_field', ext='png', framerate=10, option='glob') # movie.make_movie(resultdir + 'pdf_vel_field_t', resultdir + 'movie_pdf_vel_field', ext='png', framerate=10, option='glob')
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)) # fig1, ax1 = graph.scatter(time_csv[vel_csv_right_ind], vel_csv[vel_csv_right_ind], fignum=1, subplot=212, # marker='x', color='C1', figsize=(12,8))
fignum=7, marker='o', linestyle='-', label=label) fig8, ax9 = graph.plot(vp_commanded_list_for_vmin, vmin_list, fignum=8, marker='o', linestyle='-', label=label) plt.figure(7) plt.legend() graph.labelaxes(ax7, 'Commanded velocity [mm/s]', '|$\overline{v^2_p} / \overline{v_p}$| [mm/s]') graph.setaxes(ax7, 0, 1100, 0, 800) # Save a figure plotfilename = os.path.join( tracking_settings['input_dir'], 'motor_characteristics/motor_characteristics') graph.save(plotfilename, verbose=True) # Save data in pkl pickledir = os.path.join(tracking_settings['input_dir'], 'motor_characteristics/') pickle_rw.write(vp_commanded_list_for_veff, pickledir + 'vp_commanded_for_veff.pkl') pickle_rw.write(veff_list, pickledir + 'veff.pkl') plt.figure(8) plt.legend() graph.labelaxes(ax8, 'Commanded velocity [mm/s]', '|$v_{min}$| [mm/s]')
n_particles_list.append(float(pivlab_output[-8:-3])) # get piv data size pivdatasize = ux.shape print nnon_nans_ux if nnon_nans_ux / 4. < 200: nbins = int(nnon_nans_ux * 0.25) else: nbins = 200 fig6, ax6 = graph.pdf(ux, nbins=nbins, fignum=6, label=label, alpha=0.7, linestyle=linestyles[i]) fig7, ax7 = graph.pdf(uy, nbins=nbins, fignum=7, label=label, alpha=0.7, linestyle=linestyles[i]) data.close() plt.figure(6) ax6.legend() graph.labelaxes(ax6, '$U_x$ (a.u.)', 'Prob. density') graph.setaxes(ax6, -4, 4, -0.1, 2) filename = 'pdf_ux' graph.save(resultdir + filename) plt.figure(7) ax7.legend() graph.labelaxes(ax7, '$U_y$ (a.u.)', 'Prob. density') graph.setaxes(ax7, -4, 4, -0.1, 2) filename = 'pdf_uy' graph.save(resultdir + filename) # Number of nans as a function of density/number of particles # Fig 8: Number of nans
uz0_coarse, 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
x=np.linspace(0,20,10) data = np.sin(x) ps = np.abs(np.fft.fft(data))**2 time_diff = np.diff(time) time_diff_avg = np.nanmean(time_diff) std = np.nanstd(time_diff) time_step = time_diff_avg freqs = np.fft.fftfreq(data.size, time_step) idx = np.argsort(freqs) ps[:]=[x / max(ps) for x in ps] fig1, ax1 = graph.plot(freqs[idx], ps[idx]) graph.setaxes(ax1, -10,10,0,1) plt.show() # # # Number of sample points # N = len(diameter) # # sample spacing # dt = 1.0 / 200.0 # t = np.linspace(0.0, N*dt, N) # x = np.sin(5.0 * 2.0*np.pi*t) + 0.5*np.sin(1.0 * 2.0*np.pi*t) # xf = fft(x) # print len(xf) # f = np.linspace(0.0, 1.0/(2.0*dt), N//2) # # # fig2, ax2 = graph.scatter(t, x) # graph.show()
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()