예제 #1
0
def draw(S, fignum, ax, color='r'):
    graphes.set_fig(fignum)
    print(S.fileCine)
    if hasattr(S.param, 'im_ref'):
        angle = S.param.angle * pi / 180
        fx = S.param.fx
        (Xpix, Zpix) = np.shape(S.param.im_ref)

        if S.param.typeview == 'sv':
            #vertical plane, the horizontal position is given py Xplane
            x0 = S.param.Xplane
            X = 0
            Z = (Xpix * sin(angle) + Zpix * cos(angle)) * fx

            zmin = -(S.param.x0 * sin(angle) + S.param.y0 * cos(angle)) * fx
            # zmax = zmin+Z
            z0 = zmin
        else:
            z0 = S.param.Zplane
            Z = 0
            X = max([Xpix, Zpix]) * fx
            x0 = -S.param.x0 * fx

        print([x0, z0, X, Z])
        graphic_run(ax, x0, z0, X, Z, color=color)
    #find the plane of measurement from Sdata file and
    else:
        print('No reference image given')

    pass
예제 #2
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    
예제 #3
0
def compute_Ct(M,
               tlist=[],
               axes=['Ux', 'Ux'],
               p=1,
               display=False,
               label='ko',
               fignum=1):
    display_part = False
    if tlist == []:
        t0 = 20
        Dt = 50
        dimensions = M.shape()
        tlist = range(t0, dimensions[2] - t0, Dt)

    tau = np.zeros(len(tlist))
    tf = np.zeros(len(tlist))

    for i, t in enumerate(tlist):
        X, Y, Yerr = stat_corr_t(M, t, axes=axes, p=1, display=False)
        try:
            popt, pcurv = scipy.optimize.curve_fit(fitting.exp, np.abs(X), Y)
        except ValueError:
            print("NaN values encountered, fit skipped")
            X, Y, Yerr = stat_corr_t(M, t, axe='E', p=1, display=True)
            # input()
            pcurv = []
            popt = [1]
        except RuntimeError:
            print(
                "Fitting did not converge, arbitrarly chosen to previous value"
            )
            pcurv = []
            if i == 0:
                popt = [1]
            else:
                popt = [tau[i - 1]]

        tf[i] = M.t[t]
        tau[i] = -1 / popt[0]
        #   print(str(M.t[t]) + ' : ' +str(tau[i]))

        if display_part:
            texp = np.abs(X)
            graphes.set_fig(1)
            graphes.errorbar(texp, Y, texp * 0, Yerr, fignum=0, label='ko')
            graphes.graph(texp, exp(texp, -1 / tau[i]), fignum=1, label='r')
            graphes.legende('$t/u^{2m}$', '$C_t$', '$m=1/2$')

    if display:
        graphes.graphloglog(tf, tau, fignum=fignum, label=label)
        graphes.legende('t (s)', 't_c', graphes.title(M))

    return tf, tau
예제 #4
0
def frames(fignum, Stroke=300, W=260., H=550., box=False):
    """
    generates the frame of the experiment (grid + box)
    drawing of the box is in option
    INPUT
    -----
    fignum : int
        number of figure to draw on
    Stroke : float
        Distance in mm between the start and the stop positions of the moving grid. 
        Its value is stored in Sdata.param.Stroke
    W : float. default value 260.
        Width of the box in mm. Default value correponds to the acrylic box used in 2015
    H : float. default value 550.
        Height of the box in mm. Default value correponds to the acrylic box used in 2015
    OUTPUT
    -----
    ax : plt.axes object
        axe corresponding to the drawing.
    """

    #    ax = axes.Axes(fig,frame)
    graphes.set_fig(fignum)
    ax = plt.gca()

    #draw the box : vertical position of the box is set manually
    zmin = -380

    if box:
        rect = patch.Rectangle((-W / 2, zmin),
                               W,
                               H,
                               facecolor='w',
                               edgecolor='k',
                               linewidth=3)
        ax.add_patch(rect)

    #draw the grid
    Z_start = 0
    Z_end = Z_start - Stroke
    draw_grid(ax, 0, Z_start)
    draw_grid(ax, 0, Z_end, facecolor='b')

    ax.set_aspect('equal')

    #set the axis limits
    e = 50
    graphes.set_axes(-e - W / 2, W / 2 + e, -e + zmin, H + zmin + e)
    graphes.refresh()

    return ax
