In [1]:
import gnuplot as gp
import numpy as np
from numpy import random, fft

from IPython.display import display, Image

In [4]:
import cft

N = 16
L = 22
B = cft.Box(2, N, L)

def garfield(B, wn, P):
    f = fft.ifftn(fft.fftn(wn) * np.sqrt(P(B.K))).real
    f /= f.std()
    return f

P = [cft.Power_law( 0) * cft.Scale(B, 0.1),
     cft.Power_law(-1) * cft.Scale(B, 0.1),
     cft.Power_law(-2) * cft.Scale(B, 0.1)]

wn = random.normal(0, 1, [N, N])

data = [garfield(B, wn, p) for p in P]
phi = [fft.ifftn(fft.fftn(d) * cft.Potential()(B.K)).real for d in data]

def displacement(B, phi, t = 1.0):
    phi_f = fft.fftn(phi)s
    vx = fft.ifftn(phi_f * cft.D(1)(B.K)).real
    vy = fft.ifftn(phi_f * cft.D(2)(B.K)).real
    Q = np.indices(B.shape) * (L/N)
    X = Q + np.array([vx, vy])
    return X

g = gp.Gnuplot() ; g("set term pngcairo size 900, 600") ; g("set output 'tmp.png'")
g("set multiplot layout 2,3", "unset colorbox")
for d in phi:
    g(gp.plot_data(gp.matrix(d, "with image".format(L/N, L/2))))
for d in [displacement(B, p).transpose([1,2,0]).reshape([N**2, 2]) for p in phi]:
    g(gp.plot_data(gp.record(d, "with dots lc 0")))
g("unset multiplot")
g.terminate()


plot '-' binary matrix with image
plot '-' binary matrix with image
plot '-' binary matrix with image
plot '-' binary record=256 format='%float64%float64' with dots lc 0
plot '-' binary record=256 format='%float64%float64' with dots lc 0
plot '-' binary record=256 format='%float64%float64' with dots lc 0

In [3]:
display(Image(filename='tmp.png'))



In [ ]: