pyAtmosThermo Documentation Release 0.1

Ravi Shekhar

February 06, 2016

Contents

i ii pyAtmosThermo Documentation, Release 0.1

This library allows calculation of moist atmospheric thermodynamic quantities. For example, the following snippet will calculate moist static energy from mixing ratio of 0.001 kg/kg, 298 Kelvin, and 200 meters height. Thus, MSE has the value 304161.6 J/kg. import atmos_thermo h= atmos_thermo.h_from_r_T_z(0.001, 298, 200)

This code calculates the saturation vapor pressure and produces 3533.7 Pa. e_saturation= atmos_thermo.esat_from_T(300)

All functions are designed around using numpy arrays transparently, and using numpy arrays is vastly faster than passing in values one by one. Contents:

Contents 1 pyAtmosThermo Documentation, Release 0.1

2 Contents CHAPTER 1

atmos_thermo package

1.1 Submodules

1.2 atmos_thermo.atmoslib module

atmos_thermo.atmoslib.Lv_from_T(T) Calculate of vaporization for water, Lv. Args: T: temperature (Kelvin) Returns: Latent heat of vaporization [J / kg K] atmos_thermo.atmoslib.T_from_p_theta(p, theta, p0=100000.0) Calculate the temperature of air. Calculate the temperature (T) given pressure (p) and potential temperature (theta). Formula is : T = theta * (p / p0) ** (R_d / C_pd) Args: p: total pressure (Pascals) theta: potential temperature (Kelvin) p0: reference pressure used in calculating potential temperature Returns: temperature in Kelvin atmos_thermo.atmoslib.Tv_from_r_T(r, T) Calculate the virtual temperature. Calculate the virtual temperature (T_v) given temperature (T) and mixing ratio (r). Args: r: mixing ratio (dimensionless) T: temperature (Kelvin) Returns: Virtual Temperature in Kelvin atmos_thermo.atmoslib.e_from_r_p(r, p) Calculate partial pressure of water vapor. Calculate partial pressure of water vapor (e) from mixing ratio (r) and total pressure (p). Args: r: Mixing ratio in dimensionless ([kg H2O]/[kg Air]) units. p: Total pressure in Pascals. Returns: Vapor pressure (e) in Pascals. atmos_thermo.atmoslib.esat_from_T(T) Calculates saturation vapor pressure. Using the reference Emanuel 1994 (Atmospheric ) p.116, equation 4.4.13 , this function calculates the saturation vapor pressure (esat) at the given temperature.

3 pyAtmosThermo Documentation, Release 0.1

Args: T: Air temperature in Kelvin. Can be numpy array. Returns: Saturation vapor pressure (esat) in units of Pa. atmos_thermo.atmoslib.h_Em1994_from_r_T_z(r, T, z) Calculate the moist static energy (h). Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.23 h = (C_pd + r_t C_pv) T + Lv r + g z Args: r: mixing ratio (dimensionless) T: temperature (Kelvin) z: height (meters) Returns: Moist static energy in J/kg (m^2 / s^2) atmos_thermo.atmoslib.h_KF_from_r_T_z_rliq_rfroz(r, T, z, rliq, rfroz) Calculate moist static energy according to the Kain-Fritsch definition. The standard frozen MSE formulation is: h = cp * T + Lv * r + g * z - Lf * r_froz Kain-Fritsch uses: cp_moist = cp_dry * (1 + 0.887 * r) # this is only the vapor r Lv = XLV0 - T * XLV1 Lf = XLS0 - T * XLS1 XLV0 = 3.15E6 J/kg XLV1 = 2370 J/(kg K) XLS0 = 2.905E6 J/kg XLS1 = 259.532 J/(kg K) atmos_thermo.atmoslib.h_from_r_T_z(r, T, z) Calculate the moist static energy (h). Using the classical definiton of moist static energy h = C_pd T + Lv r + g z Args: r: mixing ratio (dimensionless, or kg/kg) T: temperature (Kelvin) z: height (meters) Returns: Moist static energy in J/kg (m^2 / s^2) atmos_thermo.atmoslib.hd_Em1994_from_r_T_z(r, T, z) Calculate the dry static energy (hd). Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.23. Notice that the mixing ratio is required to calculate the heat capacity correctly. hd = (C_pd + r_t C_pv) T + g z Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) z: height (meters). Returns: Dry static energy in J/kg (m^2 / s^2) atmos_thermo.atmoslib.hd_from_r_T_z(r, T, z) Calculate the classical dry static energy (hd). Args: p: total pressure (Pascals) T: temperature (Kelvin) z: height (meters). Returns: Dry static energy in J/kg (m^2 / s^2) atmos_thermo.atmoslib.hstar_Em1994_from_p_T_z(p, T, z) Calculate the saturation moist static energy (h). Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.23 h = (C_pd + r_sat C_pv) T + Lv (r_sat) + g z Args: p: total pressure (Pascals) T: temperature (Kelvin) z: height (meters) Returns: Saturation moist static energy in J/kg (m^2 / s^2) atmos_thermo.atmoslib.hstar_classical_from_p_T_z(p, T, z) Calculate the saturation moist static energy (h). Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.23

