Skip to content

Commit

Permalink
Merge pull request #952 from AlbertoCuadra/develop
Browse files Browse the repository at this point in the history
Add: include routine to compute specific humidity of air
  • Loading branch information
AlbertoCuadra authored Feb 20, 2024
2 parents 0ebecec + fe8ec63 commit 940431c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions utils/thermo/humidity_specific.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function value = humidity_specific(T, p, humidity_relative)
% Get the specific humidity of air [kg_w/kg_da] at a given temperature and pressure
%
% Args:
% T (float): Temperature [K]
% p (float): Pressure [bar]
% humidity_relative (float): Relative humidity [%]
%
% Returns:
% value (float): Specific humidity of air [kg_w/kg_da] at a given temperature and pressure

% Constants
A = [-5.8002206e3, 1.3914993e0, -4.8640239e-2, 4.1764768e-5, -1.4452093e-8, 6.5459673e0];

% Change pressure from [bar] to [Pa]
p = p * 1e5;

% Saturated vapor pressure [Pa]
p_ws = exp( A(1)./T + A(2) + A(3) * T + A(4) * T.^2 + A(5) * T.^3 + A(6) * log(T) ); % Temperature in [K]

% Vapor pressure [Pa]
p_w = humidity_relative * p_ws * 1e-2;

% Specific humidity [kg_w/kg_da]
value = 0.622 * p_w ./ (p - p_w);
end

0 comments on commit 940431c

Please sign in to comment.