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 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 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 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 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)
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 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 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 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 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 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 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 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 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)) if display: sigma, center, figs = fit_core_size(x, y, Z[..., i_example], fignum=fignum, display=display) 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') else: fit_core_size(x, y, Z[..., i_example], fignum=fignum, display=False) return lc, std_lc
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 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 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 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 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 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 tangle_vs_t(fileList): # fileList = glob.glob(Directory+'*.tangle') print('Number of fileList : ' + str(len(fileList))) indice = np.arange(0, 700, 1) for i, file in enumerate(fileList): if i in indice: print(i) T = path.load_tangle(file) L = T.total_length() L, epsilon = example_tangle(T, n=7, d=3) graphes.graph([indice[i]], [L], fignum=1, label='ko') graphes.graph([indice[i]], [epsilon], fignum=2, label='r^')
def average_global(list_corr, field, key='t', fignum=1): # mean is a linear operator. average first on each realization then on the realizations X = [] C = [] for dict_corr in list_corr: dict_corr = average(dict_corr, field, key=key) X.append(dict_corr[('moy', key + '_' + field)]) C.append(dict_corr[('moy', 'C_' + field)]) Cmoy = np.nanmean(np.asarray(C), axis=0) X = np.nanmean(np.asarray(X), axis=0) graphes.graph(X, Cmoy, label='r-', fignum=fignum) n = len(list_corr) graphes.plt.title('Ensemble average over ' + str(n) + ' realizations')
def compare_profil(S1, S2): raise RuntimeError( 'This function is depricated: move Sdata.subset_index to a new module of smart data indexing' ) #### 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 vertical_profile(S, xlines, Dt, start=0): """ Parameters ---------- S xlines Dt start Returns ------- """ 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 detect_start(X, start, fileCine, epsilon=10, Dt=10): # start at the beginning : measure the average on the first ten images vstart = np.mean(X[:Dt]) + epsilon # endwhen the motion is the stronger indmax = np.argmax(X) vend = np.mean(X[indmax - Dt / 2:indmax + Dt / 2]) # geometrical average lim = sqrt(vstart * vend) lbound = 2400 lim = max([lim, lbound]) if np.isnan(lim): lim = lbound # lim=2000 print('Threshold : ' + str(lim)) indices = np.where(X > lim) # print(np.shape(indices)) # np.extract : find the first indices satisfying this condition im0 = indices[0][0] + start val = np.max(X) index = np.arange(len(X)) + start title = fileCine graphes.graph(index, X, True) graphes.graph([im0, im0], [0, val], False, 'r-') graphes.legende('t (# image)', 'grid motion (a.u.)', title) valid = '' # valid=input('Confirm ?') if valid == '': print('ok') else: valid = input('Confirm ?') if not valid == '': print('Origin of time arbitrary set to 0') im0 = 0 return im0
def time_corr(data, param, N=800, outdir='/Users/npmitchell/Dropbox/Soft_Matter/turbulence/jhtd/'): """ Parameters ---------- data param N Returns ------- """ 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=outdir + 'corr_functions/', suffix='', prefix='', frmt='pdf', dpi=300)
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 turbulence.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 compute_tc(Mlist, Corr_fun, fields, log=True): M = Mlist[0] labels = ['ro', 'k^'] s = '' figs = {} for i, field in enumerate(fields): C = Corr_fun[field] t = [] tau = [] for tup in C: tc = tup[1] C_norm = tup[2] N = len(C_norm) / 2 ind1 = np.argmin(np.abs(C_norm[N + 1] / 2. - C_norm[1:N])) ind2 = np.argmin(np.abs(C_norm[N + 1] / 2. - C_norm[N:])) tau.append(tc[ind2 + N] - tc[ind1]) t.append(tc[N]) if log: graphes.graphloglog(t, tau, fignum=1, label=labels[i]) # graphes.set_axis(min(t),max(t),min(t),0.1) else: graphes.graph(t, tau, fignum=1, label=labels[i]) graphes.set_axis(0, 0.4, 0, 0.1) s = s + field + ', ' figs.update(graphes.legende('t (s)', 't_c (s)', s[:-2])) name = 'fx_' + str(int(np.floor(M.fx * 1000))) + 'm' graphes.save_figs(figs, prefix='./Stat_avg/Time_correlation/Overview/' + field + '/' + name, dpi=300, display=True, frmt='png')
def display_corr_vs_t(M, dlist, indices, step=100, Dt=1, label='-', display=False, fignum=1): """ Parameters ---------- M dlist indices step Dt label display fignum Returns ------- """ 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