Skip to content

Commit

Permalink
conform code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Osamu Miyawaki committed Nov 7, 2023
1 parent 4e00271 commit 5f1cc4d
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,65 +357,62 @@ def dt_standard(p, t, params):

def dt_pseudoadiabatic(p, t, params):
rs = saturation_mixing_ratio._nounit(p, t)
frac = ( (1 + rs) * (mpconsts.nounit.Rd * t + mpconsts.nounit.Lv * rs)
/ (mpconsts.nounit.Cp_d + rs * mpconsts.nounit.Cv_d +
(mpconsts.nounit.Lv**2 * rs * (mpconsts.nounit.epsilon + rs)
/ (mpconsts.nounit.Rd * t**2))))
frac = ((1 + rs) * (mpconsts.nounit.Rd * t + mpconsts.nounit.Lv * rs)
/ (mpconsts.nounit.Cp_d + rs * mpconsts.nounit.Cv_d
+ (mpconsts.nounit.Lv**2 * rs * (mpconsts.nounit.epsilon + rs)
/ (mpconsts.nounit.Rd * t**2))))
return frac / p

def dt_reversible(p, t, params):
rs = saturation_mixing_ratio._nounit(p, t)
rl = params['rt'] - rs ## assuming no ice content
frac = ( (1 + params['rt']) * (mpconsts.nounit.Rd * t + mpconsts.nounit.Lv * rs)
/ (mpconsts.nounit.Cp_d + rs * mpconsts.nounit.Cv_d +
rl * mpconsts.nounit.Cp_l + (mpconsts.nounit.Lv**2 * rs *
(mpconsts.nounit.epsilon + rs)
/ (mpconsts.nounit.Rd * t**2))))
rl = params['rt'] - rs # assuming no ice content
frac = ((1 + params['rt']) * (mpconsts.nounit.Rd * t + mpconsts.nounit.Lv * rs)
/ (mpconsts.nounit.Cp_d + rs * mpconsts.nounit.Cv_d
+ rl * mpconsts.nounit.Cp_l + (mpconsts.nounit.Lv**2 * rs
* (mpconsts.nounit.epsilon + rs)
/ (mpconsts.nounit.Rd * t**2))))
return frac / p

def dt_so13(p, t, params):
zp = -params['h0'] * np.log(p / params['p0']) # pseudoheight
if np.abs(zp)==0: # entrainment rate undefined at z=0, assume dry adiabat
zp = -params['h0'] * np.log(p / params['p0']) # pseudoheight
if np.abs(zp)==0: # entrainment rate undefined at z=0, assume dry adiabat
frac = mpconsts.nounit.Rd * t / mpconsts.nounit.Cp_d
else:
ep = params['ep0'] / zp # entrainment rate
ep = params['ep0'] / zp # entrainment rate
rs = saturation_mixing_ratio._nounit(p, t)
qs = specific_humidity_from_mixing_ratio(rs)
frac = (
(mpconsts.nounit.Rd * t + mpconsts.nounit.Lv * qs +
ep * qs * mpconsts.nounit.Lv * (1 - params['rh0']) *
mpconsts.nounit.Rd * t / mpconsts.nounit.g)
/ (mpconsts.nounit.Cp_d + (
mpconsts.nounit.Lv**2 * qs * mpconsts.nounit.epsilon
/ (mpconsts.nounit.Rd * t**2)
))
)
frac = ((mpconsts.nounit.Rd * t + mpconsts.nounit.Lv * qs
+ ep * qs * mpconsts.nounit.Lv * (1 - params['rh0'])
* mpconsts.nounit.Rd * t / mpconsts.nounit.g)
/ (mpconsts.nounit.Cp_d
+ (mpconsts.nounit.Lv**2 * qs * mpconsts.nounit.epsilon
/ (mpconsts.nounit.Rd * t**2))))
# cap lapse rate at dry adiabat (can be steeper with large entrainment rate)
frac = np.min([frac, mpconsts.nounit.Rd * t / mpconsts.nounit.Cp_d])
return frac / p

def dt_r14(p, t, params):
if hasattr(params['ep'],'__len__'): # evaluate entrainment rate at p if not constant
if hasattr(params['ep'],'__len__'): # evaluate entrainment rate at p if not constant
ep = np.interp(p,params['pa'],params['ep'])
else:
ep = params['ep']
if hasattr(params['de'],'__len__'): # same as above for detrainment
if hasattr(params['de'],'__len__'): # same as above for detrainment
de = np.interp(p,params['pa'],params['de'])
else:
de = params['de']
rs = saturation_mixing_ratio._nounit(p, t)
qs = specific_humidity_from_mixing_ratio(rs)
a1 = ( mpconsts.nounit.Rv * mpconsts.nounit.Cp_d * t**2 / mpconsts.nounit.Lv +
qs * mpconsts.nounit.Lv )
a2 = ( mpconsts.nounit.Rv * mpconsts.nounit.Cp_d * t**2 / mpconsts.nounit.Lv *
(de + mpconsts.nounit.g / (mpconsts.nounit.Rd * t)) +
qs * mpconsts.nounit.Lv * (de - ep) - mpconsts.nounit.g )
a3 = ( (mpconsts.nounit.Rv * mpconsts.nounit.Cp_d * t /
(mpconsts.nounit.Rd * mpconsts.nounit.Lv) - 1) * mpconsts.nounit.g * de )
frac = ( mpconsts.nounit.Rd * t / (mpconsts.nounit.g) *
mpconsts.nounit.Rv * t**2 / mpconsts.nounit.Lv *
((-a2 + np.sqrt(a2**2 - 4 * a1 * a3)) / (2 * a1) +
mpconsts.nounit.g / (mpconsts.nounit.Rd * t)) )
a1 = (mpconsts.nounit.Rv * mpconsts.nounit.Cp_d * t**2 / mpconsts.nounit.Lv
+ qs * mpconsts.nounit.Lv )
a2 = (mpconsts.nounit.Rv * mpconsts.nounit.Cp_d * t**2 / mpconsts.nounit.Lv
* (de + mpconsts.nounit.g / (mpconsts.nounit.Rd * t))
+ qs * mpconsts.nounit.Lv * (de - ep) - mpconsts.nounit.g )
a3 = ((mpconsts.nounit.Rv * mpconsts.nounit.Cp_d * t
/ (mpconsts.nounit.Rd * mpconsts.nounit.Lv) - 1) * mpconsts.nounit.g * de )
frac = (mpconsts.nounit.Rd * t / (mpconsts.nounit.g)
* mpconsts.nounit.Rv * t**2 / mpconsts.nounit.Lv
* ((-a2 + np.sqrt(a2**2 - 4 * a1 * a3)) / (2 * a1)
+ mpconsts.nounit.g / (mpconsts.nounit.Rd * t)) )
return frac / p

temperature = np.atleast_1d(temperature)
Expand Down

0 comments on commit 5f1cc4d

Please sign in to comment.