예제 #5
0
def graphic(Slist):
    """
    Represent graphically the various experimental runs by their angle of view
         each graph correspond to a experimental configuration. They are distinguable by the used stroke
         (still looking for other criterions)
    INPUT
    -----
    Slist : Sdata list
        List of Sdata (Sdata is a rich header associated to each cine file after processing)
    OUTPUT
    -----
    figs : dict
        keys corresponds to fig number, associated values to a default figure name based on x and y legends.
        Autogenerated from output of stephane.display.graphes.legende
    """

    #find all the different experimental configurations (now only given by the total stroke S)
    axes = []
    figures = []
    strokes = []
    c = 0

    for S in Slist:
        if not S.param.stroke in strokes:
            stroke = S.param.stroke
            strokes.append(stroke)
            c += 1
            figures.append(c)
            axes.append(frames(c, Stroke=int(stroke), box=(stroke != 100.)))

    print(strokes)
    #    graphic_run(ax)
    for S in Slist:
        if S.fileCine.find('Polymer') > 0:
            color = 'b'
        else:
            color = 'r'

        stroke = S.param.stroke
        i = strokes.index(stroke)
        draw(S, figures[i], axes[i], color=color)

    figs = {}
    for i, fig in enumerate(figures):
        graphes.set_fig(fig)
        figs.update(
            graphes.legende(
                'Pictural representation, S = ' + str(strokes[i]) + ' mm', '',
                ''))

    return figs
예제 #6
0
def make_movie(M,Range=None,field=['E','vorticity'],Dirbase=None,Dt=1):
    if Dirbase==None:
        Dirbase = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/PIV_data' #local saving
    
    nx,ny,nt = M.shape()
    
    axes = panel(M)
    if Range is not None:
        start,stop,step = tuple(Range)
    else:
        start,stop,step = tuple([0,nt,1])
    frames = range(start,stop,step)
    
#    field = ['Ux','Uy']
  #  field = ['E','vorticity']
    figs={}
    Dirname = Dirbase+'/'+M.Id.get_id()+'/'+graphes.remove_special_chars(str(field))+'/'
    print(Dirname)
    
    for i,f in enumerate(field):
        if not hasattr(M,f):
            M,field_n[i] = vgradient.compute(M,field[i],Dt=Dt)
            field = field_n
            
#    M,field[1] = vgradient.compute(M,field[1],Dt=Dt)
    
    if Dt>1:
        print('Smoothed data')
        Dirname = Dirname + 'Smooth_Dt_'+str(int(Dt))+'/'

    for i in frames:        
        graphes.set_fig(1)
        for axe in axes:
            plt.sca(axe)
            plt.cla()
            
        axes = panel(M,fignum=1)        
        plt.sca(axes[1])
        print(i)
        graphes.Mplot(M,field[0],i,fignum=1,log=True)
        plt.text(-10,80,field[0],fontsize=20)

        plt.sca(axes[2])
        graphes.Mplot(M,field[1],i,fignum=1,log=True)
        plt.text(-10,80,field[1],fontsize=20)
        
        figs.update(graphes.legende('','','Front view',cplot=True))
        graphes.save_figs(figs,savedir=Dirname,suffix='_'+str(i),dpi=100,frmt='png',display=False)
    return axes
