Exemplo n.º 1
0
def Curl_uD_components(u,v,D_,T,dx,dy):
	"A function that calculates the time-mean curl of uD"

	uD = timeAverage(u * D_, T, len(T)-1)
	vD = timeAverage(v * D_, T, len(T)-1)

	return diff(vD,1,1,dx), -diff(uD,0,0,dy)	
Exemplo n.º 2
0
def footprint(uq,Uq,uQ,UQ,vq,vQ,x_nd,T_nd,dx_nd,dy_nd,N,Nt):
	'''
	This code calculates the PV footprint, i.e. the PV flux convergence defined by
	P = -(div(u*q,v*q)), where _av denotees the time average.
	We will take the time average over one whole forcing period, and subtract this PV flux
	convergence from the PV flux convergence at the end of one period.
	To calculate footprints, we use the full PV and velocity profiles.
	'''
		
	uq_full = uq + Uq + uQ		# Total zonal PV flux
	#for j in range(0,N):
		#qu_full[:,j,:] = qu_full[:,j,:] + UQ[j];
	vq_full = vq + vQ			# Total meridional PV flux	
	
	# Time-averaging
	uq_full = timeAverage(uq_full,T_nd,Nt)
	vq_full = timeAverage(vq_full,T_nd,Nt)

	# Calculate the footprint.
	P = - diff(uq_full,1,1,dx_nd) - diff(vq_full,0,0,dy_nd)

	P = extend(P)
		
	# We are interested in the zonal average of the footprint
	P_xav = np.trapz(P,x_nd,dx_nd,axis=1) # / 1 not required.

	return P, P_xav
Exemplo n.º 3
0
def footprint(u_full, v, q_full, x, y, dx, dy, T, Nt):
    # This code calculates the PV footprint, i.e. the PV flux convergence defined by
    # P = -(div(u*q,v*q)-div((u*q)_av,(v*q)_av)), where _av denotees the time average.
    # We will take the time average over one whole forcing period, and subtract this PV flux
    # convergence from the PV flux convergence at the end of one period.
    # To calculate footprints, we use the full PV and velocity profiles.

    uq = q_full * u_full
    # Zonal PV flux
    vq = q_full * v
    # Meridional PV flux

    # Next step: taking appropriate derivatives of the fluxes. To save space, we won't define new variables, but instead overwrite the old ones.
    # From these derivatives we can calculate the

    # Time-averaging
    uq = timeAverage(uq, T, Nt)
    vq = timeAverage(vq, T, Nt)

    # Calculate the footprint.
    P = -diff(uq, 1, 1, dx) - diff(vq, 0, 0, dy)

    P = extend(P)

    # We are interested in the zonal average of the footprint
    P_xav = np.trapz(P, x, dx, axis=1)
    # / 1 not required.

    return P, P_xav
Exemplo n.º 4
0
def conv(uE, vE, T_nd, Nt, x_nd, dx_nd, y_nd, dy_nd):
    '''Time-mean convergence of energy fluxes.'''

    uE_av = timeAverage(uE, T_nd, Nt)
    vE_av = timeAverage(vE, T_nd, Nt)

    Econv = -diff(uE_av, 1, 1, dx_nd) - diff(vE_av, 0, 0, dy_nd)
    Econv = extend(Econv)

    Econv_xav = np.trapz(Econv, x_nd, dx_nd, axis=1)  # / 1 not required.

    return Econv, Econv_xav
Exemplo n.º 5
0
def KEspectrum(u, v, K, y, T, Nt, N):
    '''Return kinetic energy (not column-averaged) spectrum, taking spectral solution as input'''

    from scipy.signal import welch

    dy = y[1] - y[0]
    dt = T[1] - T[0]

    N4 = N // 4

    u4 = u[N4:N - N4, N4:N - N4, :]
    v4 = v[N4:N - N4, N4:N - N4, :]
    y4 = y[N4:N - N4]

    KEspec = 0.5 * (u4**2 + v4**2)
    freq, KEspec = welch(KEspec, axis=1)
    print(np.shape(KEspec))

    KEspec = timeAverage(KEspec, T, Nt)
    KEspec = np.trapz(KEspec, y4, dy, axis=0)

    #freq, KEspec = welch(KEspec)

    plt.plot(KEspec)
    plt.show()
    np.save('KEouter', KEspec)

    return KEspec
