def make_movie(M,Range=None,field=['E','vorticity'],Dirbase=None,Dt=1): if Dirbase==None: Dirbase = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/PIV_data' #local saving nx,ny,nt = M.shape() axes = panel(M) if Range is not None: start,stop,step = tuple(Range) else: start,stop,step = tuple([0,nt,1]) frames = range(start,stop,step) # field = ['Ux','Uy'] # field = ['E','vorticity'] figs={} Dirname = Dirbase+'/'+M.Id.get_id()+'/'+graphes.remove_special_chars(str(field))+'/' print(Dirname) for i,f in enumerate(field): if not hasattr(M,f): M,field_n[i] = vgradient.compute(M,field[i],Dt=Dt) field = field_n # M,field[1] = vgradient.compute(M,field[1],Dt=Dt) if Dt>1: print('Smoothed data') Dirname = Dirname + 'Smooth_Dt_'+str(int(Dt))+'/' for i in frames: graphes.set_fig(1) for axe in axes: plt.sca(axe) plt.cla() axes = panel(M,fignum=1) plt.sca(axes[1]) print(i) graphes.Mplot(M,field[0],i,fignum=1,log=True) plt.text(-10,80,field[0],fontsize=20) plt.sca(axes[2]) graphes.Mplot(M,field[1],i,fignum=1,log=True) plt.text(-10,80,field[1],fontsize=20) figs.update(graphes.legende('','','Front view',cplot=True)) graphes.save_figs(figs,savedir=Dirname,suffix='_'+str(i),dpi=100,frmt='png',display=False) return axes
def example(M,Range=None,field=['E','vorticity']): nx,ny,nt = M.shape() axes = panel(M) if Range is not None: start,stop,step = tuple(Range) else: start,stop,step = tuple([0,nt,1]) frames = range(start,stop,step) # field = ['Ux','Uy'] # field = ['E','vorticity'] figs={} Dirbase = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/PIV_data' #local saving Dirname = Dirbase+'/'+M.Id.get_id()+'/'+graphes.remove_special_chars(str(field))+'/' print(Dirname) M,field[0] = vgradient.compute(M,field[0]) M,field[1] = vgradient.compute(M,field[1]) for i in frames: graphes.set_fig(1) for axe in axes: plt.sca(axe) plt.cla() axes = panel(M,fignum=1) plt.sca(axes[1]) graphes.Mplot(M,field[0],i,log=True) plt.text(-10,20,field[0],fontsize=20) plt.sca(axes[2]) graphes.Mplot(M,field[1],i,fignum=1,log=True) plt.text(-10,20,field[1],fontsize=20) figs.update(graphes.legende('','','Front view',cplot=True)) graphes.save_figs(figs,savedir=Dirname,suffix='_'+str(i),dpi=100,frmt='png') return axes
def example(M, i=None): figs = {} if i == None: nx, ny, nt = M.shape() i = nt // 4 fields, names, vmin, vmax, labels, units = std_fields() for j, field in enumerate(fields): figs.update( graphes.Mplot(M, field, i, fignum=j + 1, colorbar=True, vmin=vmin[j], vmax=vmax[j])) ### add label on colorbar return figs
def remove_spurious(M, borne=2., display=False): M.get('E') nx, ny, nt = M.shape() i = nt / 2 #only a small data chunk #tup,error = rm_baddata(M.E[...,i-5:i+5],d_max=2,b=1,borne=borne,display=False) #for j,t in enumerate(tup): # tup[j] = (t[0],t[1],t[2] + i-5) tup, error = rm_baddata(M.E, d_max=2, b=1, borne=borne, display=False) if display: import stephane.display.graphes as graphes graphes.Mplot(M, 'E', i, colorbar=True) xc, yc = [], [] for t in tup: xc.append([M.x[t[0], t[1]]]) yc.append([M.y[t[0], t[1]]]) graphes.graph(xc, yc, label='ro') #tup_list_y,error_y = rm_baddata(M.Uy[...,t:t+Dt],d_max=2,b=1,borne=borne,display=False) M.Ux = replace_data(M.Ux, tup) M.Uy = replace_data(M.Uy, tup) return M
def make_plot(M,Range=None,color='k',field=['E','vorticity'],Dirbase=None,Dt=1,example=False,total=True,fignum=1,save=True): if Dirbase==None: Dirbase = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/PIV_data/Test6/' #local saving Dirbase = './Stat_avg/Panel/'+M.Id.date axes = flex_panel(M,fignum=fignum) # for axe in axes: # plt.sca(axe) #plt.cla() frames = select_range(M,Range) # field = ['Ux','Uy'] # field = ['E','vorticity'] figs={} if hasattr(M,'id'): Dirname = Dirbase+'/'+M.Id.get_id()+'/'+graphes.remove_special_chars(str(field))+'/' else: Dirname = Dirbase+'/JHTD_Data/'+graphes.remove_special_chars(str(field))+'/' print(Dirname) if Dt>1: print('Smoothed data') Dirname = Dirname + 'Smooth_Dt_'+str(int(Dt))+'/' #Dt = 50 t_moy,E_moy = access.avg_vs_t(M,'E',frames,Dt=Dt) t_moy,Omega_moy = access.avg_vs_t(M,'omega',frames,Dt=Dt) t_moy,Strain_moy = access.avg_vs_t(M,'strain',frames,Dt=Dt) t_moy,Y_pdf_moy = access.avg_vs_t(M,field[1],frames,Dt=Dt) epsilon = scale.dissipation_rate(Omega_moy) #dissipation rate eta = scale.K_scale(epsilon) #dissipative scale micro_1 = np.sqrt(1./4*E_moy/Strain_moy**2) micro_2 = np.sqrt(E_moy/(Omega_moy)**2) Re = scale.Re(micro_1,eta) Re_lambda_1 = scale.Re_lambda(E_moy,micro_1) Re_lambda_2 = scale.Re_lambda(E_moy,micro_2) L = scale.I_scale(Re,E_moy) # plt.sca(axes[2]) # graphes.graphloglog(t_moy,E_moy,fignum=1,label=color+'o-') #Fourier.add_theory(t_moy,E_moy,[-2.],fignum=1) # graphes.graphloglog(t_moy,Y_pdf_moy,fignum=1,label=color+'s-') # graphes.graphloglog(t_moy,epsilon,fignum=1,label='gv-') #Fourier.add_theory(t_moy,epsilon,[-3.],fignum=1) # figs.update(graphes.legende('t (s)','E (mm^2/s^2), epsilon(mm^2/s^-3)','')) plt.sca(axes[1]) graphes.graphloglog(t_moy,eta,fignum=fignum,label=color+'o-') graphes.graphloglog(t_moy,micro_1,fignum=fignum,label=color+'s-') graphes.graphloglog(t_moy,micro_2,fignum=fignum,label='cp-') graphes.graphloglog(t_moy,L,fignum=fignum,label='gv-') figs.update(graphes.legende('t (s)','eta (mm), lambda (mm)','')) plt.sca(axes[2]) graphes.graphloglog(t_moy,Re,fignum=fignum,label=color+'o-') graphes.graphloglog(t_moy,Re_lambda_1,fignum=fignum,label=color+'s-') graphes.graphloglog(t_moy,Re_lambda_2,fignum=fignum,label='cp-') figs.update(graphes.legende('t (s)','Re , Re_lambda','')) # print(t_moy) # print(Y_moy) # print(t) # print(Y_moy) indices = [0,1] # indices = [1,4] cla_axes = [axes[i] for i in indices] if save: graphes.save_figs(figs,savedir=Dirname,prefix='General',suffix='_vs_t',dpi=300,frmt='png',display=True) individual=False if example: frames_disp =[1200] else: step =frames[1]-frames[0] frames_disp = range(frames[0]+step*10,frames[-1],step*10) if individual: for frame in frames_disp: #print(frame) #print(frames) i = frames.index(frame) graphes.set_fig(1) for axe in cla_axes: plt.sca(axe) plt.cla() axes = flex_panel(M,fignum=1) if total: plt.sca(axes[0]) graphes.Mplot(M,field[0],frame,fignum=1,log=True) plt.text(-10,80,field[0],fontsize=20) plt.sca(axes[1]) # graphes.graphloglog(t_moy,eta,fignum=1,label='ko-') # graphes.graphloglog(t_moy,micro,fignum=1,label='ks-') graphes.graph([t_moy[i]],[eta[i]],fignum=1,label='ro') graphes.graph([t_moy[i]],[micro_1[i]],fignum=1,label='rs') graphes.graph([t_moy[i]],[micro_2[i]],fignum=1,label='rp') graphes.graphloglog([t_moy[i]],[L[i]],fignum=1,label='rv-') plt.sca(axes[2]) graphes.graphloglog([t_moy[i]],[Re[i]],fignum=1,label='ro-') graphes.graphloglog([t_moy[i]],[Re_lambda_1[i]],fignum=1,label='rs-') graphes.graphloglog([t_moy[i]],[Re_lambda_2[i]],fignum=1,label='rp-') plt.sca(axes[3]) figs.update(graphes.pdf(M,'Ux',frame,Dt=Dt,fignum=1,label='m^')) figs.update(graphes.pdf(M,'Uy',frame,Dt=Dt,fignum=1,label='b>')) figs.update(graphes.legende('t (s)','Re , Re_lambda','')) plt.sca(axes[4]) figs.update(graphes.pdf(M,field[1],frame,Dt=Dt,fignum=1,label=color+'-')) # graphes.Mplot(M,field[1],i,fignum=1,log=True) # plt.text(-10,80,'PDF '+field[1],fontsize=20) # figs.update(graphes.legende('','','Front view',cplot=True)) graphes.save_figs(figs,savedir=Dirname,suffix='_'+str(frame),dpi=100,frmt='png',display=False) return axes
def make_2dmovie(M, name, Range=None, fignum=1, local=True, log=False, vmin=0, vmax=1, filt=False): """ Movie of the colormap of the velocity modulus U over time INPUT ----- M : Mdata class instance, or any other object that contains the following fields : methods : shape() attributes : Ux, Uy Sdata object Ids object ... name : name of the field to be plotted. example : Ux,Uy, vorticity, strain Range : np array fignum : int. default value is 1 Dirname : string Directory to save the figures log : bool. default value is True OUTPUT ----- None """ if Range is not None: start, stop, step = tuple(Range) else: start, stop, step = tuple([0, M.shape()[-1], 5]) # U=np.sqrt(S.Ux**2+S.Uy**2) #by default, pictures are save here : if local: Dirlocal = '/Users/stephane/Documents/Experiences_local/Accelerated_grid' else: Dirlocal = os.path.dirname(M.Sdata.fileCine) Dirname = name if filt: Dirname = Dirname + '_filtered' Dir = Dirlocal + '/PIV_data/' + M.Id.get_id() + '/' + Dirname + '/' print(Dir) fig = graphes.set_fig(fignum) graphes.set_fig(0) #clear current figure print('Compute ' + name) M, field = vgradient.compute(M, name, filter=filt) for i in range(start, stop, step): #Z = energy(M,i) graphes.Mplot(M, field, i, fignum=fignum, vmin=vmin, vmax=vmax, log=log, auto_axis=True) # graphes.color_plot(Xp,Yp,-Z,fignum=fignum,vmax=700,vmin=0) if i == start: cbar = graphes.colorbar( ) #fignum=fignum,label=name+'(mm^2 s^{-2})') else: print('update') # cbar.update_normal(fig) filename = Dir + 'V' + str(i) graphes.save_fig(fignum, filename, frmt='png')
def single(filename, display=False): figs = {} savedir = '/Users/stephane/Documents/Postdoc_Chicago/Process_data/Scripts/Samples/Smoothing/' filesave, ext = os.path.splitext(filename) filesave = filesave + '_processed.hdf5' M = M_manip.load_Mdata_file(filename, data=True) M.get('E') M.get('omega') nx, ny, nt = M.shape() i = nt / 2 # display raw energy if display: graphes.plt.close('all') graphes.Mplot(M, 'E', i, vmin=0, vmax=50000, fignum=1, colorbar=True) figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Energy without pre-processing', cplot=True)) #Display raw vorticity graphes.Mplot(M, 'omega', i, vmin=0, vmax=100, fignum=2, colorbar=True) figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Vorticity without pre-processing', cplot=True)) graphes.save_figs(figs, savedir=savedir, prefix=M.Id.get_id()) graphes.Mplot(M, 'Ux', i, vmin=-200, vmax=200, fignum=3, colorbar=True) figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Ux after pre-processing', cplot=True)) M = cdata.remove_spurious(M, borne=1.5) M.get('E', force=True) M.get('omega', force=True) if display: graphes.Mplot(M, 'E', i, vmin=0, vmax=50000, fignum=4, colorbar=True) figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Energy after pre-processing', cplot=True)) #Display raw vorticity graphes.Mplot(M, 'omega', i, vmin=0, vmax=100, fignum=5, colorbar=True) figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Vorticity after pre-processing', cplot=True)) ### Gaussian filter omega_filt = track.smoothing(M, i, field='omega', sigma=2.5) graphes.color_plot(M.x, M.y, omega_filt, vmin=0, vmax=100, fignum=6) graphes.plt.colorbar() figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Vorticity after gaussian smoothing', cplot=True)) graphes.save_figs(figs, savedir=savedir, prefix=M.Id.get_id()) ### Gaussian filter # omega_filt = filters.gaussian_filter(omega, sigma=2.)#[...,0] # graphes.color_plot(x,y,omega_filt,vmin=0,vmax=50,fignum=5) # graphes.plt.colorbar() # figs.update(graphes.legende('$x$ (mm)','$y$ (mm)','Vorticity after gaussian smoothing',cplot=True)) # graphes.save_figs(figs,savedir=savedir) to_hdf5.write(M, filename=filesave, key='Mdata')
def example(filename): figs = {} savedir = '/Users/stephane/Documents/Postdoc_Chicago/Process_data/Scripts/Example/Smoothing/' M = M_manip.load_Mdata_file(filename, data=True) M.get('E') M.get('omega') nx, ny, nt = M.shape() x, y = M.x, M.y i = nt / 2 # display raw energy graphes.Mplot(M, 'E', i, vmin=0, vmax=50000, fignum=1, colorbar=True) figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Energy without pre-processing', cplot=True)) #Display raw vorticity graphes.Mplot(M, 'omega', i, vmin=0, vmax=80, fignum=2, colorbar=True) figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Vorticity without pre-processing', cplot=True)) # Look for bada data point in amplitude E = M.E[..., i] tup, errors = cdata.rm_baddata(E, borne=2.) xc = [] yc = [] for t in tup: xc.append([x[t[0], t[1]]]) yc.append([y[t[0], t[1]]]) graphes.graph(xc, yc, label='ro', fignum=2) print(figs) graphes.save_figs(figs, savedir=savedir) Ux, Uy = M.Ux[..., i], M.Uy[..., i] #replace component of the velocity Ux = cdata.replace_data(Ux, tup)[..., 0] Uy = cdata.replace_data(Uy, tup)[..., 0] U = np.transpose(np.asarray([Uy, Ux]), (1, 2, 0)) dU = strain.strain_tensor_C(U, b=2.) omega, enstrophy = strain.vorticity(dU, d=2, norm=False) E = Ux**2 + Uy**2 graphes.color_plot(x, y, omega, vmin=0, vmax=80, fignum=4) graphes.plt.colorbar() figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Vorticity after pre-processing', cplot=True)) graphes.color_plot(x, y, E, vmin=0, vmax=50000, fignum=3) graphes.plt.colorbar() figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Energy after pre-processing', cplot=True)) ### Gaussian filter omega_filt = filters.gaussian_filter(omega, sigma=2.) #[...,0] graphes.color_plot(x, y, omega_filt, vmin=0, vmax=80, fignum=5) graphes.plt.colorbar() figs.update( graphes.legende('$x$ (mm)', '$y$ (mm)', 'Vorticity after gaussian smoothing', cplot=True)) graphes.save_figs(figs, savedir=savedir)