"""Demonstrate the Linear Advection (LA) model.""" from matplotlib import pyplot as plt import dapper.mods as modelling from dapper.mods.LA.raanes2015 import X0, step from dapper.tools.viz import amplitude_animation simulator = modelling.with_recursion(step, prog="Simulating") x0 = X0.sample(1).squeeze() dt = 1 xx = simulator(x0, k=500, t=0, dt=dt) anim = amplitude_animation(xx, dt) plt.show()
"""Demonstrate the Lorenz-96 model.""" # For a deeper introduction, see # "DA-tutorials/T4 - Dynamical systems, chaos, Lorenz.ipynb" from matplotlib import pyplot as plt from numpy import eye import dapper as dpr from dapper.mods.Lorenz96 import step, x0 from dapper.tools.viz import amplitude_animation simulator = dpr.with_recursion(step, prog="Simulating") x0 = x0(40) E0 = x0 + 1e-3*eye(len(x0))[:3] dt = 0.05 xx = simulator(E0, k=500, t=0, dt=dt) ani = amplitude_animation(xx, dt=dt, interval=70) plt.show()
T = 150 dt = model.dt K = round(T / dt) # IC N = 3 tt = np.zeros((K + 1, )) EE = np.zeros((K + 1, N, model.Nx)) # x0 = x0_Kassam EE[0] = model.x0 + 1e-3 * np.random.randn(N, model.Nx) # Integrate for k in range(1, K + 1): EE[k] = model.step(EE[k - 1], np.nan, dt) tt[k] = k * dt # Animate from dapper.tools.viz import amplitude_animation ani = amplitude_animation(EE, dt) # Plot plt.figure() n = 0 plt.contourf(model.grid, tt, EE[:, n, :], 60) plt.colorbar() plt.set_cmap('seismic') plt.axis('tight') plt.title('Hovmoller for K-S system, member %d' % n) plt.ylabel('Time (t)') plt.xlabel('Space (x)')