Skip to content

Commit 23cb0e0

Browse files
committed
debug ComputeEPfluxDiv() for the case wave<0, i.e. when all waves are requested and do_ubar=True
1 parent ca006be commit 23cb0e0

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

climate.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def ComputeEPfluxDiv(lat,pres,u,v,t,w=None,do_ubar=False,wave=0):
965965
pp0 = (p0/pres[np.newaxis,:,np.newaxis])**kappa
966966
dp = np.gradient(pres)[np.newaxis,:,np.newaxis]
967967
if wave < 0:
968-
dp = np.expand_dims(dp,-1)
968+
dp = np.expand_dims(dp ,-1)
969969
#
970970
# absolute vorticity
971971
if do_ubar:
@@ -975,25 +975,35 @@ def ComputeEPfluxDiv(lat,pres,u,v,t,w=None,do_ubar=False,wave=0):
975975
fhat = 0.
976976
fhat = f - fhat # [1/s]
977977
#
978+
# add wavenumber dimension if needed
979+
if wave < 0:
980+
fhat = np.expand_dims(fhat,-1)
981+
coslat = np.expand_dims(coslat,-1)
982+
sinlat = np.expand_dims(sinlat,-1)
983+
dphi = np.expand_dims(dphi,-1)
984+
R = np.expand_dims(R,-1)
985+
#
978986
## compute thickness weighted heat flux [m.hPa/s]
979987
vbar,vertEddy = ComputeVertEddy(v,t,pres,p0,wave) # vertEddy = bar(v'Th'/(dTh_bar/dp))
980988
#
981989
## get zonal anomalies
982990
u = GetAnomaly(u)
983991
v = GetAnomaly(v)
984-
if isinstance(wave,list):
985-
upvp = np.sum(GetWaves(u,v,wave=-1)[:,:,:,wave],-1)
986-
elif wave == 0:
992+
#if isinstance(wave,list):
993+
# upvp = np.sum(GetWaves(u,v,wave=-1)[:,:,:,wave],-1)
994+
if wave == 0:
987995
upvp = np.nanmean(u*v,axis=-1)
988996
else:
989997
upvp = GetWaves(u,v,wave=wave)
990998
#
991999
## compute the horizontal component
9921000
if do_ubar:
993-
shear = np.gradient(ubar,edge_order=2)[1]/dp # [m/s.hPa]
1001+
grad_u= np.gradient(ubar,edge_order=2)[1]
1002+
if wave < 0:
1003+
grad_u = np.expand_dims(grad_u,-1)
1004+
shear = grad_u/dp # [m/s.hPa]
9941005
else:
9951006
shear = 0.
996-
print(upvp.shape,vertEddy.shape)
9971007
ep1_cart = -upvp + shear*vertEddy # [m2/s2 + m/s.hPa*m.hPa/s] = [m2/s2]
9981008
#
9991009
## compute vertical component of EP flux.
@@ -1017,7 +1027,7 @@ def ComputeEPfluxDiv(lat,pres,u,v,t,w=None,do_ubar=False,wave=0):
10171027
# where a*cosphi comes from using cartesian, and cosphi from the derivative
10181028
# With some algebra, we get
10191029
# div1 = cosphi d/d phi[ep1_cart] - 2 sinphi*ep1_cart
1020-
if wave < 1:
1030+
if wave < 0:
10211031
div1 = coslat*np.gradient(ep1_cart,edge_order=2)[-2]/dphi - 2*sinlat*ep1_cart
10221032
else:
10231033
div1 = coslat*np.gradient(ep1_cart,edge_order=2)[-1]/dphi - 2*sinlat*ep1_cart

0 commit comments

Comments
 (0)