# Water Vapor Calculator

My Projects
My Profile
Logout
Undo
Redo
Cut
Copy
Paste
Delete
Select All
Find
Find and Replace
Editor Theme
Crimson
Eclipse
Github
Solarized
Cobalt
krTheme
Monokai
Terminal
Textmate
Twilight
Vibrant Ink
Font Size
8px
9px
10px
11px
12px
13px
14px
15px
16px
17px
18px
20px
22px
24px
Tab Size
1
2
3
4
5
6
7
8
Show Invisible
Hide Invisible
Show Line Numbers
Hide Line Numbers
Ace Editor (Default)
Vim Editor
Emacs Editor
Open New Project
Save Project
Save As New Project
Share Project
Search Project
# Atmospheric thermodynamics calculators and LCL calculator. import math # Function to calculate the saturation vapor pressure over water in mb for temperature T in C. # Relationship is from Bolton as quoted in Grant Petty's Atmospheric Thermo book. def esatWater(T): return 6.112*math.exp(17.67*T/(243.5+T)) # Function to calculate relative humidity, RH, in %, from T and Tdew in C. # This function calls the esatWater function. def RelativeHumidity(Tdew,T): return 100.0*esatWater(Tdew)/esatWater(T) # Function to calculate the approximate water vapor mixing ratio in g/kg # Inputs are water vapor pressure, e, in mb and total pressure, P, in mb. def mixingRatio(e,P): Ro = 8314.3 # Universal gas constant in Joules/K kmole RD = Ro/28.97 # Dry air gas constant in Joules/K kg Rv = Ro/18.02 # Water vapor gas constant in Joules/K kg epsilon=RD/Rv return epsilon*e*1000.0/(P-e) # Potential temperature calculator, returning in Celsius. # T is entered in Celsius, P in mb. def PotTemp(T,P): theta=(T+273.15)*((1000.0/P)**(2.0/7.0)) return theta-273.15 # Pressure altitude calcutor, returning in meters. # Inputs: # To, Po, starting temperature in Kelvin and mb. # Pz pressure in mb where the pressure altitude is desired. def PressureAltitude(To,Po,Pz): gamma=9.8/1000.0 # Lapse rate in Kelvin / meter Ro = 8314.3 # Universal gas constant in Joules/K kmole RD = Ro/28.97 # Dry air gas constant in Joules/K kg g = 9.81 # Acceleration due to gravity in N/kg. expon=RD*gamma/g PressureRatio=Pz/Po z=(To/gamma)*(1-PressureRatio**expon) return z # Function to calculate the Lifting condensation level properties, LCL. # LCL P and T calculator given Tdew, To, and Po at the level o. # Theory: mixing ratio and potential temperature are constant (conserved) below the LCL. # Solve the equations for mixing ratio and potential temperature for pressure. # Set these equations for pressure equal to each other and solve for temperature. # INPUTS: # Po in mb # To in Celsius # Tdew in Celsius. # OUTPUTS: # P in mb, pressure at the LCL. # Tc in Celsius, temperature at the LCL. # zo in meters, the height of the starting level o as a pressure altitude. # z in meters, the height of the LCL level pressure altitude. # thetaK in Kelvin, the potential temperature below the LCL (constant value). # wo in kg/kg, the water vapor mixing ratio below the LCL (constant value) # Tw in Celsius, wet bulb temperature at Po. # ThetaW in Kelvin, wet bulb temperature at 1000 mb. def LCL(Po,To,Tdew): epsilon=0.622 e0=esatWater(0.0) # Saturation vapor pressure at T=0 C. zo=PressureAltitude(285.0,1013.25,Po) # Pressure altitude at the initial point. esatTdew=esatWater(Tdew) # Saturation vapor pressure at the dew point temp. wo=mixingRatio(esatTdew,Po)/1000.0 # kg/kg value. beta=epsilon*e0/(wo*1000.0) # Intermediate value. thetaK=PotTemp(To,Po) + 273.15 # Potential temperature in Kelvin. thetaE_K=thetaK+3000.0*wo Tguess=-10.0 + 273.15 # Initial guess in Kelvin. #print " Itterating to get the LCL temperature" for i in range(100): T=273.15+(3.5*math.log(Tguess/thetaK)-math.log(beta))*(243.5+Tguess-273.15)/17.67 # print "Tguess={0:1.3f}".format(Tguess),"K"," T={0:1.3f}".format(T),"K" Tguess=T Tc=T-273.15 # temperature at the LCL in Celsius. P=1000.0*((T/thetaK)**3.5) # Pressure at the LCL in mb. z=PressureAltitude(To+273.15,Po,P)+zo # Pressure altitude at the LCL in meters. # Get the wetbulb temperature and the wetbulb potential temperature. PressureValues=[Po,1000.0] # Pressure values for wet bulb and wetbulb potential temp are needed. nudge = 0.5 # Used for itterating towards a solution, use the new value with the old value. for pref in PressureValues: # Loop over pressure values Tguess=(Tdew+To)/2.0 + 273.15 # Initial estimate for wetbulb for i in range(100): Tw=nudge*(thetaE_K-3.0*mixingRatio(esatWater(Tguess-273.15),pref))*((pref/1000.0)**(2./7.)) + (1.0-nudge)*Tguess Tguess=Tw if pref == Po: Twvalue=Tw-273.15 elif pref == 1000.0: thetaW=Tw return P,Tc,zo,z,thetaK,wo,thetaE_K,Twvalue,thetaW # Demonstrate saturation water vapor partial pressure calculator. print "SATURATON VAPOR PRESSURE CALCULATOR RESULTS" esat20C=esatWater(20.0) print "esatWater(T=20C)={0:1.2f}".format(esat20C),"mb\n" # Demonstrate relative humidity calculator. print "RELATIVE HUMIDITY CALCULATOR RESULTS" Tdew=-1.0 # Celsius T =20.0 # Celsius RH = RelativeHumidity(Tdew,T) print "RH(Tdew={0:1.1f}".format(Tdew),"C, T={0:1.1f}".format(T),"C) = {0:1.2f}".format(RH),"%\n" # Demonstrate water vapor mixing ratio calculator. print "SATURATION WATER VAPOR MIXING RATIO CALCULATOR RESULTS" P=1000.0 # total pressure in mb. T=20.0 # temperature in Celsius. Wsat20C=mixingRatio(esatWater(T),P) print "INPUT VALUES:" print " P={0:1.1f}".format(P),"mb" print " T={0:1.2f}".format(T),"C" print "Calculated Wsat={0:1.2f}".format(Wsat20C),"g/kg\n" # Demonstrate water vapor mixing ratio calculator. print "SATURATION WATER VAPOR MIXING RATIO CALCULATOR RESULTS" P=1000.0 # total pressure in mb. T=-1.0 # temperature in Celsius. Wsat20C=mixingRatio(esatWater(T),P) print "INPUT VALUES:" print " P={0:1.1f}".format(P),"mb" print " T={0:1.2f}".format(T),"C" print "Calculated Wsat={0:1.2f}".format(Wsat20C),"g/kg\n" # Demonstrate the pressure altitude calculator. To=290.0 # Kelvin Assumed temperature value at the surface. Po=1013.25 # mb Taken to be sea level pressure. Pz=400.0 # mb Pressure at the unknown altitude. z=PressureAltitude(To,Po,Pz) print "PRESSURE ALTITUDE CALCULATOR RESULTS" print "INPUT VALUES:" print " Po={0:1.1f}".format(Po),"mb" print " To={0:1.2f}".format(To),"C" print " Pz={0:1.1f}".format(Pz),"mb" print "Calculated Pressure Altitude={0:1.1f}".format(z),"meters\n" # Demonstrate the LCL calculator. # Input values Po=876.0 # Pressure at the measurement level. To=21.0 # Temperature at the measurement level. Tdew=9.59 # Dewpoint temperature at the measurement level. # Call the function P,Tc,zo,z,thetaK,wo,thetaE_K,Tw,thetaW = LCL(Po,To,Tdew) # Summary the LCL calculation output. print "LCL CALCULATOR RESULTS" print "INPUT VALUES:" print " Po={0:1.1f}".format(Po),"mb" print " To={0:1.2f}".format(To),"C" print " Tdew={0:1.2f}".format(Tdew),"C" print " Calculated Pressure Altitude={0:1.1f}".format(zo),"meters" print "CONSTANT VALUES BELOW THE LCL:" print " Potential Temperature={0:1.1f}".format(thetaK),"K ={0:1.1f}".format(thetaK-273.15),"C" print " Water vapor mixing ratio={0:1.2e}".format(wo),"kg/kg ={0:1.2f}".format(wo*1000.0),"g/kg" print "CONSTANT VALUE EVERYWHERE ON THE PARCEL TRAJECTORY:" print " Equivalent Potential Temperature={0:1.1f}".format(thetaE_K),"K ={0:1.1f}".format(thetaE_K-273.15),"C" print "WET BULB RELATED VALUES:" print " Wetbulb Temperature={0:1.1f}".format(Tw+273.15),"K ={0:1.1f}".format(Tw),"C" print " Wetbulb Potential Temperature={0:1.1f}".format(thetaW),"K ={0:1.1f}".format(thetaW-273.15),"C" print "LCL VALUES:" print " P={0:1.1f}".format(P),"mb" print " T={0:1.1f}".format(Tc+273.15),"K ={0:1.2f}".format(Tc),"C" print " Calculated Pressure Altitude={0:1.1f}".format(z),"meters"

# Water Vapor Calculator (Python v2.7.13)

Water Vapor Calculator (Python v2.7.13) helps you to Edit, Run and Share your Python Code directly from your browser. This development environment provides you version Python v2.7.13.

## How to give program Input?

The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.

## Keyboard Shortcuts

ShortcutDescription
⌘ + EnterRun the program
⌘ + SSave Project (Login Required)
⇧ + ⌘ + SSave As Project
⌘ + PNew Project
⌘ + GShare Project
⌘ + ZUndo Editing
⌘ + YRedo Editing
⌘ + ASelect All Text
⌘ + XCut Selected Text
⌘ + CCopy Selected Text
⌘ + VPaste Copied Text
⌘ + FSearch Text
⌘ + ⌥ + FReplace Text
ShortcutDescription
Ctrl + EnterRun the program
Ctrl + SSave Project
Shift + Ctrl + SSave As Project
Ctrl + GShare Project
Ctrl + ZUndo Editing
Ctrl + YRedo Editing
Ctrl + ASelect All Text
Ctrl + XCut Selected Text
Ctrl + CCopy Selected Text
Ctrl + VPaste Copied Text
Ctrl + FSearch Text
Ctrl + HReplace Text

## Save Python Project

You can save your Python Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.

## Share Python Project

You can use this feature to share your Python Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.