예제 #7
0
def draw_fieldofview(S,ax,fignum=None,color='r',view='side'):
    """
    Draw the field view of the camera, currently side view only.
    """
    if fignum is not None:
        graphes.set_fig(fignum)
  #  print(S.fileCine)

    u0,L=field_of_view(S)
    if view=='side':
        graphic_run(ax,u0[1],u0[2],L[1],L[2],color=color)
    if view=='front':
        graphic_run(ax,u0[0],u0[2],L[1],L[2],color=color)
        graphic_run(ax,u0[0]+L[0],u0[2],L[1],L[2],color=color)
        graphic_run(ax,u0[0],u0[2],L[0],L[1],color=color)
        graphic_run(ax,u0[0],u0[2]+L[2],L[0],L[1],color=color)
    if view=='bottom':
        pass
예제 #8
0
def make(subplot,fignum=1,axis='off'):
    """
    From a dictionnary of subplot location, generate a panel
    """
    axes = {}
    fig = graphes.set_fig(fignum)
    for num in subplot:
        axes[num] = plot_axes(fig,num,axis=axis)
    return fig,axes
예제 #9
0
def example(M,Range=None,field=['E','vorticity']):
    nx,ny,nt = M.shape()
    axes = panel(M)
    if Range is not None:
        start,stop,step = tuple(Range)
    else:
        start,stop,step = tuple([0,nt,1])
    frames = range(start,stop,step)
    
#    field = ['Ux','Uy']
  #  field = ['E','vorticity']
    
    figs={}
    
    Dirbase = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/PIV_data' #local saving
    Dirname = Dirbase+'/'+M.Id.get_id()+'/'+graphes.remove_special_chars(str(field))+'/'
    print(Dirname)
    
    M,field[0] = vgradient.compute(M,field[0])
    M,field[1] = vgradient.compute(M,field[1])
    
    for i in frames:        
        graphes.set_fig(1)
        for axe in axes:
            plt.sca(axe)
            plt.cla()
        axes = panel(M,fignum=1)    
            
        plt.sca(axes[1])
        graphes.Mplot(M,field[0],i,log=True)
        plt.text(-10,20,field[0],fontsize=20)

        plt.sca(axes[2])
        graphes.Mplot(M,field[1],i,fignum=1,log=True)
        plt.text(-10,20,field[1],fontsize=20)
        
        figs.update(graphes.legende('','','Front view',cplot=True))
        graphes.save_figs(figs,savedir=Dirname,suffix='_'+str(i),dpi=100,frmt='png')
    return axes
    
    
예제 #10
0
def make_plot(M,Range=None,color='k',field=['E','vorticity'],Dirbase=None,Dt=1,example=False,total=True,fignum=1,save=True):
    if Dirbase==None:
        Dirbase = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/PIV_data/Test6/' #local saving
        Dirbase = './Stat_avg/Panel/'+M.Id.date
    
    axes = flex_panel(M,fignum=fignum)
    
   # for axe in axes:
    #    plt.sca(axe)
        #plt.cla()
    
    frames = select_range(M,Range)
    
#    field = ['Ux','Uy']
  #  field = ['E','vorticity']
    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))+'/'

    #Dt = 50
    t_moy,E_moy = access.avg_vs_t(M,'E',frames,Dt=Dt)
    t_moy,Omega_moy = access.avg_vs_t(M,'omega',frames,Dt=Dt)
    t_moy,Strain_moy = access.avg_vs_t(M,'strain',frames,Dt=Dt)
    t_moy,Y_pdf_moy = access.avg_vs_t(M,field[1],frames,Dt=Dt)
    
    epsilon = scale.dissipation_rate(Omega_moy) #dissipation rate
    eta = scale.K_scale(epsilon)  #dissipative scale
    
    micro_1 = np.sqrt(1./4*E_moy/Strain_moy**2)
    micro_2 = np.sqrt(E_moy/(Omega_moy)**2) 
    
    Re = scale.Re(micro_1,eta)
    Re_lambda_1 = scale.Re_lambda(E_moy,micro_1)
    Re_lambda_2 = scale.Re_lambda(E_moy,micro_2)
    
    L = scale.I_scale(Re,E_moy)
    
#    plt.sca(axes[2])
#    graphes.graphloglog(t_moy,E_moy,fignum=1,label=color+'o-')
    #Fourier.add_theory(t_moy,E_moy,[-2.],fignum=1)
