def shear_limit_M(M, W, Dt, type=1, **kwargs): """ Test the shear criterion : dU/W < 0.1 """ values = access.get(M, 'strain', frame) M, field = vgradient.compute(M, 'strain', step=1, filter=False, Dt=1, rescale=False, type=type, compute=False) values = getattr(M, field) #/W dUmin, dUmax = check.shear_limit_M(M, W) xbin, n = graphes.hist(values, normalize=False, num=200, range=(-0.5, 0.5), **kwargs) #xfactor = Dt maxn = max(n) * 1.2 graphes.graph([dUmin, dUmin], [0, maxn], label='r-', **kwargs) graphes.graph([dUmax, dUmax], [0, maxn], label='r-', **kwargs) graphes.legende('', '', '')
def velocity_profile(M, xlines, ylines, display=True, start=0, end=10000, label='k^'): nx, ny, nt = M.shape() nt = min(nt, end) U = np.sqrt(M.Ux[:, :, start:nt]**2 + M.Uy[:, :, start:nt]**2) label = ['k^', 'rx', 'bo'] Dt = 10 t = M.t[start + Dt:nt - Dt] Ut = [] for i in ylines: for j in xlines: Ut.append(basics.smooth( U[i, j], Dt)) #[np.mean(S.Uy[i,j,k-Dt:k+Dt]) for k in range(Dt,nt-Dt)] # std_U=[np.std(U[i,j,k-Dt:k+Dt]) for k in range(Dt,nt-Dt)] if display: graphes.graph(t, Ut[-1]) graphes.legende('t (ms)', 'V (m/s)', '') #return a list of time series, for each element in xlines and ylines return t, Ut
def vertical_profile(S, xlines, Dt, start=0): nx, ny, nt = S.shape() y = S.y[:, 0] for i in range(start, nt, Dt): Ux = np.mean(np.mean(S.Ux[:, xlines, i:i + Dt], axis=1), axis=1) Uy = np.mean(np.mean(S.Uy[:, xlines, i:i + Dt], axis=1), axis=1) #standard deviation computation std_Ux = np.sqrt( np.mean(np.mean(abs(S.Ux[:, xlines, i:i + Dt] - Ux)**2, axis=1), axis=1)) std_Uy = np.sqrt( np.mean(np.mean(abs(S.Uy[:, xlines, i:i + Dt] - Uy)**2, axis=1), axis=1)) print(std_Ux) plt.subplot(121) graphes.graph(y, Ux, std_Ux) graphes.legende('z (m)', 'V (m/s)', 'Ux') plt.subplot(122) graphes.graph(y, Uy, std_Uy) graphes.legende('z (m)', 'V (m/s)', 'Uy') plt.draw() raw_input()
def test_bound(dataList, W, Dt, **kwargs): maxn = 0 Umin, Umax = bounds_pix(W) ratio = [] for data in dataList: # values = np.asarray(data['u'])**2+np.asarray(data['v']**2) values = np.sqrt(np.asarray(data['u'])**2 + np.asarray(data['v'])**2) r = len(np.where(np.logical_and( values > Umin, values < Umax))[0]) * 100. / len(data['u']) ratio.append(r) xbin, n = graphes.hist(values, normalize=False, num=200, range=(0., 2 * Umax), **kwargs) #xfactor = Dt maxn = max([maxn, max(n) * 1.2]) ratio = np.nanmean(np.asarray(ratio)) graphes.graph([Umin, Umin], [0, maxn], label='r-', **kwargs) graphes.graph([Umax, Umax], [0, maxn], label='r-', **kwargs) graphes.set_axis(0, Umax * 1.2, 0, maxn) title = 'Dt = ' + str(Dt) + ', W = ' + str(W) + 'pix' fig = graphes.legende('U (pix)', 'Histogram of U', title) # graphes.set_axis(0,1.5,0,maxn) return ratio, fig
def fit_core_circulation(M, fignum=1, display=False): R, Gamma, center, factor = compute_circulation_2(M, fignum=fignum, display=display) factor = np.max(Gamma) Gamma = Gamma / factor #fit_core_circulation(R_list,Gamma,M,fignum=fignum,display=False) nx, ny, nt = M.shape() a0 = (1, np.max(Gamma)) fun = circ_gaussian res = opt.minimize(distance_fit, a0, args=(fun, R, Gamma)) cond = ((center[0] > 5) and (center[0] < nx - 5) and (center[1] > 5) and (center[1] < ny - 5)) if cond: lc = np.sqrt(res.x[0]) G0 = factor * res.x[1] else: lc = None G0 = None if display: graphes.graph(R, factor * Gamma, fignum=1, label='ko') graphes.graph(R, factor * fun(res.x, R), fignum=1, label='r') return lc, G0, center
def velocity_profile_xy(S, xlines, ylines, display=False, label='k^'): nx, ny, nt = S.shape() label = ['k^', 'rx', 'bo'] t = S.t Dt = 5 Uxt = [] Uyt = [] for i in ylines: for j in xlines: # std_Ux=[np.std(S.Ux[i,j,k-Dt:k+Dt]) for k in range(Dt,nt-Dt)] # std_Uy=[np.std(S.Uy[i,j,k-Dt:k+Dt]) for k in range(Dt,nt-Dt)] Uxt.append( basics.smooth(S.Ux[i, j], Dt) ) #(-1)**i*(-1)**j* [(-1)**i*(-1)**j*np.mean(S.Ux[i,j,k-Dt:k+Dt]) for k in range(Dt,nt-Dt)] Uyt.append(basics.smooth( S.Uy[i, j], Dt)) #[np.mean(S.Uy[i,j,k-Dt:k+Dt]) for k in range(Dt,nt-Dt)] if display: # plt.subplot(211) graphes.graph(t[Dt:-Dt], Uxt[-1]) #,std_Ux) graphes.legende('t (ms)', 'V (m/s)', 'Ux') # plt.subplot(212) graphes.graph(t[Dt:-Dt], Uyt[-1]) #,std_Uy) graphes.legende('t (ms)', 'V (m/s)', 'Uy') return t, Uxt, Uyt
def spatial_corr(data, N=1024, Dt=10): Cxx = np.zeros((N / 2, Dt)) d = np.arange(N / 2) figs = {} for p in range(3): for k in range(Dt): key = data.keys()[k] Z = np.asarray(data[key]) Ex = np.nanmean(np.power(Z[:N / 2, 0, 0, p], 2)) Cxx[:, k] = np.nanmean(np.asarray([[ Z[i, 0, 0, p] * Z[i + j, 0, 0, p] / Ex for i in range(N / 2) ] for j in range(N / 2)]), axis=1) #print(Cxx[0,:]) C = np.nanmean(Cxx, axis=1) graphes.graph(d, C, fignum=1) graphes.set_axis(0, N / 4, -1, 1.5) figs.update(graphes.legende('d', 'C', '')) graphes.save_figs(figs, savedir='./Corr_functions/', suffix='', prefix='', frmt='pdf', dpi=300)
def fit_core_size(x, y, Z, fignum=1, display=False): """ Find the half width of a gaussian bump INPUT ----- x : 2d np array spatial coordinates (columns) y : 2d np array spatial coordinates (lines) Z : 2d np array data to be fitted (typically vorticity field ) fignum : int figure number for the output. Default 1 display : bool OUTPUT ----- a : float parameter of the gaussian bump center : 2 elements np array center coordinates """ ny, nx = Z.shape X, Y, data, center, factor = normalize(x, y, Z) R, theta = Smath.cart2pol(X, Y) a0 = 1 fun = gaussian res = opt.minimize(distance_fit, a0, args=(fun, R, data)) cond = ((center[0] > 5) and (center[0] < nx - 5) and (center[1] > 5) and (center[1] < ny - 5)) if cond: a = np.sqrt(res.x) else: a = None if display: figs = {} graphes.graph(R, factor * data, fignum=3, label='ko') graphes.graph(R, factor * gaussian(res.x, R), label='r.', fignum=fignum + 2) graphes.set_axis(0, 20, 0, factor * 1.1) figs.update(graphes.legende('r (mm)', 'Vorticity s^{-1})', '')) graphes.cla(fignum=fignum) graphes.color_plot(X, Y, factor * data, fignum=fignum + 3) graphes.colorbar() figs.update( graphes.legende('X (mm)', 'Y (mm)', 'Vorticity', display=False, cplot=True)) return a, center, figs else: return a, center
def display_profile(x, V, label='k', axe=2, fignum=0): x = np.asarray(x) z = x[:, axe] labels = ['Ux', 'Uy', 'Uz'] for i in range(3): graphes.graph(z, V[:, i], fignum=-i + 3 + fignum, label=label) graphes.legende(labels[i][1] + ' (au)', 'V ', labels[i])
def plot(p,tmin,tmax,label='',c=True,fignum=0): """ Plot the position of the vortex as a function time. pos is a dictionnary obtained from track.position tmin : minimum index tmax : maximum index """ figs = {} keys = ['Xmax','Xmin','Ymin','Ymax'] subplot = {'Xmax':121,'Xmin':121,'Ymax':122,'Ymin':122} fig1 = graphes.set_fig(fignum+1) fig1.set_size_inches(10,4) accurate = {key:None for key in keys} for key in keys: # print(p[key][tmin:tmax]) if c: p[key][tmin:tmax],accurate[key] = correct(p[key][tmin:tmax],a=5.) else: accurate[key]=True if 'Y' in key: #print('invert !') if np.nanmean(p[key])<0: p[key] = -np.asarray(p[key]) #X axis is inverted ! if accurate[key]: graphes.set_fig(fignum+1,subplot[key]) graphes.graph(p['t'],p[key],fignum=fignum+1,label=label) figs.update(graphes.legende('Time (s)',key[0]+' position (mm)','')) if 'Y' in key: graphes.set_axis(0.05,p['t'][tmax],0,100) else: graphes.set_axis(0.05,p['t'][tmax],-50,50) p['d']=np.sqrt((np.asarray(p['Xmin'])-np.asarray(p['Xmax']))**2+(np.asarray(p['Ymin'])-np.asarray(p['Ymax']))**2) graphes.graph(p['t'],p['d'][tmin:tmax],fignum=fignum+2,label=label) graphes.set_axis(0,p['t'][tmax],0,50) figs.update(graphes.legende('Time (s)','Distance (mm)','')) if accurate['Xmin'] and accurate['Ymin']: graphes.graph(p['Ymin'][tmin:tmax],p['Xmin'][tmin:tmax],fignum=fignum+3,label=label) figs.update(graphes.legende('X position (mm)','Y position (mm)','')) graphes.set_axis(0,60,-50,50) if accurate['Xmax'] and accurate['Ymax']: graphes.graph(p['Ymax'][tmin:tmax],p['Xmax'][tmin:tmax],fignum=fignum+3,label=label) graphes.graph(p['t'],p['Gammamax'],fignum=fignum+4,label=label) figs.update(graphes.legende('Time (s)','Circulation (mm^2/s)','')) graphes.set_axis(p['t'][tmin],p['t'][tmax],0,5*10**4) return figs,accurate
def spatial_average(M, indices=None): figs = {} fields, names, vmin, vmax, labels, units = std_fields() for j, field in enumerate(fields): Y_moy = np.nanmean(getattr(M, field), axis=(0, 1)) graphes.graph(M.t, Y_moy, label=labels[j], fignum=j + 1) #graphes.set_axis(0,5,0,18000) figs.update( graphes.legende('Time (s)', names[j] + ' (' + units[j] + ')', '')) return figs
def compute_Ct(M, tlist=[], axes=['Ux', 'Ux'], p=1, display=False, label='ko', fignum=1): display_part = False if tlist == []: t0 = 20 Dt = 50 dimensions = M.shape() tlist = range(t0, dimensions[2] - t0, Dt) tau = np.zeros(len(tlist)) tf = np.zeros(len(tlist)) for i, t in enumerate(tlist): X, Y, Yerr = stat_corr_t(M, t, axes=axes, p=1, display=False) try: popt, pcurv = scipy.optimize.curve_fit(fitting.exp, np.abs(X), Y) except ValueError: print("NaN values encountered, fit skipped") X, Y, Yerr = stat_corr_t(M, t, axe='E', p=1, display=True) # input() pcurv = [] popt = [1] except RuntimeError: print( "Fitting did not converge, arbitrarly chosen to previous value" ) pcurv = [] if i == 0: popt = [1] else: popt = [tau[i - 1]] tf[i] = M.t[t] tau[i] = -1 / popt[0] # print(str(M.t[t]) + ' : ' +str(tau[i])) if display_part: texp = np.abs(X) graphes.set_fig(1) graphes.errorbar(texp, Y, texp * 0, Yerr, fignum=0, label='ko') graphes.graph(texp, exp(texp, -1 / tau[i]), fignum=1, label='r') graphes.legende('$t/u^{2m}$', '$C_t$', '$m=1/2$') if display: graphes.graphloglog(tf, tau, fignum=fignum, label=label) graphes.legende('t (s)', 't_c', graphes.title(M)) return tf, tau
def spectrum_1d(M, indices=None, norm_factor=1): Fourier.compute_spectrum_1d(M, Dt=3) S_k = np.nanmean(M.S_k[..., indices], axis=1) / norm_factor graphes.graphloglog(M.k, S_k, label='^-', fignum=1) k0 = 0.1 i = np.argmin(np.abs(M.k - k0)) A = S_k[i] * k0**(5. / 3) # print('Total energy : '+np.sum(M.k*S_k)) graphes.graph(M.k, A * M.k**(-5. / 3), label='r--') figs = graphes.legende('$k$ (mm$^{-1}$)', 'E (m/s^2)', '') return figs
def from_circulation_2(M, fignum=1, display=True): # R_list,Gamma,center,factor = compute_circulation_2(M,fignum=fignum) lc, G0, center = fit_core_circulation(M, fignum=fignum, display=True) nx, ny, nt = M.shape() for i in range(nt): R_list, Gamma, center, factor = circulation_2(M, i) graphes.graph(R_list, Gamma * factor, fignum=fignum, label='k^') graphes.legende('r (bmm)', 'Circulation (mm^2/s)', '') graphes.set_axis(0, 12., -7000, 500) return None
def artificial_1d(): #just to test derivative : works perfectly dx = 0.001 p = 5 x = np.arange(0, 1, dx) y = np.power(x, p) dy_num = tangent(y, d=1, step=1, cyclic=False) / dx dy_th = p * np.power(x[3:-3], p - 1) graphes.graph(x, dy_num) graphes.graph(x, dy_th) graphes.set_axis(0, 1, -1, p + 1)
def from_vorticity(M, fignum=1, display=True): ny, nx, nt = M.shape() field = 'omega' M.get(field) # M,field = vgradient.compute(M,'vorticity',filter=True) Z = getattr(M, field) x, y = space_axis_vorticity(M) a = [] indices = range(0, nt, 1) x0 = [] y0 = [] index = [] for i in indices: sigma, center = fit_core_size(x, y, Z[..., i], display=False) if sigma is not None: a.append(sigma) index.append(i) x0.append(center[0]) y0.append(center[1]) lc = np.nanmedian(a) std_lc = np.nanstd(a) #plot example error = 0.5 if len(index) > 0 and std_lc / lc < error: i_example = index[len(index) // 2] print('Indice : ' + str(i_example)) sigma, center, figs = fit_core_size(x, y, Z[..., i_example], fignum=fignum, display=True) t = np.asarray([M.t[i] for i in index]) graphes.graph(t, a, label='k', fignum=fignum + 1) # graphes.graph(t,x0,label='r.',fignum=3) # graphes.graph(t,y0,label='b.',fignum=3) title = os.path.basename(M.dataDir) graphes.set_axis(np.min(t), np.max(t), 0., 7.) figs.update(graphes.legende('t (s)', 'Core size', title, display=False)) save_graphes(M, figs, method='vorticity') return lc, std_lc
def isotropy(M, label='k^--', display=True, fignum=1): step = 1 tl = M.t[0:None:step] N = 50 display_part = False Anisotropy = np.zeros(len(tl)) Meanflow = np.zeros(len(tl)) for i, t in enumerate(tl): print(i * 100 / len(tl)) rho, Phi = angles(M, i) theta, U_moy, U_rms = angular_distribution(M, i) # t,U_moy,U_rms = time_window_distribution(M,i,Dt=40) if display_part: graphes.hist(Phi, fignum=1, num=N) graphes.legende('Phi', 'PDF', '') graphes.graph(theta, U_moy, fignum=3, label='k^') graphes.legende('$\theta$', '$U^p$', 'Angular fluctation distribution') graphes.graph(theta, U_rms, fignum=4, label='ro') graphes.legende('$\theta$', '$U^p$', 'Angular average flow') Anisotropy[i] = np.std(U_rms) / np.nanmean(U_rms) Meanflow[i] = np.std(U_moy) / np.nanmean(U_rms) graphes.semilogx(tl, Anisotropy, label='ro', fignum=fignum, subplot=(1, 2, 1)) graphes.legende('Time (s)', 'I', 'Anisotropy' + graphes.set_title(M)) graphes.set_axes(10**-2, 10**4, 0, 2) graphes.semilogx(tl, Meanflow, label='k^', fignum=fignum, subplot=(1, 2, 2)) graphes.legende('Time (s)', '<U>', 'Average flow') graphes.set_axes(10**-2, 10**4, 0, 4)
def positions(M,i,field='omega',display=False,sigma=1.,**kwargs): """ find the maximum position of the vortex core at a given instant, using the field specified in argument """ imin,imax,jmin,jmax,Zfilt,X,Y = position_index(M,i,field=field,display=display,sigma=sigma,**kwargs) deltax_max,deltay_max = SubPix2DGauss(Zfilt/np.max(Zfilt),imax,jmax,SubPixOffset=0) deltax_min,deltay_min = SubPix2DGauss(Zfilt/np.min(Zfilt),imin,jmin,SubPixOffset=0) # print(deltax_max) # print(deltax_min) # print(deltay_min) # print(deltax_max) #if deltax_max == np.nan or deltax_min==np.nan: # return np.nan,np.nan,np.nan,np.nan #else: xmin = X[imin,jmin]+deltax_min xmax = X[imax,jmax]+deltax_max ymin = Y[imin,jmin]-deltay_min ymax = Y[imax,jmax]-deltay_max # print(Zfilt.shape) # print(Y.shape) # print(X.shape) if display: graphes.color_plot(X[:,5:],Y[:,5:],Zfilt/np.min(Zfilt),**kwargs) graphes.graph([xmin+10],[ymin],label='bo',**kwargs) graphes.graph([xmax+10],[ymax],label='ro',**kwargs) # graphes.color_plot(X[:,5:],Y[:,5:],Zfilt/np.max(Zfilt),fignum=2) #input() # t.append(M.t[i]) # Xmin.append(M.x[imin,jmin]) # Xmax.append(M.x[imax,jmax]) # Ymin.append(M.y[imin,jmin]) # Ymax.append(M.y[imax,jmax]) return xmin,xmax,ymin,ymax
def multi_plane_measurements(Dt, N): ti = 500 n = 13 # Dtlist=[2,4,6,8,10,20,30,50,70,100,150,200,500] m = len(Mlist) t = np.zeros((n, m)) Ux_rms = np.zeros((n, m)) Uy_rms = np.zeros((n, m)) Uxt_rms = np.zeros((n, m)) Uyt_rms = np.zeros((n, m)) Zlist = [M.param.Zplane for M in Mlist] Dtlist = [Dt] for M in Mlist: j = Mlist.index(M) print(j) for i in range(n): t0 = (i + 1) * N + ti mid = t0 + Dt / 2 t[i] = M.t[mid] # Sdata_measure.velocity_distribution(M_1000fps,t0,t0+Dt) if i == 0: fig = j * 2 + 1 plt.figure(fig) # Ux_rms[i,j],Uy_rms[i,j],Uxt_rms[i,j],Uyt_rms[i,j]=Sdata_measure.velocity_distribution(M,t0,t0+Dt) Dir = M.fileDir + 'Velocity_Distribution' + '/' file = graphes.set_title(M, 'Dt=' + str(Dt / 10) + ' ms' + 'pdf_U') filename = Dir + file print(Dir) print(filename) # graphes.save_fig(fig,filename,Dir) U_rms = (Ux_rms + Uy_rms) / 2 Ut_rms = (Uxt_rms + Uyt_rms) / 2 graphes.graph(Zlist, U_rms[0, :], -1, 'o') graphes.graph(Zlist, Ut_rms[0, :], 0, '^') graphes.graph(Zlist, U_rms[0, :], -1, '+--') for i in range(1, n): graphes.graph(Zlist, (U_rms[i, :] * t[i] / t[0]), 0, '+--') graphes.set_axes(-110, 50, 0, 1) graphes.legende('$Z (mm)$', '$(t/t_0) <Urms_{xi}>_{Dt,x,y}$', '') file = graphes.set_title(M, 'U_rms_vs_t') filename = Dir + file
def mean_profile(S, i, j, direction='v', label='k^', display=False): #mean profile along the whole field : average on one direction only ! (and small windows on the other direction ?) nx, ny, nt = S.shape() Ux = S.m.Ux Uy = S.m.Uy #remove the data out of the PIV bounds # Ux,Uy=fix_PIV(S) U = np.sqrt(Ux**2 + Uy**2) # V=np.reshape(U,(nx*ny,nt)) #median is not so affected by peak values, but standard deviation definetely ! #histogramm between vmin and vmax, and remove values out of bound (set to NaN) U_moy = [] U_std = [] t = S.m.t Dt = 2 if direction == 'v': #average along the horizontal direction U_moy = [ np.mean(np.mean(U[j - Dt:j + Dt, :, k], axis=0), axis=0) for k in range(nt) ] print('horizontal average') else: #average along the vertical direction U_moy = [ np.mean(np.mean(U[:, i - Dt:i + Dt, k], axis=0), axis=0) for k in range(nt) ] print('vertical average') print(np.shape(U_moy)) if display: #U_moy=np.mean(V[np.invert(np.isnan(V))],axis=0) print('Number of frames : ' + str(len(S.m.t))) graphes.graph(t, U_moy, label) graphes.legende('t (ms)', '<V>_{x,y} (m/s)', '') return U_moy, U_std
def movie_spectrum(M, field, alpha=[-5. / 3], Dt=10, fignum=1, start=0, stop=0): #switch_field(field) if not hasattr(M, field): M, field = vgradient.compute(M, field) if not hasattr(M, 'S_' + field): Y = getattr(M, field) Y_k, k = spectrum_1d(Y, M, display=False, Dt=Dt) print(Y_k.shape) else: Y_k = getattr(M, 'S_' + field) k = getattr(M, 'k_' + field) step = max(Dt / 2, 1) N, nt = Y_k.shape if stop == 0: tax = range(start, nt, step) else: tax = range(start, stop, step) figs = {} for i, t in enumerate(tax): #graphes.cla(fignum) graphes.graph(k, Y_k[:, t], label='k-', fignum=fignum) #graphes.graphloglog(k,Y_k[:,t],label='k-',fignum=fignum) add_theory(k, Y_k[:, t], alpha, fignum=fignum) # graphes.set_axis(10**-2,10**0,10**-4,10**2) figs.update(graphes.legende('k (mm^-1)', 'E_k (mm^3/s^-2)', '')) graphes.save_graphes(M, figs, prefix='Movie_Spectrum_' + field + '/', suffix='_' + str(t))
def tangent_test(): N = 100 path = generate_vortex(1, N) dV = tangent(path) * N / (2 * np.pi) print(np.mean(norm(dV))) print(np.std(norm(dV))) indices = np.arange(0, 100, 10) for i in indices: print(dV[i, :], path[i, :]) # graphes.graph(path[:,0],path[:,1],label='r') graphes.graph(np.arange(N), path[:, 0]) graphes.graph(np.arange(N), np.sum(dV * path, axis=1)) # vfield.plot(path[:,0],path[:,1],dV) # graphes.set_axis(-1.1,1.1,-1.5,1.5) graphes.legende('x', 'y', '')
def horizontal_profile(S, ylines, Dt, start=0): nx, ny, nt = S.shape() x = S.x[0, :] for i in range(start, nt, Dt): Ux = np.mean(np.mean(S.Ux[ylines, :, i:i + Dt], axis=0), axis=1) Uy = np.mean(np.mean(S.Uy[ylines, :, i:i + Dt], axis=0), axis=1) std_Ux = np.std(np.std(S.Ux[ylines, :, i:i + Dt], axis=0), axis=1) std_Uy = np.std(np.std(S.Uy[ylines, :, i:i + Dt], axis=0), axis=1) plt.subplot(121) graphes.graph(x, Ux, 0, std_Ux) graphes.legende('x (m)', 'V (m/s)', 'Ux') plt.subplot(122) graphes.graph(x, Uy, 0, std_Uy) graphes.legende('x (m)', 'V (m/s)', 'Uy') plt.draw() raw_input()
def display_corr_vs_t(M, dlist, indices, step=100, Dt=1, label='-', display=False, fignum=1): tref, d, Cxx, Cyy, Cxy, CEE = correlation_functions(M, dlist, indices, Dt=Dt) #Display successive correlations functions times = range(0, len(tref) - 3 * Dt, step) times = range(0, len(tref), step) if display: for t in times: graphes.graph(d, Cxx[:, t] / Cxx[0, t], fignum=fignum) graphes.set_axis(0, max(d), -1, 1.5) graphes.legende('d (mm)', 'C_{xx}', '') graphes.graph(d, Cyy[:, t] / Cyy[0, t], fignum=fignum + 1) graphes.set_axis(0, max(d), -1, 1.5) graphes.legende('d (mm)', 'C_{yy}', '') graphes.graph(d, CEE[:, t] / CEE[0, t], fignum=fignum + 2) graphes.set_axis(0, max(d), -1, 1.5) graphes.legende('d (m)', 'C_{E}', '') return tref, d, Cxx, Cyy, Cxy, CEE
def time_corr(data, param, N=800): keys = data.keys() figs = {} for p in range(3): print(p) keys = np.sort(keys) [data[key] for key in keys] t = np.asarray([param[key]['t0'] for key in keys[0:N / 2]]) C = np.zeros(N / 2) Dt = np.zeros(N / 2) for i in range(N / 2): if i % 100 == 0: print(i) C[i] = np.nanmean(np.asarray([ data[key1][..., p] * data[keys[i + j]][..., p] for j, key1 in enumerate(keys[0:N / 2]) ]), axis=(0, 1, 2)) Dt[i] = np.nanmean( np.asarray([ param[keys[j + i]]['t0'] - param[keys[j]]['t0'] for j in range(N / 2) ])) # print(Dt) graphes.graph(Dt, C / C[0], fignum=4) graphes.set_axis(0, 400, -1, 1.1) figs.update(graphes.legende('t', 'C', 'JHTD corr functions')) graphes.save_figs(figs, savedir='./Corr_functions/', suffix='', prefix='', frmt='pdf', dpi=300)
def test_Dt(W): figs = {} ratio = [] Dt_list = range(1, 11) for i, Dt in enumerate(Dt_list): print('Dt : ' + str(Dt)) Dir = '/Users/stephane/Documents/Experiences_local/PIV_tests/Database/Turbulence/PIV_data/' base = '_2016_03_01_PIV_sv_vp_zoom_zoom_X10mm_M24mm_fps10000_n14000_beta500m_H1180mm_S150mm_1' Dirbase = Dir + 'PIVlab_ratio2_W' + str(W) + 'pix_Dt_' + str(Dt) + base fileList = glob.glob(Dirbase + '/*.txt') dataList = get_data(fileList) r, fig = test_bound(dataList, W, Dt, fignum=1 + i) figs.update(fig) ratio.append(r) graphes.graph(Dt_list, ratio, fignum=11, label='ko') graphes.graph([0, 11], [100, 100], label='r-', fignum=11) graphes.set_axis(0, 11, 0, 110.) figs.update( graphes.legende('Dt (# frame)', 'Percentage of good measurements', ''))
def Test_dv(M, frames=None, W=32, display=True, scale=True, type=1, **kwargs): frames = get_frames(M, frames) r = 0. ropt = 0. dU = access.get(M, 'dU', frames[0], Dt=len(frames), compute=False, rescale=False, type=type) for frame in frames: r0, ropt0 = gradient(M, frame, display=False, W=W, scale=scale) r += r0 ropt += ropt0 R = r / len(frames) Ropt = ropt / len(frames) if display: import stephane.display.graphes as graphes dUmin, dUmax = shear_limit(W) xbin, n = graphes.hist(dU, normalize=False, num=200, range=(-0.5, 0.5), **kwargs) #xfactor = Dt maxn = max(n) * 1.2 graphes.graph([dUmin, dUmin], [0, maxn], label='r-', **kwargs) graphes.graph([dUmax, dUmax], [0, maxn], label='r-', **kwargs) graphes.legende('', '', '') print("Percentage of good values (gradient test) : " + str(R) + " %") print("ratio measured shear / optimal value : " + str(Ropt)) #greater than 1 start to be bad return R
def compare_profil(S1, S2): #### DEPRECIATED : move Sdata.subset_index to a new module of smart data indexing #S1 and S2 must be the same length, and the same x and y dimensions #compare velocity measurement obtained with two different frame rate #norm and direction Ux1, Uy1 = fix_PIV(S1) Ux2, Uy2 = fix_PIV(S2) U1, theta1 = Smath.cart2pol(Ux1, Uy1) U2, theta2 = Smath.cart2pol(Ux2, Uy2) print(U2.shape) nx, ny, nt = S1.shape() indices1, indices2, nt = subset_index(S1, S2) #locate a subset of identical im_index #indices correspond of the number of the U rows, not to the im_index valeurs # indices,nt=subset_index(S1,S2) U1 = np.reshape(U1[:, :, indices1], nx * ny * nt) U2 = np.reshape(U2[:, :, indices2], nx * ny * nt) #if U1 and U2 have not the same length, #a fraction can be selected using the attr im_index of each one (to use the same list of images) #random extract N = 2000 ind = random.sample(xrange(nx * ny * nt), N) graphes.graph(U1[ind], U2[ind]) xlabel = 'V (m/s) at ' + str(S1.timescale * S1.fps) + ' fps' ylabel = 'V (m/s) at ' + str(S2.timescale * S2.fps) + ' fps' graphes.legende(xlabel, ylabel, '') bounded_velocity(S1, True, 5, 'v') bounded_velocity(S2, True, 5, 'h') raw_input()
def example(): R = 2 Gamma = 5 N = 10**3 path = generate_vortex(R, N) #generation of a vortex ring eps = 0.02 X = [np.asarray([0., 0., z]) for z in np.arange(-10, 10 + eps, eps)] #axis to look at start = time.time() V = velocity_from_line([path], X, Gamma) end = time.time() print("Time elapsed : " + str(end - start) + "s") print("Number of computed values :" + str(np.shape(X)[0])) V_th = B_along_axis(X, R, Gamma) x = np.asarray(X) display_profile(x, V, label='ks') graphes.graph(x[:, 2], V_th, label='r.-', fignum=1)
def divergence(S, xlines, ylines, display=False): """ DEPRECIATED : was used to compute the asymetry of the flow """ #xlines list of tuple ?? #take two points (symmetric in respect to X=0?), and mesure the relative distance between each #as a function of time #relative means in respect to the spatial averaged velocity at the time t = S.t Dt = 10 ny, nx, nt = S.shape() U_moy, U_std = mean_profile(S, label='k^', display=False) n = len(xlines) Ds = np.zeros((ny, nx, nt - 2 * Dt)) #first element is centered ! for i in ylines: for pair in xlines: dx = S.Ux[i, pair[0], :] + S.Ux[i, pair[1], :] #antisymetric x profile ? dy = S.Uy[i, pair[0], :] - S.Uy[i, pair[1], :] D, phi = Smath.cart2pol(dx, dy) #Divide by the global average velocity at each time !! Ds[ylines.index(i), pair[0], :] = smooth(D, Dt) #=smooth(D/U_moy,Dt) Ds[ylines.index(i), pair[1], :] = Ds[i, pair[0], :] if display: graphes.graph(t[Dt:-Dt], Ds) graphes.legende( 't (ms)', 'V (m/s)', 'Velocity difference between two symetric points') return Ds