wrf-python icon indicating copy to clipboard operation
wrf-python copied to clipboard

A question about the equation used in wrf.rh

Open KianHuangKimeow opened this issue 1 year ago • 3 comments

I recently converted mixing ratio (qv) to relative humidity (RH) by using wf-python and metpy. I compared the results from wrf.rh and metpy.calc.relative_humidity_from_mixing_ratio, and found that the RH from wrf-python is overall higher than the one from metpy.

Although the definitions of relative humidity are different between wrf-python (qv/qvs) and metpy (WMO standard), there is another significant difference between these two libraries. In both libraries, related functions compute the saturation vapor pressure using an empirical equation and then the saturation mixing ratio (qvs). However, in wrf_user.f90, there is another term (1.D0 - EPS) in subroutine DCOMPUTERH. qvs = EPS*es/(0.01D0*pressure - (1.D0 - EPS)*es) I am wondering whether this term should appear here.

KianHuangKimeow avatar Feb 18 '25 04:02 KianHuangKimeow

Working through a derivation: $q_{vs}=\frac{m_v}{m_d} = \frac{N_v M_v}{N_d M_d}=\frac{M_v}{M_d} \left(\frac{P_v V}{R^* T} / \frac{P_d V}{R^* T}\right) = \frac{M_v}{M_d} \frac{P_v}{P_d} = \frac{M_v}{M_d} \frac{P_v}{P_{tot} - P_v}$ I don't see that term either. It looks like the complement of the mass ratio of water to dry air, but the scenarios I can think of with such a quantity involve parcel-total quantities, rather than only partial pressure of water vapor. Given one could find the same kind of equation for, say, CFCs, which would have $1 - \frac{M_{CFC}}{M_d} < 0$, I am leery of that term.

The logs for that line say it was last changed when adding unit tests, though that commit just got rid of spaces. Before that was a backport from NCL, which changed the name of the constant and added spaces. Before that was this commit creating wrf_user.f90, so prior history would be in the NCL repository here, which helpfully informs me that it got that code from wrf-python.

This file seems to have the old version, which this commit seems to have created. It looks like that would be the earliest version of wrf_rh/dcomputerh, added for version 4.2.0 alpha 34.

There's another file with the same formulation, but without the constants, present from the 2005 creation of that function, but it doesn't document why

DWesl avatar Feb 19 '25 01:02 DWesl

It looks like the WRF-Python function is using the following definition of relative humidity based upon specific humidity: $RH=\frac{q}{q_s} $

With the saturation specific humidity defined as: $q_s=\frac{\epsilon e_s}{P-e_s (1-\epsilon)} $

Interestingly, the documentation defines qv (or ${q}$ as I defined it above) as the mixing ratio. I'm not sure why this is the case, but suspect the terms may be being used interchangeably.

As @DWesl mentioned, it looks like this came from the NCL codebase, but I'm not sure on the history before that. I did notice that the coefficients for calculating saturation vapor pressure were consistent with those used in WRF, but didn't see this formulation for RH in there.

I can ask around to see if anyone might know more.

Some references:

  • https://pressbooks-dev.oer.hawaii.edu/atmo/chapter/chapter-4-water-vapor/
  • http://www.atmo.arizona.edu/students/courselinks/spring11/hwr523/HWR423_523_files/Module1b.pdf

kafitzgerald avatar Mar 06 '25 01:03 kafitzgerald

I found a similar definition in a relative humidity function written in 1992 for whichever of NCEP or NMC existed at the time, with no indication the coefficient of $e_s$ was changed since then. This might mean some NMC report has a derivation,

I'm inclined to think the $P_{tot} - e$ bit means it's defined in terms of mixing ratio, which I seem to recall WRF using, rather than specific humidity.

On the other hand: $$q = \frac{\frac{M_v}{M_d} e}{p_{tot} - \frac{M_d - M_v}{M_d} e} = \frac{M_v e}{M_d (p_{tot} - e) + M_v e}$$ $$q = \frac{M_v e}{M_d p_d + M_v e} = \frac{m_v}{m_d+m_v}$$ it looks like a specific-humidity definition with a few optimizations ($M_d p_d = M_d N_d R^* T / V = m_d R^* T/V$, most of which cancels).

That rather explains why my mixing-ratio derivation didn't come close.

DWesl avatar Mar 14 '25 00:03 DWesl