#    graphes.graphloglog(t_moy,Y_pdf_moy,fignum=1,label=color+'s-')
#    graphes.graphloglog(t_moy,epsilon,fignum=1,label='gv-')
    #Fourier.add_theory(t_moy,epsilon,[-3.],fignum=1)    
#    figs.update(graphes.legende('t (s)','E (mm^2/s^2), epsilon(mm^2/s^-3)',''))
    
    plt.sca(axes[1])
    graphes.graphloglog(t_moy,eta,fignum=fignum,label=color+'o-')
    graphes.graphloglog(t_moy,micro_1,fignum=fignum,label=color+'s-')
    graphes.graphloglog(t_moy,micro_2,fignum=fignum,label='cp-')
    graphes.graphloglog(t_moy,L,fignum=fignum,label='gv-')
    figs.update(graphes.legende('t (s)','eta (mm), lambda (mm)',''))        
    
    plt.sca(axes[2])
    graphes.graphloglog(t_moy,Re,fignum=fignum,label=color+'o-')
    graphes.graphloglog(t_moy,Re_lambda_1,fignum=fignum,label=color+'s-')
    graphes.graphloglog(t_moy,Re_lambda_2,fignum=fignum,label='cp-')
    figs.update(graphes.legende('t (s)','Re , Re_lambda',''))
    
   # print(t_moy)
#    print(Y_moy)
   # print(t)
#    print(Y_moy)
    indices = [0,1]
#    indices = [1,4]
    cla_axes = [axes[i] for i in indices]
    
    if save:
        graphes.save_figs(figs,savedir=Dirname,prefix='General',suffix='_vs_t',dpi=300,frmt='png',display=True)

    individual=False
    
    if example:
        frames_disp =[1200]
    else:
        step =frames[1]-frames[0]
        frames_disp = range(frames[0]+step*10,frames[-1],step*10)
        
    if individual:
        for frame in frames_disp:  
            #print(frame)
            #print(frames)
            i = frames.index(frame)      
            graphes.set_fig(1)
            for axe in cla_axes:
                plt.sca(axe)
                plt.cla()
            axes = flex_panel(M,fignum=1)   
            
            
            if total:     
                plt.sca(axes[0])
                graphes.Mplot(M,field[0],frame,fignum=1,log=True)
                plt.text(-10,80,field[0],fontsize=20)
                
            plt.sca(axes[1])
         #   graphes.graphloglog(t_moy,eta,fignum=1,label='ko-')
         #   graphes.graphloglog(t_moy,micro,fignum=1,label='ks-')
            graphes.graph([t_moy[i]],[eta[i]],fignum=1,label='ro')
            graphes.graph([t_moy[i]],[micro_1[i]],fignum=1,label='rs')
            graphes.graph([t_moy[i]],[micro_2[i]],fignum=1,label='rp')
            graphes.graphloglog([t_moy[i]],[L[i]],fignum=1,label='rv-')
            
            plt.sca(axes[2])
            graphes.graphloglog([t_moy[i]],[Re[i]],fignum=1,label='ro-')
            graphes.graphloglog([t_moy[i]],[Re_lambda_1[i]],fignum=1,label='rs-')
            graphes.graphloglog([t_moy[i]],[Re_lambda_2[i]],fignum=1,label='rp-')

        
            plt.sca(axes[3])
            figs.update(graphes.pdf(M,'Ux',frame,Dt=Dt,fignum=1,label='m^'))
            figs.update(graphes.pdf(M,'Uy',frame,Dt=Dt,fignum=1,label='b>'))
            figs.update(graphes.legende('t (s)','Re , Re_lambda',''))

            plt.sca(axes[4])
            figs.update(graphes.pdf(M,field[1],frame,Dt=Dt,fignum=1,label=color+'-'))
        
