atmos-python / atmos

An atmospheric sciences library for Python
MIT License
64 stars 21 forks source link

Calculate absolute humidity from temperature and relative humidity #3

Open vrs01 opened 7 years ago

vrs01 commented 7 years ago

Hi!

I got a bit lost in all of these formulas. Could someone tell what would be the most elegant way to calculate the absolute humidity from a given temperature and a relative humidity value?

Best, vrs01

mcgibbon commented 7 years ago

You can calculate AH from density (rho, in kg/m^3), pressure (p, in Pa), relative humidity (RH, in percent), and temperature (T, in degK) using the following sequence of formulas:

es = 611.2*exp(17.67*(T-273.15)/(T-29.65))
rvs = 0.622*es/(p - es)
rv = RH/100. * rvs
qv = rv/(1 + rv)
AH = qv*rho

You can also use p = rho * Rd * T to calculate one of the three required quantities from the other two.

vrs01 commented 7 years ago

can I use the FluidSolver for this?

mcgibbon commented 7 years ago

Yes, using debug=True. Though it should be simpler to use calculate. Specifically:

from atmos import calculate
print(calculate('AH', RH=50., p=1e5, T=300., debug=True)

The second returned value should be a list of functions, and you can look at their docstrings or at their equation property (e.g. rv_from_e_es.equation).

iamz33 commented 5 years ago

Hey there, Thanks for the simple sequence of formulas. Its really convenient. Can you please provide reference from where you got the formulas? I want to add them in my report for reference. Many thanks.

mcgibbon commented 5 years ago

@iamz33 when writing I put references down in the docstrings for equations, using an automatic documentation thing I wrote in the equations module. The dictionary ref at the top contains all the references, and for each equation you can see which references it uses in the references argument for @autodoc.

mcgibbon commented 5 years ago

Ah, cool. You can also access the references of the equations using e.g. rv_from_e_es.references.

iamz33 commented 5 years ago

Perfect!! Thanks.