Skip to content
Snippets Groups Projects
Commit e15c80aa authored by bjorn-stevens's avatar bjorn-stevens
Browse files

fixed doctest, including bug-fix of two es_mxd*

Fixed the call and expected outcome statements of the doctest strings in
the funciton documentation.  In doing noticed that for the mixed
supersaturations we should use the minimum, not maximum values, which
reverts a false correction from a previous commit.
parent 69b62764
No related branches found
No related tags found
No related merge requests found
...@@ -35,8 +35,8 @@ def es_liq(T): ...@@ -35,8 +35,8 @@ def es_liq(T):
def es_ice(T): def es_ice(T):
""" Returns the saturation vapor pressure of water over ice following Wagner et al., (2011) """ Returns the saturation vapor pressure of water over ice following Wagner et al., (2011)
fits for saturation over ice, these also define the IAPWS standard for ice. fits for saturation over ice, these also define the IAPWS standard for ice.
>>> mt.es_ice(np.asarray([273.16,260.])) >>> es_ice(np.asarray([273.16,260.]))
[611.65706974, 222.66896149] array([611.655 , 195.80103377])
""" """
TvT = constants.temperature_water_vapor_triple_point TvT = constants.temperature_water_vapor_triple_point
PvT = constants.pressure_water_vapor_triple_point PvT = constants.pressure_water_vapor_triple_point
...@@ -54,10 +54,10 @@ def es_ice(T): ...@@ -54,10 +54,10 @@ def es_ice(T):
def es_mxd(T): def es_mxd(T):
""" Saturation vapor pressure of water over liquid (T>Tmelt) or ice (T>Tmel) following the """ Saturation vapor pressure of water over liquid (T>Tmelt) or ice (T>Tmel) following the
Wagner and Pruss (2002) and Wagner et al (2011) formuations for each of these. Wagner and Pruss (2002) and Wagner et al (2011) formuations for each of these.
>>> mt.es_mxd(np.asarray([305.,260.])) >>> es_mxd(np.asarray([305.,260.]))
[4719.32683147, 222.66896149] array([4719.32683147, 195.80103377])
""" """
return np.maximum(es_liq(T),es_ice(T)) return np.minimum(es_liq(T),es_ice(T))
def es_liq_analytic(T, delta_cl=constants.delta_cl): def es_liq_analytic(T, delta_cl=constants.delta_cl):
""" Returns an analytic approximation to the saturation vapor pressure over liquid """ Returns an analytic approximation to the saturation vapor pressure over liquid
...@@ -103,7 +103,7 @@ def es_mxd_analytic(T, delta_cl=constants.delta_cl, delta_ci=constants.delta_ci) ...@@ -103,7 +103,7 @@ def es_mxd_analytic(T, delta_cl=constants.delta_cl, delta_ci=constants.delta_ci)
>>> es_ice_analytic(np.asarray([273.16,260.])) >>> es_ice_analytic(np.asarray([273.16,260.]))
array([611.655 , 195.99959431]) array([611.655 , 195.99959431])
""" """
return np.maximum(es_liq_analytic(T,delta_cl),es_ice_analytic(T,delta_ci)) return np.minimum(es_liq_analytic(T,delta_cl),es_ice_analytic(T,delta_ci))
def vaporization_enthalpy(TK,delta_cl=constants.delta_cl): def vaporization_enthalpy(TK,delta_cl=constants.delta_cl):
""" Returns the enthlapy [J/g] of vaporization (default) of water vapor or """ Returns the enthlapy [J/g] of vaporization (default) of water vapor or
...@@ -296,8 +296,8 @@ def theta_rho(TK,PPa,qt,es=es_liq): ...@@ -296,8 +296,8 @@ def theta_rho(TK,PPa,qt,es=es_liq):
def T_from_Te(Te,P,qt,es=es_liq): def T_from_Te(Te,P,qt,es=es_liq):
""" Given theta_e solves implicitly for the temperature at some other pressure, """ Given theta_e solves implicitly for the temperature at some other pressure,
so that theta_e(T,P,qt) = Te so that theta_e(T,P,qt) = Te
>>> T_from_Te(350.,1000.,17) >>> T_from_Te(350.,100000.,17.e-3)
304.4761977 array([304.49321301])
""" """
def zero(T,Te,P,qt,es=es): def zero(T,Te,P,qt,es=es):
return np.abs(Te-theta_e(T,P,qt,es=es)) return np.abs(Te-theta_e(T,P,qt,es=es))
...@@ -326,8 +326,8 @@ def T_from_Ts(Ts,P,qt,es=es_liq): ...@@ -326,8 +326,8 @@ def T_from_Ts(Ts,P,qt,es=es_liq):
def P_from_Te(Te,T,qt,es=es_liq): def P_from_Te(Te,T,qt,es=es_liq):
""" Given Te solves implicitly for the pressure at some temperature and qt """ Given Te solves implicitly for the pressure at some temperature and qt
so that theta_e(T,P,qt) = Te so that theta_e(T,P,qt) = Te
>>> P_from_Te(350.,305.,17) >>> P_from_Te(350.,305.,17e-3)
100464.71590478 array([100586.3357635])
""" """
def zero(P,Te,T,qt,es=es_liq): def zero(P,Te,T,qt,es=es_liq):
return np.abs(Te-theta_e(T,P,qt,es=es)) return np.abs(Te-theta_e(T,P,qt,es=es))
...@@ -346,7 +346,7 @@ def P_from_Tl(Tl,T,qt,es=es_liq): ...@@ -346,7 +346,7 @@ def P_from_Tl(Tl,T,qt,es=es_liq):
def plcl(TK,PPa,qt,es=es_liq): def plcl(TK,PPa,qt,es=es_liq):
""" Iteratively solve for the pressure [Pa] of the LCL, allows for saturate air. """ Iteratively solve for the pressure [Pa] of the LCL, allows for saturate air.
>>> plcl(300.,102000.,17e-3) >>> plcl(300.,102000.,17e-3)
array([95971.6975098]) array([95971.69750248])
""" """
p2r = partial_pressure_to_mixing_ratio p2r = partial_pressure_to_mixing_ratio
...@@ -356,7 +356,7 @@ def plcl(TK,PPa,qt,es=es_liq): ...@@ -356,7 +356,7 @@ def plcl(TK,PPa,qt,es=es_liq):
return np.abs(qs/qt-1.) return np.abs(qs/qt-1.)
Tl = theta_l(TK,PPa,qt) Tl = theta_l(TK,PPa,qt)
return optimize.fsolve(zero, 80000., args=(Tl,qt), xtol=1.e-10) return optimize.fsolve(zero, 80000., args=(Tl,qt), xtol=1.e-5)
def plcl_bolton(TK,PPa,qt): def plcl_bolton(TK,PPa,qt):
""" Returns the pressure [Pa] of the LCL using the Bolton formula. Usually accurate to """ Returns the pressure [Pa] of the LCL using the Bolton formula. Usually accurate to
...@@ -380,8 +380,8 @@ def zlcl(Plcl,T,P,qt,z): ...@@ -380,8 +380,8 @@ def zlcl(Plcl,T,P,qt,z):
""" Returns the height of the LCL assuming temperature changes following a """ Returns the height of the LCL assuming temperature changes following a
dry adiabat with vertical displacements from the height where the ambient dry adiabat with vertical displacements from the height where the ambient
temperature is measured. temperature is measured.
>>> Zlcl(300.,1020.,17) >>> zlcl(95000.,300.,90000.,17.e-3,500.)
96007.495 16.621174077862747
""" """
Rd = constants.dry_air_gas_constant Rd = constants.dry_air_gas_constant
Rv = constants.water_vapor_gas_constant Rv = constants.water_vapor_gas_constant
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment