"""----- CLEO -----File: thermoeqns.pyProject: sdmout_srcCreated Date: Tuesday 24th October 2023Author: Clara Bayley (CB)Additional Contributors:-----Last Modified: Monday 8th April 2024Modified By: CB-----License: BSD 3-Clause "New" or "Revised" Licensehttps://opensource.org/licenses/BSD-3-Clause-----Copyright (c) 2023 MPI-M, Clara Bayley-----File Description:equations in python for calculating thermodynamicvariables e.g. potential temperature"""importnumpyasnpdefvapour_pressure(press,qv,Mr_ratio):pv=qv*press/(Mr_ratio+qv)returnpvdefrelative_humidity(p,temp,qv,Mr_ratio):pv=vapour_pressure(p,qv,Mr_ratio)psat=saturation_pressure(temp)relh=pv/psatreturnrelhdefsupersaturation(p,temp,qv,Mr_ratio):pv=vapour_pressure(p,qv,Mr_ratio)psat=saturation_pressure(temp)qsat=Mr_ratio*psat/(p-pv)supersat=qv/qsat-1returnsupersat
[docs]defsaturation_pressure(TEMP):"""Calculate the equilibrium vapor pressure of water over liquid water ie. the saturation pressure (psat) given TEMP /K. Equation taken from Bjorn Steven's "make_tetens" python function from his module "moist_thermodynamics.saturation_vapour_pressures" available on gitlab. Original paper "Murray, F. W. On the Computation of Saturation Vapor Pressure. Journal of Applied Meteorology and Climatology 6, 203–204 (1967)." """A=17.4146# constants from Bjorn Gitlab originally from paperB=33.639# dittoTREF=273.16# Triple point temperature [K] of waterPREF=611.655# Triple point pressure [Pa] of waterifnp.any(TEMP<=0):err="Temperature must be larger than 0K."raiseValueError(err)expothis=A*(TEMP-TREF)/(TEMP-B)returnPREF*np.exp(expothis)# dimensionless psat /Pa
[docs]defsaturation_pressure_murphy_koop(TEMP):"""Calculate the equilibrium vapor pressure of water over liquid water ie. the saturation pressure (psat [Pa]). Equation taken from typhon.physics.thermodynamics.e_eq_water_mk."""ifnp.any(TEMP<=0):err="Temperature must be larger than 0K."raiseValueError(err)lnpsat=(54.842763# ln(psat) [Pa]-6763.22/TEMP-4.21*np.log(TEMP)+0.000367*TEMP+np.tanh(0.0415*(TEMP-218.8))*(53.878-1331.22/TEMP-9.44523*np.log(TEMP)+0.014025*TEMP))returnnp.exp(lnpsat)# psat [Pa]
[docs]defdry_pot_temp(Temp,P,qv,consts):"""calculate potential Temperature [K] assuming moist (unsaturated) air with vapour content qv"""Cpdry=consts["CP_DRY"]Cpv=consts["CP_V"]Rgasdry=consts["RGAS_DRY"]Rgasv=consts["RGAS_V"]Cp=Cpdry*(1+qv*Cpv/Cpdry)/(1+qv)Rgas=Rgasdry*(1+qv*Rgasv/Rgasdry)/(1+qv)Theta=Temp*(P[0]/P)**(Rgas/Cp)returnTheta
[docs]defspecific_moist_static_energy(Z,Temp,qv,consts):"""calculate the specific mass moist static energy, mse, J/Kg. (ie. mse per unit mass)."""GRAVG=consts["G"]# [m/s^2]Latent_v=consts["LATENT_V"]# [J/Kg]Cp_dry=consts["CP_DRY"]# [J/Kg/K]returnGRAVG*Z+Latent_v*qv+Cp_dry*Temp