4 Chapter 1. atmos_thermo package pyAtmosThermo Documentation, Release 0.1

h = (C_pd + r_sat C_pv) T + Lv (r_sat) + g z Args: p: total pressure (Pascals) T: temperature (Kelvin) z: height (meters) Returns: Saturation moist static energy in J/kg (m^2 / s^2) atmos_thermo.atmoslib.moist_specific_entropy_Emanuel_from_r_p_T(r, p, T, r_rain=0, r_cloud=0, r_ice=0) Calculate the moist specific entropy. Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.9 s = (C_pd + C_pv * r_t) * ln(T) • R_d ln (pd)

• Lv r / T

• r R_v ln (H)

Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) Returns: Equivalent potential temperature in Kelvin atmos_thermo.atmoslib.moist_specific_entropy_Emanuel_sat_from_p_T(p, T, r_rain=0, r_cloud=0, r_ice=0) Calculate the moist specific entropy. Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.9 s = (C_pd + C_pv * r_t) * ln(T) • R_d ln (pd)

• Lv r / T

• r R_v ln (H)

Args: p: total pressure (Pascals) T: temperature (Kelvin) Returns: Equivalent potential temperature in Kelvin atmos_thermo.atmoslib.moist_specific_entropy_from_r_p_T(r, p, T) Calculate the moist specific entropy. Calculate moist specific entropy for the mixing ratio (r), total pressure (p), and temperature (T). Uses the definition given in Benedict et. al 2014 - Gross Moist Stability and MJO Simulation Skill ... Equation 1 Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) Returns: Moist specific entropy in J / (kg K) atmos_thermo.atmoslib.pd_from_r_p(r, p) Calculate dry pressure without water vapor. Calculate dry pressure (pd) from mixing ratio (r) and total pressure (p) Args: r: Mixing ratio in dimensionless ([kg H2O]/[kg Air]) units. p: Total pressure in Pascals.

1.2. atmos_thermo.atmoslib module 5 pyAtmosThermo Documentation, Release 0.1