#        graphes.Mplot(M,field[1],i,fignum=1,log=True)
#        plt.text(-10,80,'PDF '+field[1],fontsize=20)       
#        figs.update(graphes.legende('','','Front view',cplot=True))
            graphes.save_figs(figs,savedir=Dirname,suffix='_'+str(frame),dpi=100,frmt='png',display=False)
            
    return axes
예제 #11
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_')
예제 #12
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
예제 #13
0
def make_2dmovie(M,
                 name,
                 Range=None,
                 fignum=1,
                 local=True,
                 log=False,
                 vmin=0,
                 vmax=1,
                 filt=False):
    """
    Movie of the colormap of the velocity modulus U over time  
    INPUT
    -----
    M : Mdata class instance, or any other object that contains the following fields :
        methods : shape()
        attributes : Ux, Uy
        Sdata object
        Ids object
        ...
    name : name of the field to be plotted. example : Ux,Uy, vorticity, strain
    Range : np array
    fignum : int. default value is 1
    Dirname : string
        Directory to save the figures
    log : bool. default value is True
    OUTPUT
    -----
    None
    """
    if Range is not None:
        start, stop, step = tuple(Range)
    else:
        start, stop, step = tuple([0, M.shape()[-1], 5])


#    U=np.sqrt(S.Ux**2+S.Uy**2)
#by default, pictures are save here :
    if local:
        Dirlocal = '/Users/stephane/Documents/Experiences_local/Accelerated_grid'
    else:
        Dirlocal = os.path.dirname(M.Sdata.fileCine)
    Dirname = name
    if filt:
        Dirname = Dirname + '_filtered'

    Dir = Dirlocal + '/PIV_data/' + M.Id.get_id() + '/' + Dirname + '/'
    print(Dir)

    fig = graphes.set_fig(fignum)
    graphes.set_fig(0)  #clear current figure

    print('Compute ' + name)
    M, field = vgradient.compute(M, name, filter=filt)

    for i in range(start, stop, step):
        #Z = energy(M,i)
        graphes.Mplot(M,
                      field,
                      i,
                      fignum=fignum,
                      vmin=vmin,
                      vmax=vmax,
                      log=log,
                      auto_axis=True)
        #        graphes.color_plot(Xp,Yp,-Z,fignum=fignum,vmax=700,vmin=0)

        if i == start:
            cbar = graphes.colorbar(
            )  #fignum=fignum,label=name+'(mm^2 s^{-2})')
        else:
            print('update')
        # cbar.update_normal(fig)

        filename = Dir + 'V' + str(i)
        graphes.save_fig(fignum, filename, frmt='png')
예제 #14
0
def plot(x, y, U, fignum=1, vectorScale=10**8):
    """
    Plot a 2d velocity fields with color coded vectors
    Requires fields for the object M : Ux and Uy
    INPUT
    -----	
    M : Mdata set of measure 
    frame : number of the frame to be analyzed
    fignum (opt) : asking for where the figure should be plotted
    
    OUTPUT
    ------
    None
    	"""
    Ux = U[:, 0]
    Uy = U[:, 1]

    colorCodeVectors = False
    refVector = 1.
    #    vectorScale = 100
    vectorColormap = 'jet'

    #bounds
    #chose bounds from the histograme of E values ?
    scalarMinValue = 0
    scalarMaxValue = 100

    # make the right figure active
    graphes.set_fig(fignum)

    # get axis handle
    ax = plt.gca()
    ax.set_yticks([])
    ax.set_xticks([])

    E = np.sqrt(Ux**2 + Uy**2)
    Emoy = np.nanmean(E)

    if colorCodeVectors:
        Q = ax.quiver(x,y,Ux/Emoy,Uy/Emoy, E, \
                scale=vectorScale/refVector,
                scale_units='width',
                cmap=plt.get_cmap(vectorColormap),
                clim=(scalarMinValue, scalarMaxValue),
                edgecolors=('none'),
                zorder=4)
    #elif settings.vectorColorValidation:
    #    v = 1
    #    #ax.quiver(x[v==0], y[v==0], ux[v==0], uy[v==0], \
    #    scale=vectorScale/refVector, scale_units='width', color=[0, 1, 0],zorder=4)
    #    Q = ax.quiver(x[v==1], y[v==1], ux[v==1], uy[v==1], \
    #                  scale=vectorScale/refVector, scale_units='width', color='red',zorder=4)
    else:
        Q = ax.quiver(x,
                      y,
                      Ux / E,
                      Uy / E,
                      scale=vectorScale / refVector,
                      scale_units='width',
                      zorder=4)  #, color=settings.vectorColor

    graphes.legende('$x$ (mm)', '$y$ (mm)', '')

    # add reference vector
    #if settings.showReferenceVector:
    #        plt.quiverkey(Q, 0.05, 1.05, refVector, str(refVector) + ' m/s', color=settings.vectorColor)

    #overwrite existing colorplot
    graphes.refresh(False)
