42 Function to compute specific humidity
43 Required input variables are dewpoint (K) and surface pressure (Pa)
44 From dewpoint a simple water vapor mixing ratio is calculated, then
45 specific humidity is r/(1.+r)
48 r = self.
r_sub_sr_sub_s(pres_Pa, dewp_K)
58 compute saturation mixing ratio (kg/kg) by calling function
59 to calculate saturation vapor pressure over water.
60 pres_Pa - pressure (pa)
61 temp_K - temperature (k)
64 es = self.
e_sub_se_sub_s(temp_K)
69 es = min(es, pres_Pa*0.15)
71 rs = 0.622*es/(pres_Pa-es)
80 compute saturation vapor pressure (Pa) over liquid with
81 polynomial fit of Goff-Gratch (1946) formulation. (Walko, 1991)
84 c = [610.5851, 44.40316, 1.430341, 0.2641412e-1, 0.2995057e-3, 0.2031998e-5, 0.6936113e-8, 0.2564861e-11, -0.3704404e-13]
85 x = max(-80., temp_K-self.
C_2_KC_2_K)
86 es = c[0]+x*(c[1]+x*(c[2]+x*(c[3]+x*(c[4]+x*(c[5]+x*(c[6]+x*(c[7]+x*c[8])))))))
89 ALTERNATIVE (costs more CPU, more accurate than Walko, 1991)
90 Source: Murphy and Koop, Review of the vapour pressure of ice and
91 supercooled water for atmospheric applications, Q. J. R.
92 Meteorol. Soc (2005), 131, pp. 1539-1565.
94 es = math.exp(54.842763 - 6763.22 / temp_K - 4.210 * math.alog(temp_K) + 0.000367 * temp_K
95 + math.tanh(0.0415 * (temp_K - 218.8)) * (53.878 - 1331.22
96 / temp_K - 9.44523 * math.alog(temp_K) + 0.014025 * temp_K))
98 ALTERNATIVE: Classical formula from Rogers and Yau (1989; Eq2.17)
100 es = 1000.*0.6112*math.exp(17.67*(temp_K-self.C_2_K)/(temp_K-29.65))
110 compute saturation mixing ratio (kg/kg) by calling function
111 to calculate saturation vapor pressure over ice.
112 pres_Pa - pressure (pa)
113 temp_K - temperature (k)
116 esi = self.
e_sub_ie_sub_i(temp_K)
121 esi = min(esi, pres_Pa*0.15)
123 ri = 0.622*esi/(pres_Pa-esi)
132 compute saturation vapor pressure (Pa) over ice with
133 polynomial fit of Goff-Gratch (1946) formulation. (Walko, 1991)
136 c = [.609868993E03, .499320233E02, .184672631E01, .402737184E-1, .565392987E-3, .521693933E-5, .307839583E-7, .105785160E-9, .161444444E-12]
137 x = max(-80., temp_K-self.
C_2_KC_2_K)
138 esi = c[0]+x*(c[1]+x*(c[2]+x*(c[3]+x*(c[4]+x*(c[5]+x*(c[6]+x*(c[7]+x*c[8])))))))
141 ALTERNATIVE (costs more CPU, more accurate than Walko, 1991)
142 Source: Murphy and Koop, Review of the vapour pressure of ice and
143 supercooled water for atmospheric applications, Q. J. R.
144 Meteorol. Soc (2005), 131, pp. 1539-1565.
146 esi = math.exp(9.550426 - 5723.265/temp_K + 3.53068*math.alog(temp_K) - 0.00728332*temp_K)
148 ALTERNATIVE from Rogers and Yau (1989; Eq2.17)
150 esi = 1000.*0.6112*math.exp(21.8745584*(temp_K-self.C_2_K)/(temp_K-7.66))
160 standard atmos height in meters is returned for given p in Pascals
163 height = 44307.692 * (1.0 - (pr/1013.25)**0.190)
172 standard atmos pressure in Pascals is returned for given height in meters
175 pr = math.exp(math.log(1.0-height/44307.692)/0.19)*101325.0
184 Input is a column ordered with lowest index is physically lower in the atmosphere (pressure decreasing as the index increases).
185 pres_Pa = Pressure in Pascals
186 w_non = mixing ratio (non-dimensional = kg/kg)
187 returned precipitable water value in meters only below 150mb
192 while k < len(pres_Pa):
193 if (pres_Pa[k] > 15000.0):
194 sum = sum + ((w_non[k]+w_non[k-1])*0.5) * abs(pres_Pa[k]-pres_Pa[k-1])
197 answer = sum/(self.
gg*self.
RHO_WATERRHO_WATER)
206 From wind direction and speed, compute u,v wind components
209 u = -wspd * math.sin(wdir*self.
DEG_2_RADDEG_2_RAD)
210 v = -wspd * math.cos(wdir*self.
DEG_2_RADDEG_2_RAD)
219 From altimeter (inches of mercury, Hg), and station elevation (m),
220 compute surface pressure returned in Pascals.
223 psfc = altim * ((self.
STP_TSTP_T - self.
LAPSELAPSE*elev) / self.
STP_TSTP_T)**5.2561
230 def theta_e(self, pres_Pa, temp_K, w_non, tlcl_K):
233 The following code was based on Bolton (1980) eqn #43
234 and claims to have 0.3 K maximum error within -35 < T < 35 C
235 pres_Pa = Pressure in Pascals
236 temp_K = Temperature in Kelvin
237 w_non = mixing ratio (non-dimensional = kg/kg)
238 tlcl_K = Temperature at Lifting Condensation Level (K)
246 power = (0.2854*(1.0 - (0.28*rr)))
247 xx = tt * (100000.0/pp)**power
249 p1 = (3.376/tlc) - 0.00254
250 p2 = (rr*1000.0) * (1.0 + 0.81*rr)
252 thetae = xx * math.exp(p1*p2)
261 The following code was based on Bolton (1980) eqn #15
262 and claims to have 0.1 K maximum error within -35 < T < 35 C
263 temp_K = Temperature in Kelvin
264 tdew_K = Dewpoint T at Lifting Condensation Level (K)
269 denom = (1.0/(tttd-56.0)) + (math.log(tt/tttd)/800.)
270 tlcl = (1.0/denom) + 56.0
279 I cannot recall the original source of this function
280 pres_Pa = Pressure in Pascals
281 w_non = mixing ratio (non-dimensional = kg/kg)
288 tdew = (35.86*esln-4947.2325)/(esln-23.6837)
297 Eqn below was gotten from polynomial fit to data in
298 Smithsonian Meteorological Tables showing Theta-e
302 c = [-1.00922292e-10, -1.47945344e-8, -1.7303757e-6, -0.00012709, 1.15849867e-6, -3.518296861e-9, 3.5741522e-12]
303 d = [0.0, -3.5223513e-10, -5.7250807e-8, -5.83975422e-6, 4.72445163e-8, -1.13402845e-10, 8.729580402e-14]
305 x = min(475.0, thetae_K)
308 answer =
c(0)+x*(
c(1)+x*(
c(2)+x*(
c(3)+x*(
c(4)+x*(
c(5)+x*
c(6))))))
310 answer =
d(0)+x*(
d(1)+x*(
d(2)+x*(
d(3)+x*(
d(4)+x*(
d(5)+x*
d(6))))))
312 th_wetb = answer + self.
C_2_KC_2_K
321 pres_Pa = Pressure in Pascals
322 thelcl = Theta-e at LCL (units in Kelvin)
323 Temperature (K) is returned given Theta-e at LCL
324 and a pressure. This describes a moist-adiabat.
325 This temperature is the parcel temp at level Pres
326 along moist adiabat described by theta-e.
329 guess = (thelcl_K - 0.5 * (max(thelcl_K-270., 0.))**1.05) * (pres_Pa/100000.0)**.2
334 w1 = self.
r_sub_sr_sub_s(pres_Pa, guess)
335 w2 = self.
r_sub_sr_sub_s(pres_Pa, guess+1.)
336 tenu = self.
theta_etheta_e(pres_Pa, guess, w1, guess)
337 tenup = self.
theta_etheta_e(pres_Pa, guess+1, w2, guess+1.)
338 cor = (thelcl_K - tenu) / (tenup - tenu)
340 if((cor < epsilon)
and (-cor < epsilon)):
349 If we come out of the iteration without a solution, then it did not converge. This is not good.
352 print(
"WARNING: solution did not converge in compT_fr_The, " +
str(thelcl_K) +
", " +
str(pres_Pa))
354 thwlcl_K = self.
theta_wetbtheta_wetb(thelcl_K)
355 answer = thwlcl_K*((pres_Pa/100000.0)**0.286)
def t_lcl(self, temp_K, tdew_K)
def r_sub_s(self, pres_Pa, temp_K)
def dir_speed_2_uv(self, wdir, wspd)
def e_sub_i(self, temp_K)
def std_atmos_p(self, height)
def compT_fr_The(self, thelcl_K, pres_Pa)
def specific_humidity(self, dewp_K, pres_Pa)
def theta_e(self, pres_Pa, temp_K, w_non, tlcl_K)
def theta_wetb(self, thetae_K)
def precipitable_water(self, pres_Pa, w_non)
def altim_2_sfcPressure(self, altim, elev)
def r_sub_i(self, pres_Pa, temp_K)
def e_sub_s(self, temp_K)
def t_dew(self, pres_Pa, w_non)
def std_atmos(self, pres_Pa)