Returns: Dry pressure (pd) in Pascals. atmos_thermo.atmoslib.q_from_e_p(e, p) Calculates specific . Calculates specific humidity given vapor pressure (e) and total pressure (p). Typically vapor pressure is e and specific humidity is q in the literature. q = [mass of H20 vapor] / [mass of total air] relationship is : q = epsilon * e / (p - e*(1-epsilon)) Args: e: Vapor pressure in Pascals p: Total pressure in Pascals Returns: Specific humidity in dimensionless ([kg H2O]/[kg Air]) units. atmos_thermo.atmoslib.q_from_r(r) Calculates specific humidity. Calculates specific humidity given mixing ratio. Typically mixing ratio is r and specific humidity is q in the literature. r = [mass of H20 vapor] / [mass of dry air] q = [mass of H20 vapor] / [mass of total air] relationship is : q = r / (1+r) Args: r: Mixing ratio in dimensionless ([kg H2O]/[kg Air]) units. Returns: Specific humidity in dimensionless ([kg H2O]/[kg Air]) units. atmos_thermo.atmoslib.r_from_e_p(e, p) Calculate mixing ratio of water vapor. Calculate mixing ratio of water vapor(r) from vapor pressure (e) and total pressure (p). Args: r: Mixing ratio in dimensionless ([kg H2O]/[kg Air]) units. p: Total pressure in Pascals. Returns: Vapor pressure (e) in Pascals. atmos_thermo.atmoslib.relhum_from_e_esat(e, esat) Calculate the relative humidity of air. Calculate the relative humidity of air (H) given the vapor pressure (e) and saturation vapor pressure (esat). Args: e: Vapor pressure in Pascals. esat: Saturation vapor pressure in Pascals. Returns: relative humidity in dimensionless units. atmos_thermo.atmoslib.relhum_from_r_p_T(r, p, T) Calculate the relative humidity of air. Calculate the relative humidity of air (H) given the mixing ratio (r), pressure (p) and temperature (T). Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) Returns: relative humidity in dimensionless units. atmos_thermo.atmoslib.streamfunction_from_v_p(v, p) Calculate streamfunction from v, p atmos_thermo.atmoslib.theta_from_p_T(p, T, p0=100000.0) Calculate the potential temperature of air. Calculate the potential temperature (theta) given pressure (p) and temperature (T). Formula is : theta = T * (p0 / p) ** (R_d / C_pd)

6 Chapter 1. atmos_thermo package pyAtmosThermo Documentation, Release 0.1

Args: p: total pressure (Pascals) T: temperature (Kelvin) p0: reference pressure used in calculating potential temperature Returns: potential temperature in Kelvin atmos_thermo.atmoslib.thetae_Bolton_from_r_p_T(r, p, T, p0=100000, r_rain=0.0, r_cloud=0.0) Calculate the pseudoadiabatic equivalent potential temperature. Using the Bolton 1980 definition. Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) Returns: Pseudoadibatic equivalent potential temperature in Kelvin atmos_thermo.atmoslib.thetae_from_r_p_T(r, p, T, p0=100000, r_cloud=0.0) Calculate the reversible equivalent potential temperature. Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.11 theta_e = T * [(p0 / pd) ** (R_d / (C_pd + C_pv * r_t))] • [H ** (-r R_v / (C_pd + C_pv * r_t)) ] • exp[L_v * r / ((C_pd + C_pv * r_t) * T)] Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) Returns: Reversible equivalent potential temperature in Kelvin atmos_thermo.atmoslib.thetae_star_from_p_T(p, T) Calculate the saturation equivalent potential temperature. Using the definition of Emanuel 1994 (Atmospheric Convection). Equation 4.5.11 thetaesat = T * [(p0 / pd) ** (R_d / (C_pd + C_pv * r_t))] • exp[L_v * r / ((C_pd + C_pv * r_t) * T)] Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) Returns: Saturation equivalent potential temperature in Kelvin atmos_thermo.atmoslib.thetav_from_r_p_T(r, p, T) Calculate the virtual potential temperature. Calculate the virtual potential temperature (thetav) given temperature (T) and mixing ratio (r). Args: r: mixing ratio (dimensionless) p: total pressure (Pascals) T: temperature (Kelvin) Returns: Virtual Temperature in Kelvin

1.3 atmos_thermo.constant module

The following constants are accessible as atmos_thermo.catmos. For example, atmos_thermo.catmos.R_d will return the gas constant for dry air. All quantities are in SI units. @readonly def R_d(): 'gas constant of dry air' return 287.04 # , ureg['J / (kg * degK)']

@readonly def R_v():

1.3. atmos_thermo.constant module 7 pyAtmosThermo Documentation, Release 0.1