Exemplo n.º 6
0
def budgetDissipation2(U0, H0, u, v, h, Ro, Re, gamma, dx, dy, T, Nt, N):
    ''' Calculate time-dependent and time-mean energy budget due to dissipation.
	Make sure to use full u, v and h fields. Contribution from background terms
	will be removed after time averaging. This function makes sure background isn't
	subject to viscosity/drag.'''

    uxx = np.zeros(u.shape)
    uyy = np.zeros(u.shape)
    vxx = np.zeros(u.shape)
    vyy = np.zeros(u.shape)

    for ti in range(0, Nt):

        uyy[:, :, ti] = diff(diff(u[:, :, ti], 0, 0, dy), 0, 0, dy)
        uxx[:, :, ti] = diff(diff(u[:, :, ti], 1, 1, dx), 1, 1, dx)

        vyy[:, :, ti] = diff(diff(v[:, :, ti], 0, 0, dy), 0, 0, dy)
        vxx[:, :, ti] = diff(diff(v[:, :, ti], 1, 1, dx), 1, 1, dx)

    H = np.zeros(u.shape)
    U = np.zeros(u.shape)
    for ti in range(0, Nt):
        for i in range(0, N):
            H[:, i, ti] = H0
            U[:, i, ti] = U0

    Ed = (H * u + U * h + u * h) * (
        (uxx + uyy) / Re - gamma * u / Ro) + (H * v + v * h) * (
            (vxx + vyy) / Re - gamma * v / Ro)
    # This omits a couple of terms that average to zero.

    Ed_av = timeAverage(Ed, T, Nt)

    return Ed, Ed_av
Exemplo n.º 7
0
def footprintComponents(uq,Uq,uQ,vq,vQ,x_nd,T_nd,dx_nd,dy_nd,N,Nt):
	'''
	A function that calculates the PV footprint of the 1L SW solution in terms of its components, allowing for analysis.
	The function calculates the following terms: (1) uq, (2) Uq, (3) uQ, (4) UQ, (5) vq and (6) vQ. (UQ has zero zonal derivative.)
	The zonal/meridional derivative of the zonal/meridional PV flux is taken, averaged over one forcing period.
	Lastly, the zonal averages are calculated and everything useful returned.
	'''

	# Time averaging.
	uq = timeAverage(uq,T_nd,Nt);
	Uq = timeAverage(Uq,T_nd,Nt);
	uQ = timeAverage(uQ,T_nd,Nt);
	vq = timeAverage(vq,T_nd,Nt);
	vQ = timeAverage(vQ,T_nd,Nt);

	# Derivatives (no need to operate on UQ) and time-averaging.
	P_uq = - diff(uq,1,1,dx_nd);
	P_uQ = - diff(uQ,1,1,dx_nd);
	P_Uq = - diff(Uq,1,1,dx_nd);
	P_vQ = - diff(vQ,0,0,dy_nd);
	P_vq = - diff(vq,0,0,dy_nd);

	# Extend all arrays to include the final x gridpoint.
	P_uq = extend(P_uq);
	P_uQ = extend(P_uQ);
	P_Uq = extend(P_Uq);
	P_vQ = extend(P_vQ);
	P_vq = extend(P_vq);

	# Normalisation by AmpF_nd not needed if normalised quanities are passed into the function.

	P = P_uq + P_uQ + P_Uq + P_vq + P_vQ;

	# Zonal averaging 
	P_uq_xav = np.trapz(P_uq,x_nd,dx_nd,axis=1);
	P_uQ_xav = np.trapz(P_uQ,x_nd,dx_nd,axis=1);
	P_Uq_xav = np.trapz(P_Uq,x_nd,dx_nd,axis=1);
	P_vq_xav = np.trapz(P_vq,x_nd,dx_nd,axis=1);
	P_vQ_xav = np.trapz(P_vQ,x_nd,dx_nd,axis=1);
	
	#P_xav = np.trapz(P_tav,x_nd[:N],dx_nd,axis=1);
	P_xav = P_uq_xav + P_uQ_xav + P_Uq_xav + P_vq_xav + P_vQ_xav;
	# Tests confirm that the multiple approaches for calculating P_xav and P_tav yield the same results.

	return P, P_uq, P_uQ, P_Uq, P_vq, P_vQ, P_xav, P_uq_xav, P_uQ_xav, P_Uq_xav, P_vq_xav, P_vQ_xav;
