Exemplo n.º 1
0
def LE_SimStr(b, X):
    """
	A module to produce data from simulation and analyse it to streamplot.
	"""

    datafile = LE_Simulate.LEsim(b, X)
    LEstr(datafile)

    return
Exemplo n.º 2
0
def LE_SimPlt(b, X, timefac, BW, smooth):
    """
	Wrapper for simulation + streamplot.
	"""
    me = "LE_Plot.LE_SimPlt: "

    print "\n== " + me + "b =", b, " X =", X, " BW =", BW, "==\n"

    t0 = time.time()

    ## Filenames
    trafile, rndfile, pdffile, strfile, n = get_filenames(b, X, timefac, BW)

    ## GET_TRADATA
    ## Time-series / trajectory data: load or simulate
    try:
        txyxidata = np.load(trafile + ".npy")[:n, :]
        print me + "Trajectory file found", trafile + ".npy"
    except IOError:
        print me + "No trajectory file found. Simulating..."
        txyxidata = LE_Simulate.LEsim(b, X, timefac, BW)

    print me, collect()

    ## GET_STRDATA
    ## Interpolated current data: load or calculate
    try:
        A = np.load(strfile + ".npy")
        grd = A.shape[1]
        x, y, gvx, gvy = A[0], A[1], A[2:grd + 2], A[grd + 2:]
        oargs = np.loadtxt(strfile + ".hdr")
        print me + "Steamgrid file found", strfile + ".npy"
    except IOError:
        print me + "No streamgrid file found. Calculating..."
        x, y, gvx, gvy, oargs = calc_grid(txyxidata[1:3], b, X, strfile, BW)

    print me, collect()

    ## Plots
    # plot_rand(txyxidata, b,X, rndfile)
    # print me,collect()
    plot_pdf(txyxidata[1:3], b, X, pdffile)
    print me, collect()
    plot_stream(x, y, gvx, gvy, np.append(oargs, smooth), strfile)
    print me, collect()

    print me + "Total time", round(time.time() - t0, 1), "seconds"
    return
Exemplo n.º 3
0
def plot_stream_fromPDF(b, X, timefac, BW, smooth):
    """
	Create PDF from trajectory, calculate current field, and plot.
	"""
    me = "LE_PlotII.plot_stream_fromPDF: "

    ## Filenames
    trafile, rndfile, pdffile, strfile, n = get_filenames(b, X, timefac, BW)

    ## Read in trajectory data (or simulate anew)
    try:
        xydata = np.load(trafile + ".npy")[1:3, :n]
        print me + "Trajectory file found", trafile + ".npy"
    except IOError:
        print me + "No trajectory file found. Simulating..."
        xydata = LE_Simulate.LEsim(b, X, timefac, BW)[1:3, :n]

    ## Create histogram and save PDF plot
    P, x, y = plot_pdf(xydata, b, X, pdffile)
    xmax, ymax = np.abs(x).max(), np.abs(y).max()
    x = (x[1:] + x[:-1]) * 0.5
    y = (y[1:] + y[:-1]) * 0.5
    gx, gy = np.meshgrid(x, y)
    gy = -gy

    ## Force field
    f = LE_Simulate.FBW(gx, b, X) if BW else LE_Simulate.FHO(gx, b, X)

    ## Compute currents (on-grid)
    Jx, Jy = J_BW(P, b, f, gy)
    Jt = np.sqrt(Jx * Jx + Jy * Jy)

    ## --------------------------------------------------------------------

    ## Smooth data
    if smooth is not 0.0:
        Jx = gaussian_filter(Jx, smooth)
        Jy = gaussian_filter(Jy, smooth)
        Jt = gaussian_filter(Jt, smooth)
    strfile += "_sm" + str(smooth)

    ## --------------------------------------------------------------------

    ## Plotting

    t0 = time.time()
    fs = 25

    fig = plt.figure(facecolor="white")
    fig.suptitle(strfile)

    ##############################
    P /= np.trapz(P.sum(axis=1), y)
    if False:
        v = 0.051**2  #0.115**2
        Pex = 1 / np.sqrt(2 * np.pi * v) * np.exp(-y * y * 0.5 / v)
        ## Plot P(y) against y
        plt.plot(y, P.sum(axis=1), "r-")
        plt.plot(y, Pex, "b--")
        plt.xlabel("$y$")
        plt.ylabel("$P(y)$")
        plt.savefig("Py_b" + str(b) + ".png")
        plt.show()
        ## Plot Jy against y
        plt.plot(y, Jy.sum(axis=1), "r-")
        plt.plot(y, -Pex * y * (b / v - 1) / (x[1] - x[0]), "b--")
        plt.xlabel("$y$")
        plt.ylabel("$J_y(y)$")
        plt.savefig("Jy_b" + str(b) + ".png")
        plt.show()
        ## Plot P(x) against x
        plt.plot(x, P.sum(axis=0), "r-")
        plt.xlabel("$x$")
        plt.ylabel("$P(x)$")
        plt.savefig("Px_b" + str(b) + ".png")
        plt.show()
        ## Plot Jx against y
        plt.plot(y, Jx.sum(axis=1), "r-")
        plt.plot(y, -Pex * y / (x[1] - x[0]), "b--")
        plt.xlabel("$y$")
        plt.ylabel("$J_x(y)$")
        plt.savefig("Jx_b" + str(b) + ".png")
        plt.show()
        exit()
    ##############################

    ## Add subplot with exact solution
    if not BW:
        ax1 = fig.add_subplot(121, aspect="auto")
        ax2 = fig.add_subplot(122, aspect="auto", sharey=ax1)
        plot_exact((ax2, xmax, ymax, b, False))
        # fig.tight_layout();fig.subplots_adjust(top=0.93)
        print me + "Plotting exact", round(time.time() - t0, 1), "seconds"
        plot_separatrix(ax1, b, xmax, ymax, 2)
    else:
        ax1 = fig.add_subplot(111)
        plot_walls(ax1, X, xmax, ymax, 2)

    ## Accoutrements
    ax1.set_xlim([-xmax, xmax])
    ax1.set_ylim([-ymax, ymax])
    ax1.set_xlabel("$x$", fontsize=fs)
    ax1.set_ylabel("$\eta$", fontsize=fs)

    ## Streamplot
    t0 = time.time()
    lw = 2  #3.0*Jt/Jt.max()
    q = 1
    ax1.quiver(gx[::q, ::q], gy[::q, ::q], Jx[::q, ::q], Jy[::q, ::q])
    # ax1.streamplot(gx,gy, Jx,Jy, arrowsize=1.8, arrowstyle="->", linewidth=lw, minlength=xmax/20)
    print me + "Plotting streamlines ", round(time.time() - t0, 1), "seconds"
    t0 = time.time()

    ## Output
    fig.savefig(strfile + "FP.png", edgecolor="none")
    print me + "Plot saved as\n  ", strfile + "FP.png"
    plt.show()
    plt.close()

    return