Esempio n. 1
0
def amplitude(M,i,field='omega',display=False):
    
    xmin,xmax,ymin,ymax = positions(M,i,field='omega',display=False)

    Zfilt = smoothing(M,i,field='omega',sigma=3.)    

    x = M.x[0,:]
    y = -M.y[:,0]
    dx = M.x[0,1]-M.x[0,0]    
    Omegai = interpolate.RectBivariateSpline(y, x, Zfilt,kx=3,ky=3)
    
    U,d = vgradient.make_Nvec(M,i)   # Z : d+1 dimension np array 
    b0 = 10.
    
    imin,imax,jmin,jmax,Zfilt,X,Y = position_index(M,i,field=field,display=display)
    
    tau1 = strain.strain_tensor_loc(U,imin,jmin,d,b=b0)
    tau2 = strain.strain_tensor_loc(U,imax,jmax,d,b=b0)
    
    G = []
    for tau in [tau1,tau2]:
        omega,enstrophy = strain.vorticity(tau,d=2,norm=False)
        div = strain.divergence_2d(tau,d=2)
        G.append((omega[0,0]) * np.pi*b0**2*dx**2)  #-div[0,0]

#    divergence.append(div[0,0]/np.abs(omega[0,0]))
    val_min = Omegai(-ymin,xmin)
    val_max = Omegai(-ymax,xmax)
    
    return val_min[0,0],val_max[0,0],G
Esempio n. 2
0
def compute_vorticity(M, i):
    """
    
    """
    U = M.Ux[..., i]
    V = M.Uy[..., i]

    X = M.x
    Y = M.y

    x = M.x[0, :]
    y = M.y[:, 0]

    n = 3
    Xp, Yp = np.meshgrid(x[n:-n], y[n:-n])

    dx = np.mean(np.diff(x))

    dimensions = np.shape(U) + (2, )
    Z = np.reshape(np.transpose([V, U], (1, 2, 0)), dimensions)
    dZ = strain_tensor.strain_tensor(Z, d=2)
    omega, enstrophy = strain_tensor.vorticity(dZ, d=2, norm=False)

    omega = omega / dx

    return Xp, Yp, omega
Esempio n. 3
0
def circulation_2(M, i, fignum=1, display=False):

    Omega = access.get(M, 'omega', i)
    x, y = space_axis_vorticity(M)

    X, Y, data, center, factor = normalize(x, y, Omega[..., 0])

    dx = M.x[0, 1] - M.x[0, 0]
    #print(dx)

    U, d = vgradient.make_Nvec(M, i)  # Z : d+1 dimension np array

    nx, ny = X.shape
    R_list = np.arange(1., 15., 0.5)
    Gamma = []
    divergence = []
    for b in R_list:
        # print(b)
        tau = strain_tensor.strain_tensor_loc(U,
                                              center[0],
                                              center[1],
                                              d=2,
                                              b=b)
        omega, enstrophy = strain_tensor.vorticity(tau, d=2, norm=False)
        div = strain_tensor.divergence_2d(tau, d=2)
        G = (omega[0, 0] - div[0, 0]) * np.pi * b**2 * dx**2
        Gamma.append(G)
        divergence.append(div[0, 0] / np.abs(omega[0, 0]))

    R_list = np.asarray(R_list) * dx

    if display:
        graphes.graph(R_list, Gamma, fignum=fignum, label='bo')
        graphes.legende('r (mm)', 'Circulation (mm^2/s)', '')

        graphes.graph(R_list, divergence, fignum=fignum + 1, label='ko')
        graphes.graph(R_list,
                      np.zeros(len(R_list)),
                      fignum=fignum + 1,
                      label='r--')

        graphes.legende('r (mm)', 'Relative 2d divergence', '')
        graphes.set_axis(0, 30 * dx, -0.3, 0.3)

    return R_list, Gamma, center, factor
Esempio n. 4
0
def vorticity_field(M, i, step=1, type=2, rescale=False):
    """
    Compute the vorticity field using the stephane.jhtd.strain_tensor module
    INPUT
    -----
    M : Mdata set object
        Contain the data, either 2d or 3d in space 
    i : int
        index in time. Could be removed to compute the strain tensor both in space and time        
    OUTPUT
    -----
    omega : np array of dimension (nx-6,ny-6)
        vorticity field
    name : str
        name of the field to add to the dataset
    """
    d = len(M.shape()) - 1
    dZ, field = dU_field(M, i, step=step, type=type, rescale=rescale)
    omega, enstrophy = strain_tensor.vorticity(dZ, d=d, norm=False)
    return omega, 'omega'
Esempio n. 5
0
def vortex_maps(x, y, Z, dx=1, display_map=False):
    dZ1 = strain_tensor.strain_tensor(Z, d=2) / dx

    blist = np.arange(0.5, 6., 0.5)
    b0 = 2.5
    dZ2 = {}
    for b in blist:
        print('Compute vorticity with r=' + str(b))
        dZ2[b] = strain_tensor.strain_tensor_C(Z, d=2, b=b) / dx

    omega1, enstrophy2 = strain_tensor.vorticity(dZ1, d=2, norm=False)
    omega2, enstrophy2 = strain_tensor.vorticity(dZ2[b0], d=2, norm=False)

    eigen1 = strain_tensor.Lambda(dZ1, d=2)
    eigen2 = strain_tensor.Lambda(dZ2[b0], d=2)

    strain1 = np.sqrt(
        np.power(eigen1['Lambda_0'], 2) + np.power(eigen1['Lambda_1'], 2))
    strain2 = np.sqrt(
        np.power(eigen2['Lambda_0'], 2) + np.power(eigen2['Lambda_1'], 2))

    figs = {}
    #    dimensions = np.shape(omega1)

    #graphes.hist(np.reshape(omega,np.prod(dimensions)),fignum=1)
    #figs.update(graphes.legende('vorticity (s^-1)','PDF',''))

    #    graphes.set_axis(-2.5,2.5,0,40000)
    n = 3
    Xp1, Yp1 = np.meshgrid(x[n:-n], y[n:-n])
    Xp2, Yp2 = np.meshgrid(x, y)

    if display_map:
        for i in range(2):
            for j in range(2):
                graphes.color_plot(Xp1,
                                   Yp1,
                                   dZ1[..., i, j],
                                   fignum=i + j * 2 + 2)
                graphes.colorbar()
                title = 'dU_' + str(i) + '/x_' + str(j)
                figs.update(graphes.legende('X', 'Y', title, cplot=True))

        graphes.cla(6)
        graphes.color_plot(Xp1, Yp1, -omega1, fignum=6)
        graphes.colorbar()
        figs.update(graphes.legende('X', 'Y', 'Vorticity', cplot=True))

        graphes.color_plot(Xp1, Yp1, strain1, fignum=7)
        graphes.colorbar()
        figs.update(graphes.legende('X', 'Y', 'Strain', cplot=True))

        #dissipation
        dissipation1 = np.sum(np.power(dZ1, 2), axis=(2, 3))
        graphes.color_plot(Xp1, Yp1, dissipation1, fignum=8)
        graphes.colorbar()
        figs.update(graphes.legende('X', 'Y', 'Dissipation', cplot=True))

    i1 = Xp1.shape[0] // 2
    i2 = Xp2.shape[0] // 2

    Xp = Xp2[i2, :]
    omega_th = profile_omega(Xp, sigma=2.)
    graphes.graph(Xp1[i1, :], omega1[i1, :], label='b-', fignum=9)
    graphes.graph(Xp2[i2, :], omega2[i2, :], label='k-', fignum=9)
    graphes.graph(Xp, omega_th, label='r--', fignum=9)
    graphes.legende('r', 'vorticity', 'Radial vorticity profile')

    graphes.graph(Xp1[i1, :], strain1[i1, :], label='b.-', fignum=10)
    graphes.graph(Xp2[i2, :], strain2[i2, :], label='k^-', fignum=10)
    graphes.legende('r--', 'strain', 'Radial strain profile')

    j2 = Xp2.shape[1] // 2
    for b in blist:
        omega2, enstrophy2 = strain_tensor.vorticity(dZ2[b], d=2, norm=False)
        graphes.graph(Xp2[i2, :], omega2[i2, :], label='k-', fignum=11)
        graphes.legende('r', 'vorticity',
                        'Radial vorticity profile, various b')

        graphes.graph([b], [omega2[i2, j2]], label='k^', fignum=12)
        graphes.legende('Circle radius r (in box unit)', 'max. vorticity',
                        'Influence of contour size')

    print(Xp.shape)
    print(Xp2.shape)

    #    graphes.color_plot(X,Y,R,fignum=3,vmin=0,vmax=10)
    print(figs)
    return figs