예제 #15
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
예제 #16
0
def vertical_spreading(M, N, Dt=10, label='k^'):
    """
    Compute the vertical profile of RMS velocity as a function of time
    
    INPUT
    -----
    
    OUTPUT
    -----
    figs : dict
        key correspond to figure index, value to their standarzied filename
    """
    n = 160
    ti = 50

    figs = {}

    z0 = -M.param.stroke  #!!!
    z_1 = np.zeros(n)
    z_2 = np.zeros(n)

    t = np.zeros(n)
    E = np.zeros(n)

    indices = [(i + 1) * N + ti for i in range(n)]
    for i, t0 in enumerate(indices):
        z_1[i], z_2[i], E[i], std_E = velocity_profile(M,
                                                       i,
                                                       t0,
                                                       Dt=Dt,
                                                       display=True)
        t[i] = M.t[t0]
    #average on horizontal line (if rotated, correspond to vertical line)


#compute the vertical RMS velocity profile

    fig = 1
    graphes.set_fig(fig)
    graphes.graph(t, z_1 - z0, fignum=fig, label=label)
    graphes.graph(t, z_2 - z0, fignum=fig, label=label)
    figs.update(graphes.legende('$t$ (s)', '$Front position z$ (mm)', ''))

    fig = 2
    graphes.set_fig(fig)
    graphes.graphloglog(t, np.abs(z0 - z_1), fignum=fig, label=label)
    graphes.graphloglog(t, np.abs(z0 - z_2), fignum=fig, label=label)

    graphes.graphloglog(t, np.power(t, 0.5) * 10**2, fignum=fig, label='r--')
    figs.update(graphes.legende('$t$ (s)', '$Front position z (log)$ (mm)',
                                ''))

    fig = 3
    graphes.set_fig(fig)
    graphes.graphloglog(t, E, fignum=fig, label=label)
    figs.update(graphes.legende('$t$ (s)', '$U_{rms}$ (mm/s)', ''))

    t_min = 6 * 10**-2
    t_max = 4 * 10**-1
    indices = np.where(np.logical_and(t < t_max, t > t_min))
    t_part = t[indices]
    z_part = np.abs(z0 - z_1[indices])

    P = np.polyfit(np.log(t_part / t_min), np.log(z_part), 1)
    C = np.exp(P[1])
    nu = C**2 / t_min
    print(P[0], C)
    print('Effective diffusion coefficient : ' + str(nu) + ' mm^2/s')

    graphes.graphloglog(t, C * np.power(t / t_min, P[0]), fignum=2, label='r-')
    figs.update(graphes.legende('$t$ (s)', '$Front position z (log)$ (mm)',
                                ''))

    graphes.save_figs(figs,
                      savedir='./Spreading/',
                      suffix='',
                      prefix='2015_12_28_front_both_C')

    return figs
