Example #1
0
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
Example #2
0
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
Example #3
0
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)
Example #4
0
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
Example #5
0
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    
Example #6
0
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
Example #7
0
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)
Example #8
0
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
Example #9
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
Example #10
0
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
Example #11
0
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)
Example #12
0
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', ''))
Example #13
0
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')
Example #14
0
def from_circulation_1(M, fignum=1, display=True):
    nx, ny, nt = M.shape()

    M, field = vgradient.compute(M, 'vorticity', filter=True)
    Z = getattr(M, field)  #field vorticity : omega

    x, y = space_axis_vorticity(M)

    a = []
    G0 = []
    indices = range(0, nt, 1)
    x0 = []
    y0 = []
    index = []

    Omega = getattr(M, 'omega')

    start = True
    figs = {}
    for i in indices:
        sigma, A, center = fit_core_circulation(M,
                                                fignum=fignum,
                                                display=False)
        #graphes.save_figs(figs,savedir='./Results/'+os.path.basename(M.dataDir)+'/',suffix='_method_circulation_')

        #    print(A)
        if sigma is not None:
            a.append(sigma)
            G0.append(A)
            index.append(i)
            x0.append(center[0])
            y0.append(center[1])

            if start:
                start = False
                xi = x[center[0]]
                yi = y[center[1]]

    r = [np.sqrt((x1 - xi)**2 + (y1 - yi)**2) for x1, y1 in zip(x[x0], y[y0])]
    lc = np.nanmedian(a)
    std_lc = np.nanstd(a)
    Gamma = np.nanmedian(G0)
    std_Gamma = np.nanstd(G0)

    #plot example
    error = 0.5
    if len(index) > 0 and std_lc / lc < error:
        i_example = index[len(index) // 2]
        #        fit_core_circulation(x,y,Omega[...,i_example],fignum=fignum,display=display)
        figs.update(graphes.legende('r (mm)', 'Circulation mm^2/s', ''))

        if display:
            t = np.asarray([M.t[i] for i in index])
            graphes.graph(t, a, label='ro', fignum=fignum + 2)
            title = os.path.basename(M.dataDir)
            graphes.set_axis(np.min(t), np.max(t), 0., 5.)
            figs.update(graphes.legende('t (s)', 'Core size', title))

            graphes.graph(t, G0, label='kp', fignum=fignum + 3)
            graphes.set_axis(np.min(t), np.max(t), -20000, 0)
            figs.update(graphes.legende('t (s)', 'Circulation', title))

            graphes.graph(t, r, label='b+', fignum=fignum + 4)
            graphes.legende('t (s)', 'Position (mm)', title)
            save_graphes(M, figs, method='circulation')

    return lc, std_lc, Gamma, std_Gamma
Example #15
0
def compile(Mlist, V=None, method='circulation'):
    symbol = {'50': '^', '125': 'o', '250': 's'}
    color = {'circulation': 'r', 'vorticity': 'b', 'joseph': 'k'}
    labels = {key: color[method] + symbol[key] for key in symbol.keys()}
    if V == None:
        sub_labels = labels
        piston_v = None
    else:
        piston_v = str(V)
        sub_labels = {piston_v: labels[piston_v]}  #,'125':'ro','250':'bs'}

    figs = {}

    for i, M in enumerate(Mlist):
        piston1 = browse.get_string(M.Sdata.fileCine,
                                    '_v',
                                    end='.cine',
                                    shift=0,
                                    display=False,
                                    from_end=True)
        piston2 = browse.get_string(M.Sdata.fileCine,
                                    '_v',
                                    end='_p30mum',
                                    shift=0,
                                    display=False,
                                    from_end=True)

        error = 0.25
        for piston in [piston1, piston2]:
            if piston in sub_labels.keys():
                print(M.dataDir)
                dx = np.mean(np.diff(M.x[0, :]))
                print('Spatial scale : ' + str(dx) + ' mm/box')
                lc, std_lc, Gamma, std_Gamma = compute(M,
                                                       method=method,
                                                       display=False,
                                                       fignum=(i + 1) * 2)

                #                print(piston,dx,lc,std_lc)
                if std_lc / lc < error:
                    graphes.errorbar(dx,
                                     lc, [0],
                                     std_lc,
                                     label=labels[piston],
                                     fignum=250)
                    figs.update(graphes.legende('mm/box', 'Core size (mm)',
                                                ''))
                    graphes.set_axis(0, 1.5, 0, 6.)

                    if method == 'circulation':
                        #   if np.abs(std_Gamma/Gamma)<error:
                        graphes.errorbar(dx,
                                         Gamma, [0],
                                         std_Gamma,
                                         label=labels[piston],
                                         fignum=251)
                        figs.update(
                            graphes.legende('mm/box', 'Circulation (mm^2/s)',
                                            ''))
                        graphes.set_axis(0, 1.5, -2 * 10**4, 0)
                #print(piston,dx,lc,std_lc
                print('')

    print('figure', figs)
    print(figs)
    graphes.save_figs(figs,
                      suffix='Compilation_method_' + method + '_v' + piston_v)
Example #16
0
def display_profile(M,
                    i,
                    t0,
                    z,
                    Ux_moy,
                    Uy_moy,
                    Ux_rms,
                    Uy_rms,
                    Dt=1,
                    fig=1,
                    logscale=True):
    t = M.t[t0]
    U_noise_low, U_noise_high = check.bounds(M, t0)
    graphes.set_fig(fig)
    title = 't=' + str(int(t * 1000)) + ' ms' + 'Urms_zprofile'

    Dir = M.fileDir + 'Velocity_distribution_log_M_2015_12_28_Meanfield' + '/'

    z, Ux_th = fit_profile(M, t0, z, Ux_rms, p=9, log=True)
    z, Uy_th = fit_profile(M, t0, z, Uy_rms, p=9, log=True)

    #  Ux_adv,Uy_adv = advection(Dt,z,Ux_moy,Uy_moy,Ux_rms,Uy_rms)
    #  print(Ux_adv/Ux_rms)
    #    print(Ux_adv)

    figs = {}
    if logscale:
        #   graphes.semilogx(Ux_rms,z,fignum=0,label='bo--')
        graphes.semilogx(Uy_rms, z, fignum=i, label='k^--')

        graphes.semilogx([U_noise_low, U_noise_low], [-400, -100],
                         fignum=i,
                         label='r--')
        graphes.semilogx([U_noise_high, U_noise_high], [-400, -100],
                         fignum=i,
                         label='r--')

        #   graphes.semilogx(np.sqrt(np.power(Ux_moy,2)),z,fignum=i,label='b+--')
        #   graphes.semilogx(np.sqrt(np.power(Uy_moy,2)),z,fignum=i,label='c ^--')

        graphes.set_axis(10**0, 10**4, -300, -120)
        figs.update(graphes.legende('$U_{rms} (t/t_0)$', '$z$ (m)', ''))
        file = graphes.set_title(M, title)
        filename = Dir + file

    else:
        graphes.graph(Ux_rms, z, fignum=0, label='bo--')
        graphes.graph(Uy_rms, z, fignum=i, label='k^--')

        #   graphes.semilogx(Ux_th,z,fignum=i,label='r-')
        #   graphes.semilogx(Uy_th,z,fignum=i,label='r-')
        graphes.graph([U_noise_low, U_noise_low], [-400, -100],
                      fignum=i,
                      label='r--')
        graphes.graph([U_noise_high, U_noise_high], [-400, -100],
                      fignum=i,
                      label='r--')

        graphes.graph(np.sqrt(np.power(Ux_moy, 2)), z, fignum=i, label='b+--')
        graphes.graph(np.sqrt(np.power(Uy_moy, 2)), z, fignum=i, label='c ^--')

        graphes.set_axis(0, 2.5 * 10**3, -300, -120)
        figs.update(graphes.legende('$U_{rms} (t/t_0)$', '$z$ (m)', ''))
        file = graphes.set_title(M, title)
        filename = Dir + file

        graphes.save_figs(figs,
                          savedir='./Spreading/Stat_average_lin/',
                          suffix='',
                          prefix='2015_12_28_front_' + str(t0),
                          frmt='png')

    return figs
Example #17
0
def spreading(Mlist, logscale=False):
    labels = ['k^', 'ro', 'bs']
    M = Mlist[0]
    nx, ny, nt = M.shape()

    #for i,M in enumerate(Mlist):
    #    vertical_spreading(M,10,Dt=20,label=labels[i])
    print(M.shape())
    frame = range(10, 350, 10)
    Dt = np.asarray(
        [M.t[frame[i]] - M.t[frame[i - 1]] for i in range(1, len(frame))])
    # print(Dt)
    #    Ux_adv = np.zeros(nx)
    #    Uy_adv = np.zeros(ny)

    D = 5 * 10**2
    z_init, U_init = initial_shape(offset=140)

    t_init = 0.026

    for i, t0 in enumerate(frame[:-1]):
        z, Ux_moy, Uy_moy, Ux_rms, Uy_rms = profile_average(Mlist,
                                                            t0,
                                                            Dt=10,
                                                            display=False)

        print(M.t[t0])
        z_dif, U_dif = solve_diffusion(-z_init, U_init, D, M.t[t0] - t_init)

        # print(U_dif)

        if i == 0:
            fx = interp.splrep(z, Ux_rms, s=2)  # kind='cubic')
            fy = interp.splrep(z, Uy_rms,
                               s=2)  # interp1d(z, Ux_rms, kind='cubic')

            Ux_adv = interp.splev(z, fx)
            Uy_adv = interp.splev(z, fy)

        figs = display_profile(Mlist[0],
                               i,
                               t0,
                               z,
                               Ux_moy,
                               Uy_moy,
                               Ux_rms,
                               Uy_rms,
                               Dt=Dt[i],
                               fig=i,
                               logscale=logscale)
        #     Ux_adv,Uy_adv = advection(Dt[i],i,z,Ux_moy,Uy_moy,Ux_adv,Uy_adv,display=True)

        graphes.semilogx(U_dif, z_dif, fignum=i, label='r-')
        graphes.set_axis(10**0, 10**4, -300, -120)

        graphes.save_figs(figs,
                          savedir='./Spreading/Diffusion_noNoise/',
                          suffix='',
                          prefix='2015_12_28_front_' + str(t0),
                          frmt='png')

    figs = {}
    graphes.set_fig(1)
    figs.update(graphes.legende('$t$ (s)', '$Front position z$ (mm)', ''))
    graphes.set_fig(2)
    figs.update(graphes.legende('$t$ (s)', '$Front position z (log)$ (mm)',
                                ''))
    graphes.set_fig(3)
    figs.update(graphes.legende('$t$ (s)', '$U_{rms}$ (mm/s)', ''))

    graphes.save_figs(figs,
                      savedir='./Spreading/',
                      suffix='',
                      prefix='2015_12_28_all_')
Example #18
0
def main(Mlist):
    savedir = title(Mlist[0])    
    
    indices = range(400,2000,10)
    n = len(indices)
    N = len(Mlist)
    print(N)

    figs = {}

    X = np.zeros((N,n,2))
    Y = np.zeros((N,n,2))

    for j,M in enumerate(Mlist):
        print(j)
        Xmin = []
        Xmax = []
        Ymin = []
        Ymax = []
    
        Vmin = []
        Vmax = []
        
        Gammamin = []
        Gammamax = []

        t=[]
        field = 'omega'
        Omega = access.get_all(M,field)
        for i in indices:
            Z = Omega[:,5:,i]
    
            t.append(M.t[i])
    
            xmin,xmax,ymin,ymax = positions(M,i)
        
            vmin,vmax,G = amplitude(M,i)
            Gammamin.append(G[0])
            Gammamax.append(G[1])
  
            Vmin.append(vmin)
            Vmax.append(vmax)
    
            Xmin.append(xmin)
            Xmax.append(xmax)
            Ymin.append(ymin)
            Ymax.append(ymax)
    
        X[j,:,0] = np.asarray(Xmin)
        X[j,:,1] = np.asarray(Xmax)
    
        Y[j,:,0] = np.asarray(Ymin)
        Y[j,:,1] = np.asarray(Ymax)
    
        graphes.graph(t,Xmin,label='bo',fignum=1)
        graphes.graph(t,Xmax,label='ro',fignum=1)
        figs.update(graphes.legende('Time (s)','Horizontal position (mm)',''))
        
        graphes.graph(Xmin,Ymin,label='bo',fignum=2)
        graphes.graph(Xmax,Ymax,label='ro',fignum=2)
        figs.update(graphes.legende('X (mm)','Y(mm)',''))
        
        graphes.graph(t,Vmin,label='b',fignum=3)
        graphes.graph(t,Vmax,label='r',fignum=3)
        figs.update(graphes.legende('Time (s)','Maximum vorticity (s^-1)',''))
        
        graphes.graph(t,Gammamin,label='b',fignum=4)
        graphes.graph(t,Gammamax,label='r',fignum=4)
        figs.update(graphes.legende('Time (s)','Circulation mm^2/s',''))
        graphes.set_axis(0,0.32,-25000,25000)
        
        
    Dx = (X-np.tile(np.nanmean(X,axis=0),(N,1,1)))
    Dy = (Y-np.tile(np.nanmean(Y,axis=0),(N,1,1)))

    D = np.sqrt(Dx**2+Dy**2)

    D_moy = np.nanmean(D,axis=0)
    #print(t)
    #print(D[j,:,1])
#    for j in range(N):
#        graphes.graph(t,D[j,:,0],label='bo',fignum=4)
#        graphes.graph(t,D[j,:,1],label='ro',fignum=4)

    graphes.graph(t,D_moy[:,0],label='b',fignum=6)
    graphes.graph(t,D_moy[:,1],label='r',fignum=6)
    figs.update(graphes.legende('Time (s)','Distance (mm)','Spreading of vortices'))
    graphes.set_axis(0,0.3,0,20)

    graphes.graph(np.power(t,3),np.power(D_moy[:,0],2),label='b',fignum=5)
    graphes.graph(np.power(t,3),np.power(D_moy[:,1],2),label='r',fignum=5)
    graphes.set_axis(0,0.3**3,0,100)

    figs.update(graphes.legende('t^3 (s^3)','d^2 (mm^2)','Spreading of vortices : rescaling'))
    
    
    graphes.save_figs(figs,savedir=savedir,suffix='',prefix='',frmt='pdf',dpi=300,display=True)
    #    fig,axes = panel.make([111],fignum=3+3*j)
    #    fig.set_size_inches(15,15)
    #    i = 1400
    #    graphes.Mplot(M,'enstrophy',i,fignum=3)
    #    graphes.graph(Xmin,Ymin,label='bo',fignum=3+3*j)
    #    graphes.graph(Xmax,Ymax,label='ro',fignum=3+3*j)
Example #19
0
def dispersion(Data,j,savedir):
    tmin = 20
    tmax = 160
    
    accurate = Data['accurate'][j]
    pos = Data['pos'][j]
    Mlist= Data['M'][j]
    A = Data['A'][j]
    
    figs = {}
    graphes
    
    for c,key in enumerate(accurate[0].keys()):
        Y = []
        for i,M in enumerate(Mlist):
            if accurate[i][key]:
                #c+=1
                Y.append(pos[i][key][tmin:tmax])
            else:
                print("not accurate")
        
        Y = np.asarray(Y)
#        print(key)
        t = np.asarray(pos[i]['t'][tmin:tmax])
        graphes.set_fig(1)
        #graphes.errorbar(t,np.nanmean(Y,axis=0),0*t,np.nanstd(Y,axis=0),label='k',fignum=c+4)
#        graphes.graph(t,np.nanstd(Y,axis=0),fignum=1,label=label)
#        graphes.set_axis(0.05,0.45,0,15)
#        figs.update(graphes.legende('Time (s)',key,''))

#        graphes.graph(t**3,np.nanstd(Y,axis=0)**2,fignum=2,label=label)
#        graphes.graph(t**3,1000*t**3,fignum=2,label='r-')
#        graphes.set_axis(0.05**3,0.05,0,70)
#        figs.update(graphes.legende('t^3',key+'^2',''))

        print(A)
        if A==0:
            label='c'
        else:
            label='k-'
            
        if 'X' in key:
            graphes.graphloglog(t,np.nanstd(Y,axis=0),fignum=3,label=label)
            graphes.graphloglog(t,30*t**1.5,fignum=3,label='r--')
          #  graphes.graphloglog(t,8*t**0.5,fignum=3,label='r--')

            graphes.set_axis(0.05,0.6,0.01,50)
            figs.update(graphes.legende('t',key+'',''))

        if 'Y' in key:
#            label='b-'
            graphes.graphloglog(t,np.nanstd(Y,axis=0),fignum=4,label=label)
            graphes.graphloglog(t,30*t**1.5,fignum=4,label='r--')
          #  graphes.graphloglog(t,8*t**0.5,fignum=4,label='r--')
            graphes.set_axis(0.05,0.6,0.01,50)
            figs.update(graphes.legende('t',key+'',''))
            
    #    graphes.graphloglog(t**3,1000*t**3,fignum=2,label='r-')
        #figs.update(graphes.legende('t',key+'',''))
        #print(c)
    return figs
Example #20
0
def profile_1d(M, Dt=10, direction='v', start=20, fignum=1):
    """
    Compute the 1d averaged profile> Averaging is performed along a Dt window in time, and along the specified axis, either 'v' or 'h'
    INPUT
    -----
    M : Mdata object.
    Dt : int. Default 10
        time windows width for the averaging
    direction : string. default 'v'. Only option now
    start : int
        starting index
    fignum : int
        number for the figure output
    OUTPUT
    -----
    Ux,Uy,Ux_std,Uy_std
    """
    dimensions = M.shape()

    if M.param.typeplane == 'vp':
        if M.param.angle == 0.:
            z = M.y[:, 0]
            axis = [1, 0]
        if M.param.angle == 90.:
            z = M.x[0, :]
            axis = [0, 1]
    else:
        z = M.y[:, 0]
        axis = [1, 0]

    for i in range(start, dimensions[2], Dt):
        #averaging over Dt in time, and along one dimension in space
        Ux = np.nanmean(np.nanmean(M.Ux[..., i:i + Dt], axis=2), axis=axis[0])
        Uy = np.nanmean(np.nanmean(M.Uy[..., i:i + Dt], axis=2), axis=axis[0])

        #standard deviation computation
        # print(dimensions[axis[1]])
        #    print(tuple(axis+[Dt]))

        orientation = tuple([axis[0] + 1, axis[1] + 1] + [0])
        Ux_mean = np.asarray(
            np.transpose([[
                dict2list.to_1d_list(Ux) for k in range(dimensions[axis[0]])
            ] for t in range(Dt)], orientation))
        Uy_mean = np.asarray(
            np.transpose([[
                dict2list.to_1d_list(Uy) for k in range(dimensions[axis[0]])
            ] for t in range(Dt)], orientation))

        #        Uy_mean = np.asarray([[dict2list.to_1d_list(Uy) for k in range(dimensions[axis[0]])] for t in range(Dt)],tuple(axis+[Dt]))
        std_Ux = np.sqrt(
            np.mean(np.mean(np.abs(M.Ux[..., i:i + Dt] - Ux_mean)**2, axis=2),
                    axis=axis[0]))
        std_Uy = np.sqrt(
            np.mean(np.mean(np.abs(M.Uy[..., i:i + Dt] - Uy_mean)**2, axis=2),
                    axis=axis[0]))

        graphes.set_fig(0)  #clear current axis
        graphes.graph(z, Ux, label='k^', fignum=fignum)  #,std_Ux)
        graphes.graph(z, Uy, label='ro', fignum=fignum)  #,std_Ux)
        graphes.set_axis(-400, -100, -100, 100)

        fig = graphes.legende('z (mm)', 'V_{rms} (mm/s)', 'Ux, Uy')

        filename = './Results/Mean_profile_' + M.id.get_id(
        ) + '/' + fig[fignum] + '_t_' + str(i)
        # print(filename)

        graphes.save_fig(fignum, filename, frmt='png')


#        graphes.graph(z,Uy,std_Uy)
#        graphes.legende('z (m)','V (m/s)','Uy')
#  raw_input()

    return Ux, Uy, std_Ux, std_Uy
Example #21
0
def display_fft_vs_t(m,
                     dimension='1d',
                     Dt=20,
                     fignum=0,
                     label='^',
                     display=False):
    display_part = True
    #  plt.close(1)
    if dimension == '1d':
        S_k_2d, kx, ky = energy_spectrum_2d(m, Dt=Dt)
        S_k, k = energy_spectrum_1d(m, Dt=Dt)
    if dimension == '2d':
        S_k, kx, ky = energy_spectrum_2d(m, Dt=Dt)
#    start=580
#    end=700
#    step=10
#print(S_k)
    if dimension == '1d':
        x = [10**0, 10**1.5]
        y = [10**-0.5, 10**-3]
    # graphes.graph(x,y,-1,'r-')

#   t0=590
# time_serie=range(t0+10,10000,50)#[round(t0*i**2) for i in np.arange(1,4,0.3)]

#origin of time
    t0 = 0.  #.51
    tref = np.asarray(m.t) - t0
    #  tref=1-tref
    nt = len(tref)
    # time_serie=[600,900,1200,1600,1900,2900,5000,8000]

    #  time_serie=[i for i in np.arange(400,650,10)]
    #  time_serie=range(10,nt-2)
    step = 1
    time_serie = range(Dt + 1, nt - Dt * 3 - 11,
                       step)  #[50,120,200,300,400,450,550]
    # print(nt-Dt*3-11)
    #   t0=500
    #   time_serie=[round(i)+t0 for i in np.logspace(1,3.973) if round(i)+t0<nt]
    # time_serie=range(start,end,50)

    alpha = np.zeros(len(time_serie))
    beta = np.zeros(len(time_serie))
    epsilon = np.zeros(len(time_serie))

    t_alpha = np.zeros(len(time_serie))

    #    graphes.hist(k)
    kmin = -2.7
    kmax = -1.7
    #print(np.log10(k))
    tmax = 300
    for i, t in enumerate(time_serie):
        #   print(t)
        if tref[t] < tmax:
            if dimension == '1d':
                k_log = np.log10(k)
                S_log = np.log10(S_k[:, t])
                indices = np.logical_and(k_log > kmin, k_log < kmax)
                #  print(indices)
                #  print(S_log)
                k_log = k_log[indices]
                S_log = S_log[indices]
                P = np.polyfit(k_log, S_log, 1)

                alpha[i] = 10**P[1]  #*np.mean(k)**P[0]
                beta[i] = P[0]

                C_k = 0.55
                epsilon[i] = (alpha[i] / C_k)**(3 / 2)
                t_alpha[i] = tref[t]

                #if t>min(time_serie):
                #     Dt=tref[time_serie.index(t)]-tref[time_serie.index(t-1)]
                #     print(Dt,alpha[time_serie.index(t)])
                #    print((t_alpha,alpha))
                if display_part:

                    graphes.set_fig(1)
                    # graphes.subplot(1,2,1)
                    k0 = np.min(k)
                    display_fft_1d(k, (k / k0)**(5 / 3) * S_k[:, t] / alpha[i],
                                   fignum=1,
                                   label='')
                    display_fft_1d(k, (k / k0) * S_k[:, t] / alpha[i],
                                   fignum=2,
                                   label='')

                    #normalized
                    #   print(t_alpha[i])
                    # display_fft_1d(k,np.abs(S_k[:,t]/t_alpha[i]),fignum=1)

                    # graphes.graphloglog(k[indices],10**np.polyval(P,k_log),label='r--')
                    display_fft(m, t, dimension)

                    #graphes.subplot(1,2,2)
                #  graphes.vfield_plot(m,t,fignum=2)

                #there is a slighlty degeneracy of the spectrum along both axis. Removes |kx| < epsilon and |ky| < epsilon for every k ?
                #   display_fft_2d(kx,ky,S_k_2d[:,:,t],fignum=3)
                #   display_fft(m,t,dimension)

                #   input()

            if dimension == '2d':
                display_fft_2d(kx, ky, S_k[:, :, t])
                display_fft(m, t, dimension)

    if display:
        #        title='$Z$ = '+str(m.Sdata.param.Zplane/10)+' cm'
        #    graphes.legende('$t$ (s)','$E (a.u.)$',title
        graphes.graphloglog(t_alpha, alpha, label=label, fignum=7)
        graphes.graphloglog([10**-1, 10**3], [10**8, 10**0],
                            label='r--',
                            fignum=7)
        graphes.legende('$t$ (s)', '$E_{\lambda}$ (a.u.)',
                        graphes.set_title(m))

        graphes.semilogx(t_alpha, beta, label=label, fignum=8)
        #    graphes.semilogx(t_alpha,beta,label=label,fignum=0)
        graphes.semilogx([10**-1, 10**3], [-5 / 3, -5 / 3],
                         label='r-',
                         fignum=8)
        graphes.set_axis(10**-1, 10**3, -2.5, 0)
        graphes.legende('$t$ (s)', 'exponent', graphes.set_title(m))

        #plot the dissipative scale as a function of time
        nu = 1  #in mm^2/s
        eta = (nu**3 / np.asarray(epsilon))**(1 / 4)
        graphes.graphloglog(t_alpha, eta, label=label, fignum=9)
        graphes.graphloglog([10**-1, 10**3], [10**8, 10**0],
                            label='r--',
                            fignum=9)
        graphes.legende('$t$ (s)', '$\eta$ (mm)', graphes.set_title(m))

    E_t = epsilon
    t = t_alpha
    return t, E_t