Esempio n. 6
0
def profile_avg(Mlist,i,display=False,fignum=1):
    field = 'omega'
    
    R_list=np.arange(0.25,15.,0.25)
    R = np.arange(0.,15.,0.25)
    n = len(Mlist)
    
    figs = {}
    Gamma = np.zeros((n,len(R),2))
    Flux = np.zeros((n,len(R),2))
    
    for k,M in enumerate(Mlist):
        x = M.x[0,5:]
        y = -M.y[:,0]
        dx = M.x[0,1]-M.x[0,0]
        
        U,d = vgradient.make_Nvec(M,i)   # Z : d+1 dimension np array 
        
        imin,imax,jmin,jmax,Zfilt,X,Y = position_index(M,i,field=field,display=display)
        
        G = [[] for j in range(len(R_list)+1)]
        G[0].append(0)
        G[0].append(0)

        D = [[] for j in range(len(R_list)+1)]
        D[0].append(0)
        D[0].append(0)
        
        for j,b in enumerate(R_list):
            tau1 = strain.strain_tensor_loc(U,imin,jmin,d,b=b)
            tau2 = strain.strain_tensor_loc(U,imax,jmax,d,b=b)
    
            for tau in [tau1,tau2]:
                omega,enstrophy = strain.vorticity(tau,d=2,norm=False)
                div = strain.divergence_2d(tau,d=2)
                G[j+1].append((omega[0,0]) * np.pi*b**2*dx**2)  #-div[0,0]
                D[j+1].append((div[0,0]) * np.pi*b**2*dx**2)  #-div[0,0]
                
        Gamma[k,...] = np.asarray(G)
        Flux[k,...] = np.asarray(D)
        
        graphes.graph(R,-Gamma[k,:,0],label = 'kv',fignum=fignum*2)
        graphes.graph(R,Gamma[k,:,1],label = 'k^',fignum=fignum*2)
        
        graphes.graph(R,Flux[k,:,0],label = 'kv',fignum=fignum*2+1)
        graphes.graph(R,Flux[k,:,1],label = 'k^',fignum=fignum*2+1)
        
    
    Gamma_moy = np.nanmean(Gamma,axis=0)
    Flux_moy = np.nanmean(Flux,axis=0)
    
    
    graphes.graph(R,-Gamma_moy[:,0],label = 'r--',fignum=fignum*2)
    graphes.graph(R,Gamma_moy[:,1],label = 'r--',fignum=fignum*2)
    graphes.graph(R,np.nanmean(np.asarray([Gamma_moy[:,1],-Gamma_moy[:,0]]),axis=0),label = 'rs',fignum=fignum*2)
    figs.update(graphes.legende('Distance to center (mm)','Circulation (mm^2/s)',''))
    
    graphes.graph(R,Flux_moy[:,0],label = 'r--',fignum=fignum*2+1)
    graphes.graph(R,Flux_moy[:,1],label = 'r--',fignum=fignum*2+1)
    graphes.graph(R,np.nanmean(np.asarray([Flux_moy[:,1],Flux_moy[:,0]]),axis=0),label = 'rs',fignum=fignum*2+1)
    figs.update(graphes.legende('Distance to center (mm)','Divergence (mm^2/s)',''))
    
    savedir = title(Mlist[0])    
    graphes.save_figs(figs,savedir=savedir,suffix='',prefix='frame_'+str(i),frmt='pdf',dpi=300,display=True)
    
    M_profile = np.nanmean(np.asarray([Gamma_moy[:,1],-Gamma_moy[:,0]]),axis=0)
    return np.mean(M_profile[-10:]),np.std(Gamma[:,-10:,1])
Esempio n. 7
0
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)