예제 #17
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
예제 #18
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
예제 #19
0
def spatial_correlation(M,
                        compute=True,
                        rootdir='Corr_functions',
                        label='k^',
                        fignum=1,
                        display=True,
                        save=False):
    """
    Compute the spatial correlation function 
        or display the correlation length as a function of time 
        save the correlations function in txt files
    INPUT
    -----
    M : Mdata object
    compute : bool
        default value : True
        if True, the correlations functions are computed, and save in txt files 
        if False, load the previously computed correlations functions and display the correlation length as a function of timme
    rootdir : string
        subdirectory name for saving the corr functions. Base directory correspond to the location of the associated dataset.
    OUTPUT
    -----
    None
    """

    if compute:
        # chose randomly the pair of indices that will be used for computing the spatial correlation function
        dlist = range(int(max(M.shape()) / 2))
        indices = {}
        N = 10**3
        for i, d in enumerate(dlist):
            indices[i] = d_2pts_rand(M.Ux[:, :, 0], d, N)
        print('Pair of indices computed')
        (ny, nx, nt) = M.shape()

        #  tref,d,Cxx,Cyy,Cxy,CEE = correlation_functions(M,dlist,indices,Dt=Dt)
        #  print('Correlation functions computed')

        step = 100
        Dt = 20
        tref, d, Cxx, Cyy, Cxy, CEE = display_corr_vs_t(M,
                                                        dlist,
                                                        indices,
                                                        step=step,
                                                        Dt=Dt,
                                                        label='-',
                                                        display=True)

        #How to save matrices in a single txt file ?
        #    filename = os.path.dirname(M.filename) + '/Corr_functions/' + name + '.txt'
        axes = ['xx', 'yy', 'xy', 'CEE']
        keys = ['d', 't'] + ['Corr_' + p for p in axes]

        Corr_functions = [Cxx, Cyy, Cxy, CEE]
        List_info = [d, tref] + Corr_functions

        if save:
            name = 'Corr_spatial_' + M.Id.get_id()
            filename = os.path.dirname(
                M.filename) + '/Corr_functions/' + name + '.txt'
            print(filename)
            rw_data.write_matrix(filename, keys, List_info)
            # for C in [Cxx,Cyy,Cxy,CEE]:
            #     rw_data.write_matrix(tref,D,C)

            print('Correlation functions saved in ' + filename)

    else:
        #try first to load the data rfrom the Corr_functions directory
        Dir = os.path.dirname(M.filename) + '/' + rootdir
        filename = Dir + '/Corr_spatial_' + M.Id.get_id(
        ) + '.txt'  #print(filename)
        Header, Data, axes = rw_data.read_matrix(filename,
                                                 Hdelimiter='\t',
                                                 Ddelimiter='\t')
        print(Data.keys())
        nd = axes['d']
        nt = axes['t']

        print((nd, nt))
        Dt = 20
        for key in Data.keys():
            Data[key] = np.reshape(np.asarray(Data[key]), (nd, nt))


#            Data[key]=cdata.smooth(Data[key],Dt)
        dimensions = M.shape()
        tlist = range(Dt, dimensions[2] - 3 * Dt, 1)
        lc = np.zeros(len(tlist))
        tf = np.zeros(len(tlist))

        display_part = True
        for i, t in enumerate(tlist):
            d = Data['d'][:, i]

            key = 'Corr_xx'
            Cd = Data[key][:, i] / Data[key][0, i]

            popt = fitting.fit(fitting.exp, d[0:10], Cd[0:10])

            tf[i] = M.t[t]
            lc[i] = -1 / popt[0]
            #   print(str(M.t[t]) + ' : ' +str(lc[i]))
            if display_part:
                if i % 100 == 0:
                    graphes.set_fig(1)
                    graphes.graph(d, Cd, fignum=0, label='ko')
                    graphes.graph(d, exp(d, -1 / lc[i]), label='r')
                    #   graphes.graph(d,parabola(d,-1/lc[i])+1,label='r')
                    graphes.legende('$d (mm)$', '$C_d$', '')
                    graphes.set_axes(0, 3, -1, 1.1)
                    #input()

        cdata.rm_nans([lc], d=2)

        if display:
            graphes.graphloglog(tf, lc, fignum=fignum, label=label)
            graphes.legende('$t (s)$', '$d (mm)$', graphes.title(M))