Exemple #1
0
def handle_raw_snap():
    import load_snap
    from half_rho import untangle
    import snake
    import half_peak
    os.chdir(r"D:\tmp")
    Lx = 180
    Ly = 1000
    sigma = [5, 1]
    r = np.round(np.logspace(2, 18, 17, base=np.sqrt(2))).astype(int)
    G1 = np.zeros(r.size)
    G2 = np.zeros(r.size)
    count = 0
    snap = load_snap.RawSnap(r"so_%g_%g_%d_%d_%d_%d_%d.bin" %
                             (0.35, 0, Lx, Ly, Lx * Ly, 2000, 1234))
    n = snap.get_num_frames()
    print("n=", n)
    t_beg = 250
    t_end = 300
    for i, frame in enumerate(snap.gene_frames(t_beg, t_end)):
        x, y, theta = frame
        rho = load_snap.coarse_grain2(x,
                                      y,
                                      theta,
                                      Lx=Lx,
                                      Ly=Ly,
                                      ncols=Lx,
                                      nrows=Ly).astype(float)
        xh1, rho_h = half_peak.find_interface(rho, sigma=sigma)
        rho_s = gaussian_filter(rho, sigma=sigma)
        xh2, yh2 = snake.find_interface(rho_s,
                                        0.5,
                                        0.1,
                                        0.25,
                                        400,
                                        rho_h,
                                        dx=5)
        xh1 = untangle(xh1, Lx)
        xh2 = untangle(xh2, Lx)
        G1 += cal_G(xh1, r)
        G2 += cal_G(xh2, r)
        count += 1
        print("i = ", i)
    G1 /= count
    G2 /= count
    plt.plot(r, G1)
    plt.plot(r, G2)
    plt.xscale("log")
    plt.yscale("log")
    plt.show()
    plt.close()
    for i in range(G1.size):
        print(r[i], G1[i], G2[i])
    print(count)
Exemple #2
0
def cal_spectrum(Lx, Ly, sigma_y=10, show=False, out=False, eps=0, dt=1):
    file = r"so_0.35_%g_%d_%d_%d_2000_1234.bin" % (eps, Lx, Ly, Lx * Ly)
    snap = load_snap.RawSnap(file)
    if not isinstance(sigma_y, list):
        nrows = 1
        sigma_y = [sigma_y]
    else:
        nrows = len(sigma_y)
    ncols = Ly // 2 + 1
    q = np.arange(ncols) / Ly
    spectrum = np.zeros((nrows, ncols))
    count = np.zeros(nrows, int)
    for frame in snap.gene_frames(beg_idx=300, interval=dt):
        x, y, theta = frame
        rho = load_snap.coarse_grain2(x, y, theta, Lx=Lx, Ly=Ly).astype(float)
        for i, sy in enumerate(sigma_y):
            try:
                xh, rho_h = find_interface(rho, sigma=[sy, 1])
                xh = untangle(xh, Lx)
                h = xh - np.mean(xh)
                hq = np.fft.rfft(h) / Ly
                A2 = np.abs(hq)**2
                spectrum[i] += A2
                count[i] += 1
            except:
                pass
        print("t=%d" % (dt * count[-1]))
    for i in range(nrows):
        spectrum[i] /= count[i]
    if show:
        plt.loglog(q, spectrum)
        plt.show()
        plt.close()
    if out:
        outfile = "hq_%g_%d_%d.dat" % (eps, Lx, Ly)
        with open(outfile, "w") as f:
            for i in range(q.size):
                line = "%f" % (q[i]**2)
                for j in range(nrows):
                    line += "\t%.8f" % (spectrum[j, i])
                line += "\n"
                f.write(line)
