Here is a quick overview of how to use the two-layer model. See the
:py:class:pyqg.QGModel
api documentation for further details.
First import numpy, matplotlib, and pyqg:
In [1]:
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
import pyqg
In [2]:
year = 24*60*60*360.
m = pyqg.QGModel(tmax=10*year, twrite=10000, tavestart=5*year)
m.run()
In [3]:
q_upper = m.q[0] + m.Qy[0]*m.y
plt.contourf(m.x, m.y, q_upper, 12, cmap='RdBu_r')
plt.xlabel('x'); plt.ylabel('y'); plt.title('Upper Layer PV')
plt.colorbar();
In [4]:
m.describe_diagnostics()
To look at the wavenumber energy spectrum, we plot the KEspec
diagnostic.
(Note that summing along the l-axis, as in this example, does not give us
a true isotropic wavenumber spectrum.)
In [5]:
kespec_u = m.get_diagnostic('KEspec')[0].sum(axis=0)
kespec_l = m.get_diagnostic('KEspec')[1].sum(axis=0)
plt.loglog( m.kk, kespec_u, '.-' )
plt.loglog( m.kk, kespec_l, '.-' )
plt.legend(['upper layer','lower layer'], loc='lower left')
plt.ylim([1e-9,1e-3]); plt.xlim([m.kk.min(), m.kk.max()])
plt.xlabel(r'k (m$^{-1}$)'); plt.grid()
plt.title('Kinetic Energy Spectrum');
We can also plot the spectral fluxes of energy.
In [6]:
ebud = [ -m.get_diagnostic('APEgenspec').sum(axis=0),
-m.get_diagnostic('APEflux').sum(axis=0),
-m.get_diagnostic('KEflux').sum(axis=0),
-m.rek*m.del2*m.get_diagnostic('KEspec')[1].sum(axis=0)*m.M**2 ]
ebud.append(-np.vstack(ebud).sum(axis=0))
ebud_labels = ['APE gen','APE flux','KE flux','Diss.','Resid.']
[plt.semilogx(m.kk, term) for term in ebud]
plt.legend(ebud_labels, loc='upper right')
plt.xlim([m.kk.min(), m.kk.max()])
plt.xlabel(r'k (m$^{-1}$)'); plt.grid()
plt.title('Spectral Energy Transfers');
In [ ]: