コード例 #1
0
def forcingInv(Ftilde1_nd, Ftilde2_nd, Ftilde3_nd, x_nd, y_nd, dx_nd, N):

    F1i = np.real(np.fft.ihfft(Ftilde1_nd, axis=1)) / dx_nd
    F2 = np.fft.fftshift(np.fft.ifft(Ftilde2_nd, axis=1), axes=1) / dx_nd
    F3i = np.real(np.fft.ihfft(Ftilde3_nd, axis=1)) / dx_nd

    F1 = np.zeros((N, N))
    F3 = np.zeros((N, N))
    for i in range(0, N / 2):
        F1[:, i] = F1i[:, i]
        F1[:, N - 1 - i] = F1i[:, i]
        F3[:, i] = F3i[:, i]
        F3[:, N - 1 - i] = F3i[:, i]

    F1 = np.fft.fftshift(F1, axes=1)
    F3 = np.fft.fftshift(F3, axes=1)

    F1 = extend(F1)
    F2 = extend(F2)
    F3 = extend(F3)

    plt.figure(2)

    plt.subplot(331)
    plt.contourf(x_nd, y_nd, F1)
    plt.colorbar()
    plt.subplot(332)
    plt.contourf(x_nd, y_nd, F2)
    plt.colorbar()
    plt.subplot(333)
    plt.contourf(x_nd, y_nd, F3)
    plt.colorbar()

    plt.subplot(334)
    plt.contourf(np.real(Ftilde1_nd))
    plt.colorbar()
    plt.subplot(335)
    plt.contourf(np.real(Ftilde2_nd))
    plt.colorbar()
    plt.subplot(336)
    plt.contourf(np.real(Ftilde3_nd))
    plt.colorbar()

    plt.subplot(337)
    plt.contourf(np.imag(Ftilde1_nd))
    plt.colorbar()
    plt.subplot(338)
    plt.contourf(np.imag(Ftilde2_nd))
    plt.colorbar()
    plt.subplot(339)
    plt.contourf(np.imag(Ftilde3_nd))
    plt.colorbar()

    plt.show()
コード例 #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
コード例 #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
コード例 #4
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;
コード例 #5
0
ファイル: momentum.py プロジェクト: mhaigh/Shallow-water
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
コード例 #6
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
コード例 #7
0
def eigPlot(u, v, eta, PV, x_nd, y_nd):

    u = extend(u)
    v = extend(v)
    eta = extend(eta)
    PV = extend(PV)

    plt.subplot(221)
    plt.contourf(x_nd, y_nd, u)
    plt.xticks((-1. / 2, 0, 1. / 2))
    plt.yticks((-1. / 2, 0, 1. / 2))
    plt.xlabel('x')
    plt.ylabel('y')
    plt.colorbar()
    plt.subplot(222)
    plt.contourf(x_nd, y_nd, v)
    plt.xticks((-1. / 2, 0, 1. / 2))
    plt.yticks((-1. / 2, 0, 1. / 2))
    plt.xlabel('x')
    plt.ylabel('y')
    plt.colorbar()
    plt.subplot(223)
    plt.contourf(x_nd, y_nd, eta)
    plt.xticks((-1. / 2, 0, 1. / 2))
    plt.yticks((-1. / 2, 0, 1. / 2))
    plt.xlabel('x')
    plt.ylabel('y')
    plt.colorbar()
    plt.subplot(224)
    plt.contourf(x_nd, y_nd, PV)
    plt.xticks((-1. / 2, 0, 1. / 2))
    plt.yticks((-1. / 2, 0, 1. / 2))
    plt.xlabel('x')
    plt.ylabel('y')
    plt.colorbar()
    plt.show()