Exemple #3
0
def time_ave(Lx, Ly, sigma_y=100, show=False, out=False, eps=0, dt=1):
    file = r"so_0.35_%g_%d_%d_%d_2000_1234.bin" % (eps, Lx, Ly, Lx * Ly)
    snap = load_snap.RawSnap(file)
    if not isinstance(sigma_y, list):
        nrows = 1
        sigma_y = [sigma_y]
    else:
        nrows = len(sigma_y)
    ncols = Lx
    rho_mean = np.zeros((nrows, ncols))
    count = np.zeros(nrows, int)
    x0 = np.arange(Lx) + 0.5
    for frame in snap.gene_frames(beg_idx=300, interval=dt):
        x, y, theta = frame
        rho = load_snap.coarse_grain2(x, y, theta, Lx=Lx, Ly=Ly).astype(float)
        rho_real = load_snap.coarse_grain(x, y, Lx=Lx, Ly=Ly)
        for i, sy in enumerate(sigma_y):
            try:
                xh, rho_h = find_interface(rho, sigma=[sy, 1])
                rho_mean[i] += ave_one_frame(rho_real, xh)
                count[i] += 1
            except:
                pass
        print("t=%d" % (dt * count[-1]))
    for i in range(nrows):
        rho_mean[i] /= count[i]
    if show:
        for i in range(nrows):
            plt.plot(x0, rho_mean[i])
        plt.show()
        plt.close()
    if out:
        outfile = "avePeak_%g_%d_%d.dat" % (eps, Lx, Ly)
        with open(outfile, "w") as f:
            for i in range(ncols):
                line = "%f" % (x0[i])
                for j in range(nrows):
                    line += "\t%.8f" % (rho_mean[j, i])
                line += "\n"
                f.write(line)
Exemple #4
0
                             start_row,
                             start_idx_h,
                             left=leftward,
                             debug=debug)
    xh = get_xh(rho_s, idx_h, rho_h)
    return xh, rho_h


if __name__ == "__main__":
    import os
    import load_snap
    import half_rho
    os.chdir(r"D:\tmp")
    Lx = 180
    Ly = 1000
    snap = load_snap.RawSnap(r"so_%g_%g_%d_%d_%d_%d_%d.bin" %
                             (0.35, 0, Lx, Ly, Lx * Ly, 2000, 1234))
    debug = 1
    t_beg = 1758
    t_end = 1759
    w1 = []
    w2 = []
    for i, frame in enumerate(snap.gene_frames(t_beg, t_end)):
        x, y, theta = frame
        rho = load_snap.coarse_grain2(x, y, theta, Lx=Lx, Ly=Ly).astype(float)
        xh, rho_h = find_interface(rho, sigma=[1, 1])
        xh2, rho_h2 = half_rho.find_interface(rho, sigma=[5, 1])
        xh3, rho_h3 = half_rho.find_interface(rho, sigma=[10, 1])
        xh = half_rho.untangle(xh, Lx)
        xh2 = half_rho.untangle(xh2, Lx)
        xh3 = half_rho.untangle(xh3, Lx)
        yh = np.linspace(0, Ly - 1, Ly)
Exemple #5
0

if __name__ == "__main__":
    import os
    import load_snap
    if platform.system() is not "Windows":
        os.chdir(r"snap_one")
    else:
        os.chdir(r"D:\tmp")
    Lx = int(sys.argv[1])
    Ly = int(sys.argv[2])
    eta = 0.35
    eps = 0
    dt = 2000
    seed = 1234
    snap = load_snap.RawSnap(r"so_%g_%g_%d_%d_%d_%d_%d.bin" %
                             (eta, eps, Lx, Ly, Lx * Ly, dt, seed))
    file = r"wh_%g_%g_%d_%d_%d_%d_%d.dat" % (eta, eps, Lx, Ly, Lx * Ly, dt,
                                             seed)
    f = open(file, "w")
    sigma_y = [5, 10, 15, 20, 25]
    for i, frame in enumerate(snap.gene_frames()):
        x, y, theta = frame
        rho = load_snap.coarse_grain2(
            x, y, theta, Lx=Lx, Ly=Ly, ncols=Lx, nrows=Ly) * 1.0
        line = ""
        for sy in sigma_y:
            try:
                xh, rho_h = find_interface(rho, sigma=[sy, 1])
                w = np.var(untangle(xh, Lx))
            except:
                w = -1