Exemplo n.º 8
0
def footprint(uh, uH, Uh, vh, vH, x_nd, y_nd, T_nd, dx_nd, dy_nd, dt_nd, N,
              Nt):

    bu_full = uh + uH + Uh
    # Zonal thickness flux
    bv_full = vh + vH
    # Meridional thickness flux

    bu_full = timeAverage(bu_full, T_nd, Nt)
    bv_full = timeAverage(bv_full, T_nd, Nt)

    # Calculate the footprint.
    B = -diff(bu_full, 1, 1, dx_nd) - diff(bv_full, 0, 0, dy_nd)

    B = extend(B)

    # We are interested in the zonal average of the footprint
    B_xav = np.trapz(B, x_nd, dx_nd, axis=1)

    return B, B_xav
Exemplo n.º 9
0
def footprint(uu, uv, vv, x_nd, T_nd, dx_nd, dy_nd, N, Nt):
    # A function that calculates the momentum footprint of the 1L SW solution as produced by RSW.py

    # Time-averaging
    uu = timeAverage(uu, T_nd, Nt)
    uv = timeAverage(uv, T_nd, Nt)
    vv = timeAverage(vv, T_nd, Nt)

    # Two footprint terms to calculate
    Mu = -diff(uu, 1, 1, dx_nd) - diff(uv, 0, 0, dy_nd)
    Mv = -diff(uv, 1, 1, dx_nd) - diff(vv, 0, 0, dy_nd)

    Mu = extend(Mu)
    Mv = extend(Mv)

    # We are interested in the zonal average of the footprint
    Mu_xav = np.trapz(Mu, x_nd, dx_nd, axis=1)
    Mv_xav = np.trapz(Mv, x_nd, dx_nd, axis=1)

    return Mu, Mv, Mu_xav, Mv_xav
Exemplo n.º 10
0
def budgetDissipation3(U0, H0, u, v, h, Ro, Re, gamma, dx, dy, T, Nt, N):
    ''' Calculate time-dependent and time-mean energy budget due to dissipation.
	Make sure to use full u, v and h fields. Contribution from background terms
	will be removed after time averaging. This function makes sure background isn't
	subject to viscosity/drag.'''

    # Contribution from dissipation terms, if we assume it only acts upon eddy flow, is h_full * u_full * u.
    # This separates this function from the previous two.

    uxx = np.zeros(u.shape)
    uyy = np.zeros(u.shape)
    vxx = np.zeros(u.shape)
    vyy = np.zeros(u.shape)

    for ti in range(0, Nt):

        uyy[:, :, ti] = diff(diff(u[:, :, ti], 0, 0, dy), 0, 0, dy)
        uxx[:, :, ti] = diff(diff(u[:, :, ti], 1, 1, dx), 1, 1, dx)

        vyy[:, :, ti] = diff(diff(v[:, :, ti], 0, 0, dy), 0, 0, dy)
        vxx[:, :, ti] = diff(diff(v[:, :, ti], 1, 1, dx), 1, 1, dx)

    H = np.zeros(u.shape)
    U = np.zeros(u.shape)
    for ti in range(0, Nt):
        for i in range(0, N):
            H[:, i, ti] = H0
            U[:, i, ti] = U0

    # Extra lines that look at contributions to dissipation of energy.
    #Ed_drag = - (U + u) * (H + h) * gamma * u / Ro - v * (H + h) * gamma * v / Ro
    #Ed_diss = (U + u) * (H + h) * (uxx + uyy) / Re + v * (H + h) * (vxx + vyy) / Re

    #e1 = timeAverage(Ed_drag,T,Nt)
    #e2 = timeAverage(Ed_diss,T,Nt)
    #plt.subplot(121)
    #plt.contourf(e1); plt.colorbar()
    #plt.subplot(122)
    #plt.contourf(e2); plt.colorbar()
    #plt.show()

    Ed = (U + u) * (H + h) * (
        (uxx + uyy) / Re - gamma * u / Ro) + v * (H + h) * (
            (vxx + vyy) / Re - gamma * v / Ro)
    # This omits a couple of terms that average to zero.

    Ed_av = timeAverage(Ed, T, Nt)

    return Ed, Ed_av
