Example #1
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')
Example #2
0
def compare_logtime(fignum=1):
    Dt = 0.1
    alpha = 1.001
    n = 7000

    log_time_step(Dt, alpha, n)

    # read time step
    file = '/Users/stephane/Documents/Experiences_local/Accelerated_grid/Set_time_scale/H1180mm_S300mm_decay/param_NL_Dt.txt'

    t_s, Dt = read_time_step(file)
    graphes.graphloglog(t_s, Dt, fignum=fignum, label='ko')

    Dir = os.path.dirname(file)
    print(Dir)

    params = {'Dt': Dt, 'alpha': alpha, 'n': n}
    s = rw_data.gen_name(params)
    file_fig = Dir + '' + '/' + 'Dt_vs_t_data_mes1'  # +s

    print(file_fig)
    graphes.save_fig(0, file_fig)
Example #3
0
def make_2dmovie(M, Z, start, stop, Dirname='velocity_module', vmin=-3, vmax=3):
    # Movie of the velocity modulus U
    #    U=np.sqrt(S.Ux**2+S.Uy**2)
    fignum = 5
    for i in range(start, stop):
        Z0 = Z[:, :, i] / 1000
        print(i)

        #  print('<dU>_x,y = '+str(np.median(Z0)))
        #  print('<dU^2>_x,y = '+str(np.std(Z0)))
        graphes.color_plot(M.x, M.y, np.log10(Z0), fignum=fignum, vmin=vmin, vmax=vmax)
        if i == start:
            graphes.colorbar(fignum=fignum, label='V (m/s)')
        titre = ''
        graphes.legende('x (mm)', 'y (mm)', titre)

        if i == start:
            input()
        #       graphes.vfield_plot(S)

        Dir = os.path.dirname(M.Sdata.fileCine) + '/' + Dirname + '/'
        print(Dir)
        filename = Dir + 'V' + str(i)
        graphes.save_fig(fignum, filename, fileFormat='png')
ind = 0
for skk in sk_disc:
    kk = k_disc[ind]

    print 'np.shape(skk) = ', np.shape(skk)
    print 'np.shape(kk) = ', np.shape(kk)
    todo = range(20, np.shape(skk)[1])
    colors = tcmaps.cubehelix_palette(n_colors=len(todo), start=0.5, rot=-0.75, check=False)
    print 'np.shape(colors) = ', np.shape(colors)
    dmyi = 0
    for ii in todo:
        print 'Plotting energy spectrum, item =', ii
        graphes.graphloglog(kk, skk[..., ii], 'k', color=colors[dmyi])
        dmyi += 1

    graphes.graph(mm.k, 100 * mm.k ** (-5. / 3), label='r-')
    figs = graphes.legende(r'$k$ [mm$^{-1}$]', r'$E$ [mm/s$^{2}$]', r'$S(k)$ for $r <$' + str(radii[ind]) + ' pixels')
    imout_dir = savedir + 'energy_spectrum_radius_sequence/' + date + '_' + str(index) + \
                '_energy_spectrum_radius_sequence/'
    if not os.path.exists(imout_dir):
        print 'le.ensure_dir: creating dir: ', imout_dir
        os.makedirs(imout_dir)

    figname = imout_dir + date + '_' + str(index) + '_energy_spectrum_radius{0:03d}'.format(radii[ind])
    print 'saving fig: ' + figname
    graphes.save_fig(1, figname, frmt='png', dpi=300, overwrite=True)
    plt.clf()

    ind += 1

########################################################
# Energy spectrum (Kolmogorov scaling: -5/3)
########################################################
plt.close('all')
M = Mlist[0]
for ii in range(20, 148):
    print 'Plotting energy spectrum, item =', ii
    graphes.graphloglog(M.k, M.S_k[..., ii], 'k')

graphes.graph(M.k, 15 * M.k**(-5. / 3), label='r-')
figs = graphes.legende(r'$k$ [mm$^{-1}$]', r'$E$ [mm/s$^{2}$]', '')
figname = savedir + 'energy_spectrum1'
print 'saving fig: ' + figname
graphes.save_fig(1,
                 savedir + 'energy_spectrum1',
                 frmt='pdf',
                 dpi=300,
                 overwrite=False)

########################################################
# Energy spectrum as function of shell radius
########################################################
radii = [40, 80, 160, 320, 640, 1280, 2560]
sk_disc = []
k_disc = []
for rad in radii:
    sk, k = Fourier.compute_spectrum_1d_within_region(M,
                                                      radius=rad,
                                                      polygon=None,
                                                      display=False,
                                                      dt=10)
Example #6
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