Example #1
0
def spectrum_2d(M, indices=None):
    Fourier.compute_spectrum_2d(M, Dt=3)  # smooth on 3 time step.
    S_E = np.nanmean(M.S_E[..., indices], axis=2)
    graphes.color_plot(M.kx, M.ky, S_E, log=True, fignum=1)
    graphes.colorbar(label='$E_k$')
    figs = graphes.legende('$k_x$ (mm)', '$k_y$ (mm)', 'Energy Spectrum (log)')
    return figs
Example #2
0
def time_average(M, indices=None):
    figs = {}
    fields, names, vmin, vmax, labels, units = std_fields()

    for j, field in enumerate(fields):
        Y = np.nanmean(getattr(M, field)[..., indices], axis=2)
        graphes.color_plot(M.x, M.y, Y, fignum=j + 1, vmin=vmin[j] / 5, vmax=vmax[j] / 5)
        graphes.colorbar(label=names[j] + ' ' + units[j])
        figs.update(graphes.legende('X (mm)', 'Y (mm)', 'Time averaged ' + field, cplot=True))
    return figs
Example #3
0
def spatial_decay(M, field='E', indices=None):
    from mpl_toolkits.axes_grid.inset_locator import inset_axes
    import stephane.vortex.track as track

    fields, names, vmin, vmax, labels, units = std_fields()
    j = fields.index(field)

    Z = np.nanmean(getattr(M, field)[..., indices], axis=2)

    X, Y = [], []
    for i in indices:
        tup = track.positions(M, i, field=field, indices=indices, step=1, sigma=10.)
        X.append(tup[1])
        Y.append(tup[3])
    X0, Y0 = np.nanmean(X), np.nanmean(Y)

    R, Theta = Smath.cart2pol(M.x - X0, M.y - Y0)
    R0 = M.param.Diameter

    Z_flat = np.ndarray.flatten(Z)
    R_flat = np.ndarray.flatten(R)
    Theta_flat = np.ndarray.flatten(Theta)

    phi = np.pi / 2
    C = np.mod((Theta_flat + phi + np.pi) / 2 / np.pi, 1)
    cmap = matplotlib.cm.hot
    color = [matplotlib.colors.rgb2hex(cmap(c)[:3]) for c in C]

    fig, ax2 = graphes.set_fig(1, subplot=122)
    fig.set_size_inches(20, 6)
    ax2.scatter(R_flat, Z_flat, marker='o', facecolor=color, alpha=0.3, lw=0, cmap=cmap)

    Rth = np.arange(10 ** 1, 10 ** 2, 1.)
    # graphes.graphloglog(Rth, 10 ** 5 * (Rth / R0) ** -3.2, label='k--')
    # graphes.graphloglog(Rth, 5 * 10 ** 4 * (Rth / R0) ** -4.5, label='k--')
    graphes.set_axis(10 ** 0, 10 ** 2, 10 ** 2, 8 * 10 ** 4)
    figs = graphes.legende('$R$ (mm)', 'Energy (mm$^2$/s$^{2}$)', 'Spatial decay')

    fig, ax1 = graphes.set_fig(1, subplot=121)
    graphes.color_plot(M.x, M.y, Z, fignum=1, vmin=0, vmax=40000, subplot=121)
    graphes.colorbar(label=names[j] + ' (' + units[j] + ')')
    figs.update(graphes.legende('X (mm)', 'Y (mm)', 'Time averaged ' + field, cplot=True))

    inset_ax = inset_axes(ax2, height="50%", width="50%", loc=3)
    inset_ax.pcolormesh(M.x / 10 - 10, M.y / 10 - 10, Theta, cmap=cmap)
    inset_ax.axis('off')

    return figs
Example #4
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 #5
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')
def vfield(sigma, modes, fignum=1):
    names = {
        'sigma': sigma,
        'n': modes
    }  # name:eval(name) for name in ['sigma','n','N_p']}# this piece of code does not work

    t = distribution(sigma, modes)

    B = 1.
    n = 100
    dx = 2 * B / n
    x = np.arange(-B, B, dx)
    y = 0.
    z = np.arange(-B, B, dx)
    P = np.asarray(np.meshgrid(x, y, z))

    dim = P.shape
    N = np.prod(dim[1:])
    X = np.reshape(P[0, ...], (N, ))
    Y = np.reshape(P[1, ...], (N, ))
    Z = np.reshape(P[2, ...], (N, ))

    Pos = [np.asarray([x0, y0, z0]) for x0, y0, z0 in zip(X, Y, Z)]

    V = biot.velocity_from_line(t.paths, Pos, Gamma=1, d=3)

    V_2d = np.reshape(V, (n, n, 3))
    E = np.sum(np.power(V_2d, 2), axis=2)

    subplot = [111]
    fig, axes = panel.make(subplot, fignum=fignum)
    fig.set_size_inches(10, 10)

    graphes.color_plot(x, z, E, fignum=fignum, vmin=0, vmax=0, log=True)
    c = graphes.colorbar()

    figs = {}
    figs.update(graphes.legende('X', 'Z', 'E'))

    graphes.save_figs(figs,
                      prefix='Random_path/V_Distributions/Fields/',
                      suffix=suf(names),
                      dpi=300,
                      display=True,
                      frmt='png')