Exemplo n.º 11
0
def budgetFlux(u, v, h, Ro, dx, dy, T, Nt):
    ''' Calculate time-dependent and time-mean energy budget due to fluxes.
	Make sure to use full u, v and h fields. Contribution from 
	background terms will be removed after time averaging.'''

    E = 0.5 * h * (u**2 + v**2) + h**2 / Ro

    uEflux = np.zeros(u.shape)
    vEflux = np.zeros(u.shape)
    Eflux = np.zeros(u.shape)

    for ti in range(0, Nt):

        uEflux[:, :, ti] = u[:, :, ti] * E[:, :, ti]
        vEflux[:, :, ti] = v[:, :, ti] * E[:, :, ti]

        Eflux[:, :, ti] = -diff(uEflux[:, :, ti], 1, 1, dx) - diff(
            vEflux[:, :, ti], 0, 0, dy)

    Eflux_av = timeAverage(Eflux, T, Nt)
    uEflux_av = timeAverage(uEflux, T, Nt)
    vEflux_av = timeAverage(vEflux, T, Nt)

    return Eflux, Eflux_av, uEflux_av, vEflux_av
Exemplo n.º 12
0
def budgetForcing(u, v, h, F1, F2, F3, Ro, N, T, omega, Nt):
    ''' Calculate time-dependent and time-mean energy budget due to forcing.
	Make sure to use full u, v and h fields. Contribution from 
	background terms will be removed after time averaging.
	This will produce the same time-mean as the below function.'''

    F1t = timeDep(F1, T, omega, Nt)
    F2t = timeDep(F2, T, omega, Nt)
    F3t = timeDep(F3, T, omega, Nt)

    Ef = h * u * F1t + h * v * F2t + (0.5 * (u**2 + v**2) + h / Ro) * F3t

    Ef_av = timeAverage(Ef, T, Nt)

    return Ef, Ef_av
Exemplo n.º 13
0
def budgetForcing2(U0, H0, u, v, h, F1, F2, F3, Ro, N, T, omega, Nt):
    ''' Calculate time-dependent and time-mean energy budget due to forcing.
	Make sure to use full u, v and h fields. Contribution from 
	background terms will be removed after time averaging.'''

    F1t = timeDep(F1, T, omega, Nt)
    F2t = timeDep(F2, T, omega, Nt)
    F3t = timeDep(F3, T, omega, Nt)

    H = np.zeros(u.shape)
    U = np.zeros(u.shape)
    for ti in range(0, Nt):
        for i in range(0, N):
            H[:, i, ti] = H0
            U[:, i, ti] = U0

    Ef = (H * u + h * U + h * u) * F1t + (H * v + h * v) * F2t + (
        0.5 * (2 * U * u + u**2 + v**2) + h / Ro) * F3t

    Ef_av = timeAverage(Ef, T, Nt)

    return Ef, Ef_av
Exemplo n.º 14
0
def budgetDissipation(u, v, h, Ro, Re, gamma, dx, dy, T, Nt):
    ''' Calculate time-dependent and time-mean energy budget due to dissipation.
	Make sure to use full u, v and h fields. Contribution from 
	background terms will be removed after time averaging.'''

    uxx = np.zeros(u.shape)
    uyy = np.zeros(u.shape)
    vxx = np.zeros(u.shape)
    vyy = np.zeros(u.shape)

    for ti in range(0, Nt):

        uyy[:, :, ti] = diff(diff(u[:, :, ti], 0, 0, dy), 0, 0, dy)
        uxx[:, :, ti] = diff(diff(u[:, :, ti], 1, 1, dx), 1, 1, dx)

        vyy[:, :, ti] = diff(diff(v[:, :, ti], 0, 0, dy), 0, 0, dy)
        vxx[:, :, ti] = diff(diff(v[:, :, ti], 1, 1, dx), 1, 1, dx)

    Ed = h * (u * (uxx + uyy) + v *
              (vxx + vyy)) / Re - gamma * h * (u**2 + v**2) / Ro

    Ed_av = timeAverage(Ed, T, Nt)

    return Ed, Ed_av
