Exemple #1
0
def get(M, field, frame, Dt=1, Dt_filt=1, compute=False, **kwargs):
    """
    Return a subset of the data contained in a Mdata object

    INPUT
    -----
    M : Mdata object
    field : str
        field to be extracted. Either Ux, Uy, E, omega, Enstrophy, strain
    frame : int 
        start frame index
    Dt : int
        number of frames to extract. default is 1
    Dt_filt : for filtering purpose
    compute : bool
        compute the values if True, try to recover the previoulsy stores values if False.
        default value is False
    **kwargs : key word arguments
        to be passed to vgradient.compute (computationnal option for selection the method used for instance)
    OUTPUT
    -----
    data : np array
        extracted data
    """
    if field == 'U':
        # return both component in a vectorial format
        Ux = getattr(M, 'Ux')[..., frame:frame + Dt]
        Uy = getattr(M, 'Uy')[..., frame:frame + Dt]

        d = len(M.shape())
        tup = tuple(range(1, d + 1) + [0])

        data = np.transpose(np.asarray([Ux, Uy]), tup)
        return data

    if (not hasattr(M, field)) or (compute):
        if Dt_filt > 1:
            print('Filtering of the data : irreversible')
        if Dt == 1:
            data_part, field = vgradient.compute_frame(M, field, frame)
            return data_part
        else:
            vgradient.compute(M, field, Dt=Dt_filt, **kwargs)

            data = getattr(M, field)
            data_part = data[..., frame:frame + Dt]
            return data_part
    else:
        data = getattr(M, field)
        data_part = data[..., frame:frame + Dt]
        return data_part
Exemple #2
0
def front(M):
    """
    From a temporal measurement of a turbulent spreading situation,
    compute the position of the front.
    The algorithm is based on the following steps :
    Start with an horionzal line on the top.
    At each time step, evaluates if the front has been moving downward.
    Detection based on ? threshold of detection ? energy amplitude ?? 
    Update the position of the front
    """

    X, Y = graphes.get_axis_coord(M)
    nx, ny, nt = M.shape()

    Z_front = np.zeros(nx) + 75  # the front is propagating downward

    # Z_front = np.max(Y,axis=1) #?? should correspond to the X axis ???

    frame = 100
    # energy profile along the front :

    #    print(len(Z_front))
    field = 'E'
    if not hasattr(M, field):
        M, field = vgradient.compute(M, field, filter=True)

    test_front(M, Z_front, frame)
Exemple #3
0
def shear_limit_M(M, W, Dt, type=1, **kwargs):
    """
    Test the shear criterion : dU/W < 0.1 
    """
    values = access.get(M, 'strain', frame)

    M, field = vgradient.compute(M,
                                 'strain',
                                 step=1,
                                 filter=False,
                                 Dt=1,
                                 rescale=False,
                                 type=type,
                                 compute=False)
    values = getattr(M, field)  # /W

    dUmin, dUmax = check.shear_limit_M(M, W)

    xbin, n = graphes.hist(values,
                           normalize=False,
                           num=200,
                           range=(-0.5, 0.5),
                           **kwargs)  # xfactor = Dt
    maxn = max(n) * 1.2

    graphes.graph([dUmin, dUmin], [0, maxn], label='r-', **kwargs)
    graphes.graph([dUmax, dUmax], [0, maxn], label='r-', **kwargs)
    graphes.legende('', '', '')
Exemple #4
0
def movie_spectrum(M, field, alpha=[-5. / 3], Dt=10, fignum=1, start=0, stop=0):
    # switch_field(field)

    if not hasattr(M, field):
        M, field = vgradient.compute(M, field)

    if not hasattr(M, 'S_' + field):
        yy = getattr(M, field)
        yy_k, k = spectrum_1d(yy, M, display=False, Dt=Dt)
        print(yy_k.shape)
    else:
        yy_k = getattr(M, 'S_' + field)
        k = getattr(M, 'k_' + field)
    step = max(Dt / 2, 1)
    N, nt = yy_k.shape

    if stop == 0:
        tax = range(start, nt, step)
    else:
        tax = range(start, stop, step)

    figs = {}

    for i, t in enumerate(tax):
        # graphes.cla(fignum)
        graphes.graph(k, yy_k[:, t], label='k-', fignum=fignum)
        # graphes.graphloglog(k,yy_k[:,t],label='k-',fignum=fignum)
        add_theory(k, yy_k[:, t], alpha, fignum=fignum)
        # graphes.set_axis(10**-2,10**0,10**-4,10**2)
        figs.update(graphes.legende('k (mm^-1)', 'E_k (mm^3/s^-2)', ''))

        graphes.save_graphes(M, figs, prefix='Movie_Spectrum_' + field + '/', suffix='_' + str(t))
Exemple #5
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')
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
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
Exemple #8
0
 def compute(self, field, **kwargs):
     import turbulence.analysis.vgradient as vgradient
     return vgradient.compute(self, field, **kwargs)
Exemple #9
0
 def compute(self, field, **kwargs):
     return vgradient.compute(self, field, **kwargs)
Exemple #10
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