コード例 #8
0
ファイル: thickness.py プロジェクト: mhaigh/Shallow-water
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
コード例 #9
0
ファイル: other.py プロジェクト: mhaigh/Shallow-water
        plt.title('vq1_y')
        plt.subplot(222)
        plt.contourf(vq2_y)
        plt.colorbar()
        plt.title('vq2_y')
        plt.subplot(223)
        plt.contourf(vq1_y + vq2_y + uq_x)
        plt.colorbar()
        plt.title('vq1+vq2')
        plt.subplot(224)
        plt.contourf(P)
        plt.colorbar()
        plt.title('P')
        plt.show()

    vq1_y = diagnostics.extend(vq1_y)
    vq2_y = diagnostics.extend(vq2_y)
    uq_x = diagnostics.extend(uq_x)

    vq1 = np.trapz(vq1_y, x_nd, dx_nd, axis=1)
    vq2 = np.trapz(vq2_y, x_nd, dx_nd, axis=1)
    uq = np.trapz(uq_x, x_nd, dx_nd, axis=1)

    plt.plot(vq1, label='vq1')
    plt.plot(vq2, label='vq2')
    plt.plot(uq, label='uq')
    plt.legend()
    plt.show()

    vq = diagnostics.timeAverage(vq, T_nd, Nt)
    plotting.vqPlot(x_grid, y_grid, y_nd, v_nd, PV_prime, vq, P, P_xav, EEF,
コード例 #10
0
def footprint(u_full, v_nd, PV_full, U_nd, U, x_nd, y_nd, dx_nd, dy_nd,
              AmpF_nd, FORCE1, r0, nu, BG1, Fpos, ts, period_days, N, Nt,
              GAUSS):
    # 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.

    qu = PV_full * u_full
    # Zonal PV flux
    qv = PV_full * v_nd
    # 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
    P = -diff(qu[:, :, 0], 1, 1, dx_nd) - diff(qv[:, :, 0], 0, 0, dy_nd)
    # Initialise the footprint with the first time-step
    for ti in range(1, Nt):
        P[:, :] = P[:, :] - diff(qu[:, :, ti], 1, 1, dx_nd) - diff(
            qv[:, :, ti], 0, 0, dy_nd)
    P = P / Nt
    #P_av = np.trapz(P,T_nd[:Nt],dt_nd,axis=2) / T_nd[Nt-1];

    # Normalisation
    P = P / AmpF_nd**2

    # We are interested in the zonal average of the footprint
    P_xav = np.trapz(P, x_nd[:N], dx_nd, axis=1)

    P = extend(P)

    #import scipy.io as sio
    #sio.savemat('/home/mike/Documents/GulfStream/Code/DATA/1L/' + str(FORCE) + '/' + str(BG) +  '/P_' + str(Fpos) + str(N),{'P':P});

    PLOT = 1
    if PLOT == 1:
        Plim = np.max(abs(P))
        plt.figure(1, figsize=(15, 7))
        plt.subplot(121)
        #plt.contourf(x_nd,y_nd,P,cmap='coolwarm')
        plt.contourf(x_nd, y_nd, P)
        plt.text(0.1, 0.4, 'PV FOOTPRINT', fontsize=18)
        #plt.text(0.25,0.4,str(Fpos),fontsize=18);		# Comment out this line if text on the plot isn't wanted.
        #plt.text(0.15,0.4,'r0 = '+str(r0/1000) + ' km' ,fontsize=18);
        #plt.text(0.25,0.4,str(int(period_days))+' days',fontsize=18)
        #plt.text(0.25,0.4,'U0 = ' + str(U*U0_nd[0]),fontsize=18);
        #plt.text(0.25,0.4,r'$\nu$ = ' + str(int(nu)),fontsize=18);
        plt.xticks((-1. / 2, 0, 1. / 2))
        plt.yticks((-1. / 2, 0, 1. / 2))
        plt.xlabel('x')
        plt.ylabel('y')
        plt.clim(-Plim, Plim)
        plt.colorbar()
        plt.subplot(122)
        plt.plot(P_xav, y_nd, linewidth=2)
        plt.text(40, 0.4, 'ZONAL AVERAGE', fontsize=18)
        plt.yticks((-1. / 2, 0, 1. / 2))
        plt.ylim(-0.5, 0.5)
        plt.xlim(-1.1 * np.max(abs(P_xav)), 1.1 * np.max(abs(P_xav)))
        plt.tight_layout()
        #plt.savefig('/home/mike/Documents/GulfStream/Code/IMAGES/1L/' + str(FORCE1) + '/' + str(BG) +  '/FOOTPRINT_nu=' + str(nu) + '.png');
        plt.show()

        # These if loops are for constantly altering depending on the test being done.
        if BG1 == 'GAUSSIAN':
            plt.figure(2)
            plt.contourf(x_nd, y_nd, P)
            #plt.plot(U*U1_nd/(1.5*Umag)-0.5,y_nd,'k--',linewidth=2);
            plt.text(0.25, 0.4, str(GAUSS), fontsize=18)
            #plt.text(0.25,0.4,str(period_days)+' days',fontsize=18)
            #plt.text(0.25,0.4,str(Fpos),fontsize=18);
            #plt.plot(P_xav[:,ts],y_nd,linewidth=2)
            #plt.text(0.25,0.4,'r0 = '+str(r0/1000),fontsize=18);
            plt.colorbar()
            plt.ylim([-0.5, 0.5])
            plt.xticks((-1. / 2, 0, 1. / 2))
            plt.yticks((-1. / 2, 0, 1. / 2))
            plt.xlabel('x')
            plt.ylabel('y')
            plt.tight_layout()
            #plt.savefig('/home/mike/Documents/GulfStream/Code/IMAGES/1L/' + str(FORCE) + '/' + str(BG) +  '/TEST/FOOTPRINT_' + str(GAUSS) + '.png');

        if BG1 == 'UNIFORM':
            plt.figure(2)
            plt.contourf(x_nd, y_nd, P)
            #plt.text(0.25,0.4,'U1 = ' + str(U*U0_nd[0]),fontsize=18);
            plt.colorbar()
            plt.xticks((-1. / 2, 0, 1. / 2))
            plt.yticks((-1. / 2, 0, 1. / 2))
            plt.tight_layout()
            #plt.savefig('/home/mike/Documents/GulfStream/Code/IMAGES/1L/' + str(FORCE) + '/' + str(BG) +  '/FOOTPRINT_U0=' + str(U*U0_nd[0]) + '.png');

    return P, P_xav