'gas constant of water vapor' return 461.50 # , ureg['J / (kg * degK)']

@readonly def epsilon(): 'ratio of R_d / R_v' return 0.6220 # , ureg['dimensionless']

@readonly def C_vd(): 'heat capacity of dry air at constant volume' return 719.0 # , ureg['J / (kg * degK)']

@readonly def C_pd(): 'heat capacity of dry air at constant pressure' return 1005.7 # , ureg['J / (kg * degK)']

@readonly def C_vv(): 'heat capacity of water vapor at constant volume' return 1410.0 # , ureg['J / (kg * degK)']

@readonly def C_pv(): 'heat capacity of water vapor at constant pressure' return 1870.0 # , ureg['J / (kg * degK)']

@readonly def C_l(): 'heat capacity of liquid water' return 4190.0 # , ureg['J / (kg * degK)']

@readonly def Lv0(): 'Latent heat of vaporization for water at 0 degrees C' return 2.501E6 # , ureg['J / (kg * degK)']

@readonly def L_v(): 'Latent heat of vaporization for water at 100 degrees C' return 2.26E6

Similarly, these two are earth constants. For example atmos_thermo.cearth.g. @readonly def R_Earth(): return 6.371E6 # , ureg['m']

@readonly def g(): return 9.81 # , ureg['m/s/s']

8 Chapter 1. atmos_thermo package CHAPTER 2

Indices and tables

• genindex • modindex • search

9 pyAtmosThermo Documentation, Release 0.1

10 Chapter 2. Indices and tables Python Module Index

a atmos_thermo.atmoslib,3

11 pyAtmosThermo Documentation, Release 0.1

12 Python Module Index Index

A R atmos_thermo.atmoslib (module),3 r_from_e_p() (in module atmos_thermo.atmoslib),6 relhum_from_e_esat() (in module at- E mos_thermo.atmoslib),6 e_from_r_p() (in module atmos_thermo.atmoslib),3 relhum_from_r_p_T() (in module at- esat_from_T() (in module atmos_thermo.atmoslib),3 mos_thermo.atmoslib),6 H S h_Em1994_from_r_T_z() (in module at- streamfunction_from_v_p() (in module at- mos_thermo.atmoslib),4 mos_thermo.atmoslib),6 h_from_r_T_z() (in module atmos_thermo.atmoslib),4 h_KF_from_r_T_z_rliq_rfroz() (in module at- T mos_thermo.atmoslib),4 T_from_p_theta() (in module atmos_thermo.atmoslib),3 hd_Em1994_from_r_T_z() (in module at- theta_from_p_T() (in module atmos_thermo.atmoslib),6 mos_thermo.atmoslib),4 thetae_Bolton_from_r_p_T() (in module at- hd_from_r_T_z() (in module atmos_thermo.atmoslib),4 mos_thermo.atmoslib),7 hstar_classical_from_p_T_z() (in module at- thetae_from_r_p_T() (in module at- mos_thermo.atmoslib),4 mos_thermo.atmoslib),7 hstar_Em1994_from_p_T_z() (in module at- thetae_star_from_p_T() (in module at- mos_thermo.atmoslib),4 mos_thermo.atmoslib),7 thetav_from_r_p_T() (in module at- L mos_thermo.atmoslib),7 Lv_from_T() (in module atmos_thermo.atmoslib),3 Tv_from_r_T() (in module atmos_thermo.atmoslib),3 M moist_specific_entropy_Emanuel_from_r_p_T() (in module atmos_thermo.atmoslib),5 moist_specific_entropy_Emanuel_sat_from_p_T() (in module atmos_thermo.atmoslib),5 moist_specific_entropy_from_r_p_T() (in module at- mos_thermo.atmoslib),5 P pd_from_r_p() (in module atmos_thermo.atmoslib),5 Q q_from_e_p() (in module atmos_thermo.atmoslib),6 q_from_r() (in module atmos_thermo.atmoslib),6

13