def mean_flow(M_log): # compute the mean flow by averaging the flow on the 5 movies and 10 times steps (more or less depending on the time ratio !!) Ux = [] Uy = [] M_ref = M_log[0] # X=M_ref.x # Y=M_ref.y t = M_ref.t Etot = [] for tp in range(len(t)): Umoy, Vmoy = average(M_log, tp) E = np.sqrt(Umoy**2 + Vmoy**2) Etot.append(np.nanmean(E)) print(np.nanmean(E)) # graphes.color_plot(X,Y,E,fignum=3) Ux.append(Umoy) Uy.append(Umoy) graphes.graph(t, Etot, fignum=-1, label='k^') graphes.legende('$t$ (s)', '$\sqrt{<E_c>}$ (mm/s)', '') graphes.graphloglog(t, Etot, fignum=-1, label='k^') graphes.legende('$t$ (s)', '$\sqrt{<E_c>}$ (mm/s)', '') return Ux, Uy
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 horizontal_profile(S, ylines, Dt, start=0): """ Parameters ---------- S ylines Dt start Returns ------- """ 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 velocity_distribution(M, start, end, display=False): # compute the distribution of velocity for Ux, Uy and U for all the individual measurements between start and end # substract the mean flow in each point M = cdata.rm_nan(M, 'Ux') M = cdata.rm_nan(M, 'Uy') (nx, ny, n) = M.shape() nt = end - start Ux = np.reshape(M.Ux[:, :, start:end], (nx * ny * nt, )) Uy = np.reshape(M.Uy[:, :, start:end], (nx * ny * nt, )) Ux_rms = np.std(Ux) Uy_rms = np.std(Uy) Ux_moy = np.reshape(np.mean(M.Ux[:, :, start:end], axis=2), (nx, ny, 1)) Uy_moy = np.reshape(np.mean(M.Uy[:, :, start:end], axis=2), (nx, ny, 1)) Ux_m = np.reshape(np.dot(Ux_moy, np.ones((1, 1, nt))), (nx, ny, nt)) Uy_m = np.reshape(np.dot(Uy_moy, np.ones((1, 1, nt))), (nx, ny, nt)) # Ux=np.reshape(M.Ux[:,:,start:end]-Ux_m,(nx*ny*nt,)) # Uy=np.reshape(M.Uy[:,:,start:end]-Uy_m,(nx*ny*nt,)) Ux = np.reshape(M.Ux[:, :, start:end], (nx * ny * nt, )) Uy = np.reshape(M.Uy[:, :, start:end], (nx * ny * nt, )) # U_s=np.zeros(len(Ux)+len(Uy)) U_s = np.concatenate((Ux, Uy)) # U=np.sqrt(Ux**2+Uy**2) # normalized by the RMS velocity : Uxt_rms = np.std(Ux) Uyt_rms = np.std(Uy) U_rms = np.std(U_s) print('RMS velocity : ' + str(U_rms) + ' m/s') mid = (start + end) / 2 # Normalisation by the temporal decay function Nvec = (M.t[mid] / 100)**(-1) Nvec = 1 if display: print(max(U_s)) print(min(U_s)) print(U_s.shape) print(Nvec) # graphes.hist(Ux,Nvec,0,100,'o') # graphes.hist(Uy,Nvec,0,100,'s') graphes.hist(U_s, Nvec, fignum=1, num=10**4, label='o') title = '' # title='Z= '+str(M.param.Zplane)+' mm, t='+str(M.t[mid])+' ms'+', Dt = '+str(nt*M.ft)+' ms' graphes.legende('$U_{x,y} (m/s)$', '$pdf(U)$', title) # fields={'Z':'Zplane','t',} # graphes.set_title(M,fields) return Ux_rms, Uy_rms, Uxt_rms, Uyt_rms
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 detect_start(t, X, threshold, display=False): # initial velocity : average on Dt points Dt = 10 vstart = np.mean(X[:Dt]) # endwhen the motion is the stronger indmax = np.argmax(X) vmax = np.max(X) vend = np.mean(X[indmax - Dt / 2:indmax + Dt / 2]) # geometrical average lim = np.sqrt(vstart * vend) lbound = 0.02 # in mn/s if np.isnan(lim): lim = lbound # lim=2000 # print(lim) indices = np.where(X > lim) # print(np.shape(indices)) # np.extract : find the first indices satisfying this condition if not (indices[0].size == 0): ind0 = indices[0][0] else: ind0 = np.argmax(t) t0 = t[ind0] if display: graphes.graph([t0, t0], [0, vmax], False, 'r-') graphes.legende('t (ms)', 'U (m/s)', '') return t0, vmax
def divergence(S, xlines, ylines, display=False): # 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
def compare_measure(M1, M2): indices1_t, indices2_t, nt = match.time(M1, M2) indices1_xy, indices2_xy, nt = match.space(M1, M2) for tup1 in indices1_xy: Ux1 = M1.Ux[tup1[0], tup1[1], indices1_t] Uy1 = M1.Ux[tup1[0], tup1[1], indices1_t] tup2 = indices2_xy[indices1_xy.index(tup1)] print(tup2[0]) print(tup2[1]) Ux2 = M2.Ux[tup2[0], tup2[1], indices2_t] Uy2 = M2.Uy[tup2[0], tup2[1], indices2_t] t1 = str(type(M1)) t2 = str(type(M2)) name1 = browse.get_string(t1, 'Mdata_', '.') name2 = browse.get_string(t2, 'Mdata_', '.') title = name1 + ' vs ' + name2 graphes.graph(Ux1, Ux2, 1, 'ro') graphes.legende('$Ux $', '$Ux$', title) graphes.graph(Uy1, Uy2, 2, 'ro') graphes.legende('$Uy $', '$Uy$', title) plt.pause(10)
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 initial_shape(offset=0): zmin = -500 + offset zmax = 500 + offset # Dz = 45 dz = 1 z = np.arange(zmin, zmax, dz) Dz = 200 U0 = 2.5 * 10**3 delta = 10. U1 = U0 * np.exp(-Dz / delta) # delta = Dz / np.log(U0/U1) z0 = 0 + offset z1 = Dz + offset U = np.zeros(len(z)) for i, zi in enumerate(z): if zi < z0: U[i] = U0 if zi >= z0 and zi < z1: U[i] = U0 * np.exp((z0 - zi) / delta) if zi >= z1: U[i] = U0 * np.exp(-Dz / delta) graphes.semilogy(z, U, label='r') graphes.legende('z (mm)', 'U (mm/s)', '') graphes.set_axis(-50, 150, 10**0, 5 * 10**3) return z, U
def stat_corr_t(M, t, Dt=20, axes=['Ux', 'Ux'], p=1, display=False, label='k^', fignum=0): """ Parameters ---------- M t Dt axes p display label fignum Returns ------- X, Y, Yerr """ t0 = M.t[t] tlist = range(t - Dt // 2, t + Dt // 2) curves = [] for t in tlist: curves.append(corr_v_t([M], t, N=20, axes=axes, p=p, display=False)) X, Y, Yerr = statP.box_average(curves, 50) X = X[~np.isnan(X)] Y = Y[~np.isnan(Y)] Yerr = Yerr[~np.isnan(Yerr)] if display: # graphes.set_fig(1) graphes.errorbar(np.abs(X) / t0, Y, X * 0, Yerr, fignum=fignum, label=label) graphes.legende('$t/u^{2m}$', '$C_t$', '$m=1/2$') name = 'Corr_' + axes[0] + '_' + axes[1] + '_' + str(t) filename = './Corr_functions/' + M.id.date + '/' + M.id.get_id( ) + '/' + name + '.txt' keys = ['t', name] List_info = [np.ndarray.tolist(X), np.ndarray.tolist(Y)] rw_data.write_dictionnary(filename, keys, List_info, delimiter='\t') # print(X) # print(Y) return X, Y, Yerr
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 ?) Parameters ---------- S i j direction label display Returns ------- """ # 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 detect_max(t, X, display=False): vmax = np.max(X) indmax = np.argmax(X) tmax = t[indmax] if display: graphes.graph([tmax, tmax], [0, vmax], False, 'r-') graphes.legende('t (ms)', 'U (m/s)', '') return tmax, vmax
def make_plot_lin(Mlist, Range=None, color='k', label=None, field=[['Ux', 'Uy'], ['omega']], Dirbase=None, Dt=1, example=False, total=True, fignum=1, save=True): M = Mlist[0] if Dirbase == None: Dirbase = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/PIV_data/Test6/' # local saving Dirbase = './Stat_avg/Panel/' + M.Id.date axes = panel_graphs(M, subplot=[2, 3], fignum=fignum) frames = select_range(M, Range) 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)) + '/' figs.update(plot_scales(Mlist, axes, fignum=fignum, color=color, label=label)) plt.sca(axes[2]) frame = 1500 Dt = 1400 if label is None: labels = ['m^', 'b>', 'ko'] else: labels = [label, label, label] for i, f in enumerate(field[0]): # should contain either one or two fields figs.update(graphes.pdf_ensemble(Mlist, f, frame, Dt=Dt, fignum=fignum, label=labels[i], norm=False)) figs.update(graphes.legende(f, 'pdf of ' + f, '')) plt.sca(axes[3]) for f in field[1]: figs.update(graphes.pdf_ensemble(Mlist, f, frame, Dt=Dt, fignum=fignum, label=labels[2], norm=False)) figs.update(graphes.legende(f, 'pdf of ' + f, '')) plt.sca(axes[4]) corr.corr_v_t(Mlist, frame, axes=['Ux', 'Ux'], N=200, p=1, display=True, save=False, label=labels[0], fignum=fignum) corr.corr_v_t(Mlist, frame, axes=['Uy', 'Uy'], N=200, p=1, display=True, save=False, label=labels[1], fignum=fignum) plt.sca(axes[5]) corr.corr_v_t(Mlist, frame, axes=['omega', 'omega'], N=200, p=1, display=True, save=False, label=labels[2], fignum=fignum) if save: graphes.save_figs(figs, savedir=Dirname, prefix='General', suffix='_vs_t', dpi=300, frmt='png', display=True) else: return figs, Dirname
def get_cine_time(file, display=False): c = cine.Cine(file) # something gets wrong with the computation of the cine length n = c.len() print('Number of images : ' + str(n)) times = np.asarray([c.get_time(i) for i in range(n)]) if display: graphes.graphloglog(times[1:], np.diff(times), label='k') graphes.legende('t (s)', 'Dt (s)', file) return times
def Sp(Mlist, t, Dt=50, axe=['Ux', 'Uy'], label='k', p=1): # dlist=range(1,int(max(M.shape())/2),10) dlist = [1, 2, 3, 5, 8, 10, 15, 20, 25, 50] indices = [[] for i in range(len(dlist))] M = Mlist[0] dim = M.shape() n = np.prod(dim[:-1]) N = 2 * n # 10**3 # print('Compute indices lists') for i, d in enumerate(dlist): indices[i] = corr.d_2pts_rand(M.x, d, N) # print('done') figs = {} for i, ind in enumerate(indices): print("d = " + str(dlist[i])) graphes.cla(i * 2 + 1) graphes.cla(i * 2 + 2) C_t = [] C_n = [] # print(dlist[i]) for M in Mlist: # print(M.shape()) Ct, Cn = diff(M, t, ind, Dt=Dt, axe=axe, p=p) graphes.distribution(Cn, label=label, normfactor=1, fignum=i * 2 + 1, norm=False) figs.update(graphes.legende('C_n', 'PDF C_n, d' + str(dlist[i]), '')) graphes.distribution(Ct, label=label, normfactor=1, fignum=i * 2 + 2, norm=False) figs.update(graphes.legende('C_t', 'PDF C_t, d' + str(dlist[i]), '')) C_t = C_t + Ct C_n = C_n + Cn n_ensemble = len(Mlist) if n_ensemble > 1: graphes.distribution(C_n, label='r', normfactor=n_ensemble, fignum=i * 2 + 1, norm=False) figs.update(graphes.legende('C_n', 'PDF C_n, d' + str(dlist[i]), '')) graphes.distribution(C_t, label='r', normfactor=n_ensemble, fignum=i * 2 + 2, norm=False) figs.update(graphes.legende('C_t', 'PDF C_t, d' + str(dlist[i]), '')) # graphes.distribution(C_t,label='r',normfactor=len(Mlist),fignum=i+2,norm=False) # graphes.distribution(C_t,normfactor=1,fignum=i,norm=False) return figs
def main(): file = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/Set_time_scale/Logtime_movies/setup1_Dt_fps10000_n7000_Beta_1m.cine' times = get_cine_time(file) Dt = (times[1:] - times[:-1]) * 1000 times = times[:-1] print(Dt) print(times) graphes.graphloglog(times, Dt, fignum=1, label='b^') graphes.legende('t (s)', 'Dt (ms)', '') compare_logtime(1)
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 isotropy(M, label='k^--', display=True, fignum=1): '''for each time, compute the distribution of angles (!) in horizontal plane at a very earlier time, should be peaked along x and y directions. Then spread in box directions. Compute that from 5000 or 10000fps movies ''' 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 time_correlation(Mlist, indices=None, display=False): """ Compute the spatial averaged time of velocity autocorrelation Velocity autocorrelation functions in time are fitted by an exponential in time. Typical time tc gives the time correlation Parameters ---------- Mlist : list of Mdata indices : list of int indices of Mlist elements to process. default value process all the elements display : bool default value False OUTPUT ----- tf : tau : for each time in ft, timescale over which correlation is reduced to 1/e, on average """ if indices is None: indices = range(len(Mlist)) labels = ['k^', 'ro', 'bp', 'c8', 'g*'] for i, indice in enumerate(indices): label = labels[i] M = Mlist[indice] tf, tau = compute_Ct(M, display=False, label='ko', fignum=1) graphes.graphloglog(tf, tau, fignum=9, label=label) graphes.legende('$t (s)$', '$\tau (s)$', '') # compute from the # t_d,E = decay.decay(M,label=label) t_d, E = Fourier.display_fft_vs_t(M, '1d', Dt=50, label=label) Ef = np.zeros(len(tf)) for i, t in enumerate(tf): j = np.argmin(abs(t_d - t)) # print(str(j)+ ' : '+str(E[j]) + ", " + str(tau[i])) Ef[i] = E[j] graphes.graphloglog(Ef, tau, fignum=10, label=label) graphes.legende('$E (m^2/s^2)$', '$\tau (s)$', '') return tf, tau
def log_time_step(Dt, alpha, n): # Dt in ms # alpha : power coefficient , close to 1. greater than 1 means increasing time step # n : number of images Dt_list = [Dt * alpha**i for i in range(n)] Dt_array = np.asarray(Dt_list) Dt_array = np.floor(Dt_array / Dt) * Dt # graphes.graph(np.arange(1,n+1),Dt_array,label='r+') # graphes.legende('# of image','Dt (ms)','') t = np.cumsum(Dt_array) / 1000 # t in s graphes.graphloglog(t, Dt_array, 1, label='r+') graphes.legende('t (s)', 'Dt (ms)', '')
def measure_anisotropy(fileDir, t0, fpms): fileList, n = get_fileList(fileDir, 'npz') I = [] for name in fileList: S = np.load(name) # print(name) I0 = anisotropy(S) I.append(I0) # default fps is 1000fps in PIV parameters files ft = 1. / fpms t = np.arange(t0, t0 + n * ft, ft) graphes.graphloglog(t, U, label) graphes.legende('t (ms)', 'I (norm.)', '') print(str(max(t)) + ' ' + str(max(U)))
def spatial_decay(M, field='E', indices=None): from mpl_toolkits.axes_grid.inset_locator import inset_axes import stephane.vortex.track as track fields, names, vmin, vmax, labels, units = std_fields() j = fields.index(field) Z = np.nanmean(getattr(M, field)[..., indices], axis=2) X, Y = [], [] for i in indices: tup = track.positions(M, i, field=field, indices=indices, step=1, sigma=10.) X.append(tup[1]) Y.append(tup[3]) X0, Y0 = np.nanmean(X), np.nanmean(Y) R, Theta = Smath.cart2pol(M.x - X0, M.y - Y0) R0 = M.param.Diameter Z_flat = np.ndarray.flatten(Z) R_flat = np.ndarray.flatten(R) Theta_flat = np.ndarray.flatten(Theta) phi = np.pi / 2 C = np.mod((Theta_flat + phi + np.pi) / 2 / np.pi, 1) cmap = matplotlib.cm.hot color = [matplotlib.colors.rgb2hex(cmap(c)[:3]) for c in C] fig, ax2 = graphes.set_fig(1, subplot=122) fig.set_size_inches(20, 6) ax2.scatter(R_flat, Z_flat, marker='o', facecolor=color, alpha=0.3, lw=0, cmap=cmap) Rth = np.arange(10 ** 1, 10 ** 2, 1.) # graphes.graphloglog(Rth, 10 ** 5 * (Rth / R0) ** -3.2, label='k--') # graphes.graphloglog(Rth, 5 * 10 ** 4 * (Rth / R0) ** -4.5, label='k--') graphes.set_axis(10 ** 0, 10 ** 2, 10 ** 2, 8 * 10 ** 4) figs = graphes.legende('$R$ (mm)', 'Energy (mm$^2$/s$^{2}$)', 'Spatial decay') fig, ax1 = graphes.set_fig(1, subplot=121) graphes.color_plot(M.x, M.y, Z, fignum=1, vmin=0, vmax=40000, subplot=121) graphes.colorbar(label=names[j] + ' (' + units[j] + ')') figs.update(graphes.legende('X (mm)', 'Y (mm)', 'Time averaged ' + field, cplot=True)) inset_ax = inset_axes(ax2, height="50%", width="50%", loc=3) inset_ax.pcolormesh(M.x / 10 - 10, M.y / 10 - 10, Theta, cmap=cmap) inset_ax.axis('off') return figs
def spectrum_2d(M, indices=None): Fourier.compute_spectrum_2d(M, Dt=3) # smooth on 3 time step. S_E = np.nanmean(M.S_E[..., indices], axis=2) graphes.color_plot(M.kx, M.ky, S_E, log=True, fignum=1) graphes.colorbar(label='$E_k$') figs = graphes.legende('$k_x$ (mm)', '$k_y$ (mm)', 'Energy Spectrum (log)') return figs
def distribution(sigma, n, display=False): n_p = 1 theta, N = theta_axis(n, N=None) r0 = 1 base = np.asarray([[r0 * np.cos(k), r0 * np.sin(k), 0] for k in theta]) paths = [] for p in range(n_p): # print(p) t = noise(base, sigma, n) paths.append(t.paths[0]) # h = helicity(t) # graphes.hist(h,fignum=2) if p < 3: savename = './Random_path/Tests/Examples/sigma_' + str( round(sigma * 1000)) + 'm_n' + str(n) + '_' + str(p + 1) save(t, prefix=savename) t_tot = tangle.Tangle(paths) if display: figs = radial_density(t_tot) figs.update(graphes.legende('R', 'PDF(R)', '')) # graphes.save_figs(figs,prefix='Random_path/Tests/R_Distributions/',suffix='_sigma_'+str(round(sigma*1000))+'m',dpi=300,display=True,frmt='png') return t
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): yy = getattr(M, field) yy_k, k = spectrum_1d(yy, M, display=False, Dt=Dt) print(yy_k.shape) else: yy_k = getattr(M, 'S_' + field) k = getattr(M, 'k_' + field) step = max(Dt / 2, 1) N, nt = yy_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, yy_k[:, t], label='k-', fignum=fignum) # graphes.graphloglog(k,yy_k[:,t],label='k-',fignum=fignum) add_theory(k, yy_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 display_fft(m, i, tag): # to be replaced by m.z if hasattr(m.Sdata.param, 'Zplane'): Z = m.Sdata.param.Zplane / 10 else: Z = -10 title = '$Z$ = ' + str(Z) + ' cm, $t$ = ' + str(m.t[i]) + ' ms' Dir = m.fileDir + 'FFT_vs_t_part_' + tag + '_' + m.id.get_id() + '/' if tag == '1d': graphes.legende('$k$ (mm$^{-1}$)', '$E_k$ (a.u.)', title) if tag == '2d': graphes.legende('$k_x$ (mm$^{-1}$)', '$k_y$ (mm$^{-1}$)', title) return None
def test_Dt(W): """ Parameters ---------- W : Returns ------- """ 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_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 spatial_corr(data, N=1024, Dt=10, outdir='/Users/npmitchell/Dropbox/Soft_Matter/turbulence/jhtd/'): """Compute spatial correlation Parameters ---------- data N Dt Returns ------- """ 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=outdir + 'corr_functions/', suffix='', prefix='', frmt='pdf', dpi=300)