Example #7
0
def plot_lambda_Re_lambda_coarse(Mfluc,
                                 cutoff=10**(-3),
                                 vminRe=0,
                                 vmaxRe=800,
                                 vminLambda=0,
                                 vmaxLambda=10,
                                 nu=1.004,
                                 x0=None,
                                 y0=None,
                                 x1=None,
                                 y1=None,
                                 redo=False):

    if not hasattr(Mfluc, 'U2ave') or redo:
        print 'Mfluc does not have attribute Mfluc.U2ave. Calculate it.'
        Mfluc = compute_u2_duidxi(Mfluc, x0=x0, y0=y0, x1=x1, y1=y1)

    # Calculate Local Taylor microscale: lambdaT
    Mfluc.lambdaT_Local = np.sqrt(Mfluc.U2ave / Mfluc.dUidxi2ave)
    Mfluc.Re_lambdaT_Local = Mfluc.lambdaT_Local * np.sqrt(Mfluc.U2ave) / nu

    Mfluc.lambdaTx_Local = np.sqrt(Mfluc.Ux2ave / Mfluc.dUxdx2ave)
    Mfluc.Re_lambdaTx_Local = Mfluc.lambdaTx_Local * np.sqrt(Mfluc.Ux2ave) / nu

    Mfluc.lambdaTy_Local = np.sqrt(Mfluc.Uy2ave / Mfluc.dUydy2ave)
    Mfluc.Re_lambdaTy_Local = Mfluc.lambdaTy_Local * np.sqrt(Mfluc.Uy2ave) / nu

    # Mfluc.lambdaT_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    # Mfluc.lambdaTx_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    # Mfluc.lambdaTy_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    # Mfluc.Re_lambdaT_Local = np.zeros((Mfluc.x.shape[0], Mfluc.Ux.shape[1]))
    # Mfluc.Re_lambdaTx_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    # Mfluc.Re_lambdaTy_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    # for x in range(0, Mfluc.Ux.shape[0] - 1):
    #     for y in range(0, Mfluc.Ux.shape[1] - 1):
    #         if Mfluc.dUidxi2ave[x, y] < cutoff:
    #             Mfluc.lambdaT_Local[x, y] = 0
    #         else:
    #             Mfluc.lambdaT_Local[x, y] = np.sqrt(Mfluc.U2ave[x, y] / Mfluc.dUidxi2ave[x, y])
    #             Mfluc.Re_lambdaT_Local[x, y] = Mfluc.lambdaT_Local[x, y] * np.sqrt(Mfluc.U2ave[x, y]) / nu
    #         if Mfluc.dUxdx2ave[x, y] < cutoff:
    #             Mfluc.lambdaTx_Local[x, y] = 0
    #         else:
    #             Mfluc.lambdaTx_Local[x, y] = np.sqrt(Mfluc.Ux2ave[x, y] / Mfluc.dUxdx2ave[x, y])
    #             Mfluc.Re_lambdaTx_Local[x, y] = Mfluc.lambdaTx_Local[x, y] * np.sqrt(Mfluc.Ux2ave[x, y]) / nu
    #         if Mfluc.dUydy2ave[x, y] < cutoff:
    #             Mfluc.lambdaTy_Local[x, y] = 0
    #         else:
    #             Mfluc.lambdaTy_Local[x, y] = np.sqrt(Mfluc.Uy2ave[x, y] / Mfluc.dUydy2ave[x, y])
    #             Mfluc.Re_lambdaTy_Local[x, y] = Mfluc.lambdaTy_Local[x, y] * np.sqrt(Mfluc.Uy2ave[x, y]) / nu

    # Plot Taylor miroscale

    graphes.color_plot(Mfluc.x,
                       Mfluc.y,
                       Mfluc.Re_lambdaT_Local,
                       fignum=1,
                       vmin=vminRe,
                       vmax=vmaxRe)
    graphes.colorbar()
    plt.title('Local $Re_\lambda$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x,
                       Mfluc.y,
                       Mfluc.Re_lambdaTx_Local,
                       fignum=2,
                       vmin=vminRe,
                       vmax=vmaxRe)
    graphes.colorbar()
    plt.title('Local $Re_{\lambda,x}$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x,
                       Mfluc.y,
                       Mfluc.Re_lambdaTy_Local,
                       fignum=3,
                       vmin=vminRe,
                       vmax=vmaxRe)
    graphes.colorbar()
    plt.title('Local $Re_{\lambda,y}$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')

    graphes.color_plot(Mfluc.x,
                       Mfluc.y,
                       Mfluc.lambdaT_Local,
                       fignum=4,
                       vmin=vminLambda,
                       vmax=vmaxLambda)
    graphes.colorbar()
    plt.title('Local $\lambda$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x,
                       Mfluc.y,
                       Mfluc.lambdaTx_Local,
                       fignum=5,
                       vmin=vminLambda,
                       vmax=vmaxLambda)
    graphes.colorbar()
    plt.title('Local $\lambda_x$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x,
                       Mfluc.y,
                       Mfluc.lambdaTy_Local,
                       fignum=6,
                       vmin=vminLambda,
                       vmax=vmaxLambda)
    graphes.colorbar()
    plt.title('Local $\lambda_y$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
Example #8
0
def plot_lambda_Re_lambda_heatmaps(Mfluc,
                                   cutoff=10**(-3),
                                   vminRe=0,
                                   vmaxRe=800,
                                   vminLambda=0,
                                   vmaxLambda=800,
                                   nu=1.004,
                                   x0=None,
                                   y0=None,
                                   x1=None,
                                   y1=None,
                                   redo=False):
    """
    Plots a heatmap of local Re_lambda and lambda
    Parameters
    ----------
    Mfluc
    cutoff
    vminRe
    vmaxRe
    vminLambda
    vmaxLambda
    nu

    Returns
    -------

    """
    if x0 is None:
        x0, y0 = 0, 0
        x1, y1 = Mfluc.Ux.shape[1], Mfluc.Ux.shape[0]
        print 'Will average from (%d, %d) to (%d, %d)  (index)' % (x0, y0, x1,
                                                                   y1)
    nrows, ncolumns = y1 - y0, x1 - x0

    Mfluc.lambdaT_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    Mfluc.lambdaTx_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    Mfluc.lambdaTy_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    Mfluc.Re_lambdaT_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    Mfluc.Re_lambdaTx_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))
    Mfluc.Re_lambdaTy_Local = np.zeros((Mfluc.Ux.shape[0], Mfluc.Ux.shape[1]))

    if not hasattr(Mfluc, 'U2ave') or redo:
        print 'Mfluc does not have attribute Mfluc.U2ave. Calculate it.'
        Mfluc = compute_u2_duidxi(Mfluc, x0=x0, y0=y0, x1=x1, y1=y1)
        print Mfluc.Ux2ave.shape

    # Calculate Local Taylor microscale: lambdaT
    for y in range(0, Mfluc.Ux.shape[0] - 1):
        for x in range(0, Mfluc.Ux.shape[1] - 1):
            if Mfluc.dUidxi2ave[y, x] < cutoff:
                Mfluc.lambdaT_Local[y, x] = 0
            else:
                Mfluc.lambdaT_Local[y, x] = np.sqrt(Mfluc.U2ave[y, x] /
                                                    Mfluc.dUidxi2ave[y, x])
                Mfluc.Re_lambdaT_Local[y, x] = Mfluc.lambdaT_Local[
                    y, x] * np.sqrt(Mfluc.U2ave[y, x]) / nu
            if Mfluc.dUxdx2ave[y, x] < cutoff:
                Mfluc.lambdaTx_Local[y, x] = 0
            else:
                Mfluc.lambdaTx_Local[y, x] = np.sqrt(Mfluc.Ux2ave[y, x] /
                                                     Mfluc.dUxdx2ave[y, x])
                Mfluc.Re_lambdaTx_Local[y, x] = Mfluc.lambdaTx_Local[
                    y, x] * np.sqrt(Mfluc.Ux2ave[y, x]) / nu
            if Mfluc.dUydy2ave[y, x] < cutoff:
                Mfluc.lambdaTy_Local[y, x] = 0
            else:
                Mfluc.lambdaTy_Local[y, x] = np.sqrt(Mfluc.Uy2ave[y, x] /
                                                     Mfluc.dUydy2ave[y, x])
                Mfluc.Re_lambdaTy_Local[y, x] = Mfluc.lambdaTy_Local[
                    y, x] * np.sqrt(Mfluc.Uy2ave[y, x]) / nu

    # Plot Taylor miroscale
    graphes.color_plot(Mfluc.x[y0:y1, x0:x1],
                       Mfluc.y[y0:y1, x0:x1],
                       Mfluc.Re_lambdaT_Local[y0:y1, x0:x1],
                       fignum=1,
                       vmin=vminRe,
                       vmax=vmaxRe)
    graphes.colorbar()
    plt.title('Local $Re_\lambda$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x[y0:y1, x0:x1],
                       Mfluc.y[y0:y1, x0:x1],
                       Mfluc.Re_lambdaTx_Local[y0:y1, x0:x1],
                       fignum=2,
                       vmin=vminRe,
                       vmax=vmaxRe)
    graphes.colorbar()
    plt.title('Local $Re_{\lambda,x}$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x[y0:y1, x0:x1],
                       Mfluc.y[y0:y1, x0:x1],
                       Mfluc.Re_lambdaTy_Local[y0:y1, x0:x1],
                       fignum=3,
                       vmin=vminRe,
                       vmax=vmaxRe)
    graphes.colorbar()
    plt.title('Local $Re_{\lambda,y}$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')

    graphes.color_plot(Mfluc.x[y0:y1, x0:x1],
                       Mfluc.y[y0:y1, x0:x1],
                       Mfluc.lambdaT_Local[y0:y1, x0:x1],
                       fignum=4,
                       vmin=vminLambda,
                       vmax=vmaxLambda)
    graphes.colorbar()
    plt.title('Local $\lambda$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x[y0:y1, x0:x1],
                       Mfluc.y[y0:y1, x0:x1],
                       Mfluc.lambdaTx_Local[y0:y1, x0:x1],
                       fignum=5,
                       vmin=vminLambda,
                       vmax=vmaxLambda)
    graphes.colorbar()
    plt.title('Local $\lambda_x$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
    graphes.color_plot(Mfluc.x[y0:y1, x0:x1],
                       Mfluc.y[y0:y1, x0:x1],
                       Mfluc.lambdaTy_Local[y0:y1, x0:x1],
                       fignum=6,
                       vmin=vminLambda,
                       vmax=vmaxLambda)
    graphes.colorbar()
    plt.title('Local $\lambda_y$')
    plt.xlabel('X (mm)')
    plt.ylabel('Y (mm)')
print M.Uy[10, :, 0]
print M.Id.date
print M.Id.index

for M in Mlist:
    print(M.Sdata.fileCine[-20:-5])
    print(M.Sdata.fileDir)
    print(M.Sdata.filename)  # name of the file(SData) that stores measures (M)
    print(M.Sdata.param)
    print M.shape()

# Plot the time averaged energy
frame = 10
# args are (M, variable, frame, vmin, vman)
graphes.Mplot(M, 'E', frame, vmin=0, vmax=100000)
graphes.colorbar()

# Plot the vorticity at a particular time
graphes.Mplot(M, 'omega', frame, vmin=-300, vmax=300)
graphes.colorbar()

# Plot the enstrophy at a particular time (frame#)
graphes.Mplot(M, 'enstrophy', frame, vmin=0, vmax=90000)
graphes.colorbar()

########################################################
figs = {}
fields, names, vmin, vmax, labels, units = comp.std_fields()
# print(M.param.v)
indices = range(50, M.Ux.shape[2])
field = 'E'