|
|
@ -11,6 +11,7 @@ from wrf.var._wrfext import (f_interpz3d, f_interp2dxy,f_interp1d, |
|
|
|
f_computesrh, f_computeuh, f_computepw, f_computedbz, |
|
|
|
f_computesrh, f_computeuh, f_computepw, f_computedbz, |
|
|
|
f_lltoij, f_ijtoll, f_converteta, f_computectt) |
|
|
|
f_lltoij, f_ijtoll, f_converteta, f_computectt) |
|
|
|
from wrf.var._wrfcape import f_computecape |
|
|
|
from wrf.var._wrfcape import f_computecape |
|
|
|
|
|
|
|
from wrf.var.decorators import handle_left_iter |
|
|
|
|
|
|
|
|
|
|
|
__all__ = ["FortranException", "computeslp", "computetk", "computetd", |
|
|
|
__all__ = ["FortranException", "computeslp", "computetk", "computetd", |
|
|
|
"computerh", "computeavo", "computepvo", "computeeth", |
|
|
|
"computerh", "computeavo", "computepvo", "computeeth", |
|
|
@ -43,10 +44,11 @@ def interp1d(v_in,z_in,z_out,missingval): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32") |
|
|
|
return res.astype("float32") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(2,3,0) |
|
|
|
def computeslp(z,t,p,q): |
|
|
|
def computeslp(z,t,p,q): |
|
|
|
t_surf = n.zeros((z.shape[1], z.shape[2]), "float64") |
|
|
|
t_surf = n.zeros((z.shape[-2], z.shape[-1]), "float64") |
|
|
|
t_sea_level = n.zeros((z.shape[1], z.shape[2]), "float64") |
|
|
|
t_sea_level = n.zeros((z.shape[-2], z.shape[-1]), "float64") |
|
|
|
level = n.zeros((z.shape[1], z.shape[2]), "int32") |
|
|
|
level = n.zeros((z.shape[-2], z.shape[-1]), "int32") |
|
|
|
|
|
|
|
|
|
|
|
res = f_computeslp(z.astype("float64").T, |
|
|
|
res = f_computeslp(z.astype("float64").T, |
|
|
|
t.astype("float64").T, |
|
|
|
t.astype("float64").T, |
|
|
@ -59,6 +61,7 @@ def computeslp(z,t,p,q): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0) |
|
|
|
def computetk(pres, theta): |
|
|
|
def computetk(pres, theta): |
|
|
|
# No need to transpose here since operations on 1D array |
|
|
|
# No need to transpose here since operations on 1D array |
|
|
|
shape = pres.shape |
|
|
|
shape = pres.shape |
|
|
@ -67,12 +70,14 @@ def computetk(pres, theta): |
|
|
|
res = n.reshape(res, shape, "A") |
|
|
|
res = n.reshape(res, shape, "A") |
|
|
|
return res.astype("float32") |
|
|
|
return res.astype("float32") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Note: No decorator needed with 1D arrays |
|
|
|
def computetd(pressure,qv_in): |
|
|
|
def computetd(pressure,qv_in): |
|
|
|
shape = pressure.shape |
|
|
|
shape = pressure.shape |
|
|
|
res = f_computetd(pressure.astype("float64").flatten("A"), qv_in.astype("float64").flatten("A")) |
|
|
|
res = f_computetd(pressure.astype("float64").flatten("A"), qv_in.astype("float64").flatten("A")) |
|
|
|
res = n.reshape(res, shape, "A") |
|
|
|
res = n.reshape(res, shape, "A") |
|
|
|
return res.astype("float32") |
|
|
|
return res.astype("float32") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Note: No decorator needed with 1D arrays |
|
|
|
def computerh(qv,q,t): |
|
|
|
def computerh(qv,q,t): |
|
|
|
shape = qv.shape |
|
|
|
shape = qv.shape |
|
|
|
res = f_computerh(qv.astype("float64").flatten("A"), |
|
|
|
res = f_computerh(qv.astype("float64").flatten("A"), |
|
|
@ -81,6 +86,7 @@ def computerh(qv,q,t): |
|
|
|
res = n.reshape(res, shape, "A") |
|
|
|
res = n.reshape(res, shape, "A") |
|
|
|
return res.astype("float32") |
|
|
|
return res.astype("float32") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0, ignore_args=(6,7)) |
|
|
|
def computeavo(u,v,msfu,msfv,msfm,cor,dx,dy): |
|
|
|
def computeavo(u,v,msfu,msfv,msfm,cor,dx,dy): |
|
|
|
res = f_computeabsvort(u.astype("float64").T, |
|
|
|
res = f_computeabsvort(u.astype("float64").T, |
|
|
|
v.astype("float64").T, |
|
|
|
v.astype("float64").T, |
|
|
@ -93,6 +99,7 @@ def computeavo(u,v,msfu,msfv,msfm,cor,dx,dy): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0, ignore_args=(8,9)) |
|
|
|
def computepvo(u,v,theta,prs,msfu,msfv,msfm,cor,dx,dy): |
|
|
|
def computepvo(u,v,theta,prs,msfu,msfv,msfm,cor,dx,dy): |
|
|
|
|
|
|
|
|
|
|
|
res = f_computepvo(u.astype("float64").T, |
|
|
|
res = f_computepvo(u.astype("float64").T, |
|
|
@ -107,7 +114,8 @@ def computepvo(u,v,theta,prs,msfu,msfv,msfm,cor,dx,dy): |
|
|
|
dy) |
|
|
|
dy) |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0) |
|
|
|
def computeeth(qv, tk, p): |
|
|
|
def computeeth(qv, tk, p): |
|
|
|
|
|
|
|
|
|
|
|
res = f_computeeth(qv.astype("float64").T, |
|
|
|
res = f_computeeth(qv.astype("float64").T, |
|
|
@ -116,16 +124,17 @@ def computeeth(qv, tk, p): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(4,2,2, ignore_args=(4,5), alg_out_fixed_dims=(2,)) |
|
|
|
def computeuvmet(u,v,lat,lon,cen_long,cone): |
|
|
|
def computeuvmet(u,v,lat,lon,cen_long,cone): |
|
|
|
longca = n.zeros((lat.shape[0], lat.shape[1]), "float64") |
|
|
|
longca = n.zeros((lat.shape[-2], lat.shape[-1]), "float64") |
|
|
|
longcb = n.zeros((lon.shape[0], lon.shape[1]), "float64") |
|
|
|
longcb = n.zeros((lon.shape[-2], lon.shape[-1]), "float64") |
|
|
|
rpd = Constants.PI/180. |
|
|
|
rpd = Constants.PI/180. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Make the 2D array a 3D array with 1 dimension |
|
|
|
# Make the 2D array a 3D array with 1 dimension |
|
|
|
if u.ndim != 3: |
|
|
|
if u.ndim != 3: |
|
|
|
u = u.reshape((1,u.shape[0], u.shape[1])) |
|
|
|
u = u.reshape((1,u.shape[-2], u.shape[-1])) |
|
|
|
v = v.reshape((1,v.shape[0], v.shape[1])) |
|
|
|
v = v.reshape((1,v.shape[-2], v.shape[-1])) |
|
|
|
|
|
|
|
|
|
|
|
# istag will always be false since winds are destaggered already |
|
|
|
# istag will always be false since winds are destaggered already |
|
|
|
# Missing values don't appear to be used, so setting to 0 |
|
|
|
# Missing values don't appear to be used, so setting to 0 |
|
|
@ -147,6 +156,7 @@ def computeuvmet(u,v,lat,lon,cen_long,cone): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0) |
|
|
|
def computeomega(qv, tk, w, p): |
|
|
|
def computeomega(qv, tk, w, p): |
|
|
|
|
|
|
|
|
|
|
|
res = f_computeomega(qv.astype("float64").T, |
|
|
|
res = f_computeomega(qv.astype("float64").T, |
|
|
@ -157,12 +167,14 @@ def computeomega(qv, tk, w, p): |
|
|
|
#return res.T |
|
|
|
#return res.T |
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0) |
|
|
|
def computetv(tk,qv): |
|
|
|
def computetv(tk,qv): |
|
|
|
res = f_computetv(tk.astype("float64").T, |
|
|
|
res = f_computetv(tk.astype("float64").T, |
|
|
|
qv.astype("float64").T) |
|
|
|
qv.astype("float64").T) |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0) |
|
|
|
def computewetbulb(p,tk,qv): |
|
|
|
def computewetbulb(p,tk,qv): |
|
|
|
PSADITHTE, PSADIPRS, PSADITMK = get_lookup_tables() |
|
|
|
PSADITHTE, PSADIPRS, PSADITMK = get_lookup_tables() |
|
|
|
|
|
|
|
|
|
|
@ -176,6 +188,7 @@ def computewetbulb(p,tk,qv): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(2,3,0, ignore_args=(4,)) |
|
|
|
def computesrh(u, v, z, ter, top): |
|
|
|
def computesrh(u, v, z, ter, top): |
|
|
|
|
|
|
|
|
|
|
|
res = f_computesrh(u.astype("float64").T, |
|
|
|
res = f_computesrh(u.astype("float64").T, |
|
|
@ -186,10 +199,11 @@ def computesrh(u, v, z, ter, top): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(2,3,2, ignore_args=(5,6,7,8)) |
|
|
|
def computeuh(zp, mapfct, u, v, wstag, dx, dy, bottom, top): |
|
|
|
def computeuh(zp, mapfct, u, v, wstag, dx, dy, bottom, top): |
|
|
|
|
|
|
|
|
|
|
|
tem1 = n.zeros((u.shape[0],u.shape[1],u.shape[2]), "float64") |
|
|
|
tem1 = n.zeros((u.shape[-3],u.shape[-2],u.shape[-1]), "float64") |
|
|
|
tem2 = n.zeros((u.shape[0],u.shape[1],u.shape[2]), "float64") |
|
|
|
tem2 = n.zeros((u.shape[-3],u.shape[-2],u.shape[-1]), "float64") |
|
|
|
|
|
|
|
|
|
|
|
res = f_computeuh(zp.astype("float64").T, |
|
|
|
res = f_computeuh(zp.astype("float64").T, |
|
|
|
mapfct.astype("float64").T, |
|
|
|
mapfct.astype("float64").T, |
|
|
@ -205,9 +219,10 @@ def computeuh(zp, mapfct, u, v, wstag, dx, dy, bottom, top): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(2,3,0) |
|
|
|
def computepw(p,tv,qv,ht): |
|
|
|
def computepw(p,tv,qv,ht): |
|
|
|
# Note, dim 0 is height, we only want y and x |
|
|
|
# Note, dim 0 is height, we only want y and x |
|
|
|
zdiff = n.zeros((p.shape[1], p.shape[2]), "float64") |
|
|
|
zdiff = n.zeros((p.shape[-2], p.shape[-1]), "float64") |
|
|
|
res = f_computepw(p.astype("float64").T, |
|
|
|
res = f_computepw(p.astype("float64").T, |
|
|
|
tv.astype("float64").T, |
|
|
|
tv.astype("float64").T, |
|
|
|
qv.astype("float64").T, |
|
|
|
qv.astype("float64").T, |
|
|
@ -216,6 +231,7 @@ def computepw(p,tv,qv,ht): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0, ignore_args=(6,7,8)) |
|
|
|
def computedbz(p,tk,qv,qr,qs,qg,sn0,ivarint,iliqskin): |
|
|
|
def computedbz(p,tk,qv,qr,qs,qg,sn0,ivarint,iliqskin): |
|
|
|
|
|
|
|
|
|
|
|
res = f_computedbz(p.astype("float64").T, |
|
|
|
res = f_computedbz(p.astype("float64").T, |
|
|
@ -230,9 +246,10 @@ def computedbz(p,tk,qv,qr,qs,qg,sn0,ivarint,iliqskin): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0,ignore_args=(6,7,8)) |
|
|
|
def computecape(p_hpa,tk,qv,ht,ter,sfp,missing,i3dflag,ter_follow): |
|
|
|
def computecape(p_hpa,tk,qv,ht,ter,sfp,missing,i3dflag,ter_follow): |
|
|
|
flip_cape = n.zeros((p_hpa.shape[0],p_hpa.shape[1],p_hpa.shape[2]), "float64") |
|
|
|
flip_cape = n.zeros((p_hpa.shape[-3],p_hpa.shape[-2],p_hpa.shape[-1]), "float64") |
|
|
|
flip_cin = n.zeros((p_hpa.shape[0],p_hpa.shape[1],p_hpa.shape[2]), "float64") |
|
|
|
flip_cin = n.zeros((p_hpa.shape[-3],p_hpa.shape[-2],p_hpa.shape[-1]), "float64") |
|
|
|
PSADITHTE, PSADIPRS, PSADITMK = get_lookup_tables() |
|
|
|
PSADITHTE, PSADIPRS, PSADITMK = get_lookup_tables() |
|
|
|
|
|
|
|
|
|
|
|
# The fortran routine needs pressure to be ascending in z-direction, |
|
|
|
# The fortran routine needs pressure to be ascending in z-direction, |
|
|
@ -264,7 +281,7 @@ def computecape(p_hpa,tk,qv,ht,ter,sfp,missing,i3dflag,ter_follow): |
|
|
|
# Remember to flip cape and cin back to descending p coordinates |
|
|
|
# Remember to flip cape and cin back to descending p coordinates |
|
|
|
return (cape[::-1,:,:],cin[::-1,:,:]) |
|
|
|
return (cape[::-1,:,:],cin[::-1,:,:]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: This should handle lists of coords |
|
|
|
def computeij(map_proj,truelat1,truelat2,stdlon, |
|
|
|
def computeij(map_proj,truelat1,truelat2,stdlon, |
|
|
|
lat1,lon1,pole_lat,pole_lon, |
|
|
|
lat1,lon1,pole_lat,pole_lon, |
|
|
|
knowni,knownj,dx,latinc,loninc,lat,lon): |
|
|
|
knowni,knownj,dx,latinc,loninc,lat,lon): |
|
|
@ -276,6 +293,7 @@ def computeij(map_proj,truelat1,truelat2,stdlon, |
|
|
|
|
|
|
|
|
|
|
|
return res[0],res[1] |
|
|
|
return res[0],res[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: This should handle lists of coords |
|
|
|
def computell(map_proj,truelat1,truelat2,stdlon,lat1,lon1, |
|
|
|
def computell(map_proj,truelat1,truelat2,stdlon,lat1,lon1, |
|
|
|
pole_lat,pole_lon,knowni,knownj,dx,latinc, |
|
|
|
pole_lat,pole_lon,knowni,knownj,dx,latinc, |
|
|
|
loninc,i,j): |
|
|
|
loninc,i,j): |
|
|
@ -287,6 +305,7 @@ def computell(map_proj,truelat1,truelat2,stdlon,lat1,lon1, |
|
|
|
# Want lon,lat |
|
|
|
# Want lon,lat |
|
|
|
return res[1],res[0] |
|
|
|
return res[1],res[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(3,3,0, ignore_args=(3,)) |
|
|
|
def computeeta(full_t, znu, psfc, ptop): |
|
|
|
def computeeta(full_t, znu, psfc, ptop): |
|
|
|
pcalc = n.zeros(full_t.shape, "float64") |
|
|
|
pcalc = n.zeros(full_t.shape, "float64") |
|
|
|
mean_t = n.zeros(full_t.shape, "float64") |
|
|
|
mean_t = n.zeros(full_t.shape, "float64") |
|
|
@ -302,6 +321,7 @@ def computeeta(full_t, znu, psfc, ptop): |
|
|
|
|
|
|
|
|
|
|
|
return res.astype("float32").T |
|
|
|
return res.astype("float32").T |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_left_iter(2,3,0,ignore_args=(7,)) |
|
|
|
def computectt(p_hpa,tk,qice,qcld,qv,ght,ter,haveqci): |
|
|
|
def computectt(p_hpa,tk,qice,qcld,qv,ght,ter,haveqci): |
|
|
|
res = f_computectt(p_hpa.astype("float64").T, |
|
|
|
res = f_computectt(p_hpa.astype("float64").T, |
|
|
|
tk.astype("float64").T, |
|
|
|
tk.astype("float64").T, |
|
|
|