Exemplo n.º 15
0
                                                 eta_full, H0_nd, U0_nd, N, Nt,
                                                 dx_nd, dy_nd, f_nd)
uq, Uq, uQ, UQ, vq, vQ = PV.fluxes(u_nd, v_nd, U0_nd, PV_prime, PV_BG, N, Nt)

P, P_uq, P_uQ, P_Uq, P_vq, P_vQ, P_xav, P_uq_xav, P_uQ_xav, P_Uq_xav, P_vq_xav, P_vQ_xav = PV.footprintComponents(
    uq, Uq, uQ, vq, vQ, x_nd, T_nd, dx_nd, dy_nd, N, Nt)
#plotting.footprintComponentsPlot(uq,Uq,uQ,vq,vQ,P,P_uq,P_Uq,P_uQ,P_vq,P_vQ,P_xav,P_uq_xav,P_uQ_xav,P_Uq_xav,P_vq_xav,P_vQ_xav,x_nd,y_nd,N,Nt);
#plotting.plotPrimaryComponents(P_uq,P_vq,P_uq_xav,P_vq_xav,x_nd,y_nd,FORCE,BG,Fpos,N);

# Why does the contribution from u^prime * q^prime disappear?
# Is it because <d/dx(u^prime * q^prime)> = c * (u_prime * q^prime)?
# This is periodic in x, and only need be evaluated at the endpoints in x.

TEST1 = False
if TEST1:
    uq_tav = diagnostics.timeAverage(uq, T_nd, Nt)
    # Take the time-average
    uq_tav_xav = np.zeros(N)
    for j in range(0, N):
        uq_tav_xav[j] = -(uq_tav[j, N - 1] - uq_tav[j, 0])

    plt.plot(uq_tav_xav)
    plt.plot(P_uq_xav)
    plt.show()

# We conclude:
# The zonal derivative and the zonal average operators cancel each other out.
# So the contribution from the zonal PV flux is just the difference between uq at either end of the domain,
# but the domain is periodic so this is small!
# The average of the derivative of a period function is zero.
"""!!! This test will now fail, improvements have been made based upon it !!!"""
Exemplo n.º 16
0
def Nnorm(u,v,T):
	"Normalised N"

	return timeAverage(u*v/(u**2+v**2), T, len(T)-1)
Exemplo n.º 17
0
def Mnorm(u,v,T):
	"Normalised M"

	return 0.5 * timeAverage((u**2 - v**2)/(u**2 + v**2), T, len(T)-1)
Exemplo n.º 18
0
def K(u,v,T):
	"A function that calculates the time-mean kinetic energy per unit mass"

	return 0.5 * timeAverage(u**2 + v**2, T, len(T)-1)
Exemplo n.º 19
0
def N(u,v,T):
	"A function that calculates one of the two eddy shape/orientation measures"

	return timeAverage(u*v, T, len(T)-1)
Exemplo n.º 20
0
    plt.colorbar()
    plt.subplot(222)
    plt.contourf(PV_prime2[:, :, ts])
    plt.colorbar()
    plt.subplot(223)
    plt.contourf(PV_prime1[:, :, ts] + PV_prime2[:, :, ts])
    plt.colorbar()
    plt.subplot(224)
    plt.contourf(PV_prime[:, :, ts])
    plt.colorbar()
    plt.show()

    vq1 = v_nd * PV_prime1
    vq2 = v_nd * PV_prime2

    vq1 = diagnostics.timeAverage(vq1, T_nd, Nt)
    vq2 = diagnostics.timeAverage(vq2, T_nd, Nt)

    vq1_y = -diagnostics.diff(vq1, 0, 0, dy_nd)
    vq2_y = -diagnostics.diff(vq2, 0, 0, dy_nd)

    uq_x = diagnostics.timeAverage(uq, T_nd, Nt)
    uq_x = -diagnostics.diff(uq_x, 1, 1, dx_nd)

    if True:
        plt.subplot(221)
        plt.contourf(vq1_y)
        plt.colorbar()
        plt.title('vq1_y')
        plt.subplot(222)
        plt.contourf(vq2_y)