Skip to content

Air thermo

air_density

air_density(t, p, rh)

Moist air density given temperature, pressure, and relative humidity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
rh Numeric

Relative humidity in %

required

Returns:

Type Description
Numeric

Moist air density in kg/m^3

Source code in src/pytoast/utils/air_thermo.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def air_density(t: Numeric, p: Numeric, rh: Numeric) -> Numeric:
    """Moist air density given temperature, pressure, and relative humidity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    rh : Numeric
        Relative humidity in %

    Returns
    -------
    Numeric
        Moist air density in kg/m^3
    """
    e = water_vapor_pressure(t, p, rh)
    p_dry = p - e
    rho_air = (p_mbar2pa(p_dry) * m_a + p_mbar2pa(e) * m_v) / (R * t_c2kelvin(t))
    return rho_air

dry_adiabatic_lapse_rate

dry_adiabatic_lapse_rate(t, g_lat=GRAVITATIONAL_ACCELERATION)

Adiabatic lapse rate of dry air.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
g_lat Numeric

Gravitational acceleration in m/s^2. Defaults to 9.81 if not provided

GRAVITATIONAL_ACCELERATION

Returns:

Type Description
Numeric

Lapse rate in K / m

Source code in src/pytoast/utils/air_thermo.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
def dry_adiabatic_lapse_rate(t: Numeric, g_lat: Numeric = g) -> Numeric:
    """Adiabatic lapse rate of dry air.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    g_lat : Numeric, optional
        Gravitational acceleration in m/s^2. Defaults to 9.81 if not provided

    Returns
    -------
    Numeric
        Lapse rate in K / m
    """
    cp = specific_heat(t)
    return g_lat / cp

dry_air_density

dry_air_density(t, p)

Dry air density given temperature and pressure.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required

Returns:

Type Description
Numeric

Dry air density in kg/m^3

Source code in src/pytoast/utils/air_thermo.py
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
def dry_air_density(t: Numeric, p: Numeric) -> Numeric:
    """Dry air density given temperature and pressure.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar

    Returns
    -------
    Numeric
        Dry air density in kg/m^3
    """
    rho_air_dry = p_mbar2pa(p) / (R_a * t_c2kelvin(t))
    return rho_air_dry

kinematic_viscosity

kinematic_viscosity(t)

Kinematic viscosity of air.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required

Returns:

Type Description
Numeric

Kinematic viscosity in m^2/s

Source code in src/pytoast/utils/air_thermo.py
353
354
355
356
357
358
359
360
361
362
363
364
365
366
def kinematic_viscosity(t: Numeric) -> Numeric:
    """Kinematic viscosity of air.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius

    Returns
    -------
    Numeric
        Kinematic viscosity in m^2/s
    """
    return 1.326e-5 * (1 + 6.542e-3 * t + 8.301e-6 * t**2 - 4.840e-9 * t**3)

latent_heat_of_vaporization

latent_heat_of_vaporization(t)

Latent heat of vaporization.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required

Returns:

Type Description
Numeric

Latent heat of vaporization in J/kg

Source code in src/pytoast/utils/air_thermo.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
def latent_heat_of_vaporization(t: Numeric) -> Numeric:
    """Latent heat of vaporization.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius

    Returns
    -------
    Numeric
        Latent heat of vaporization in J/kg
    """
    return (2.501 - 0.00237 * t) * 1e6

mixing_ratio

mixing_ratio(t, p, rh, sp=None)

Water vapor mixing ratio given temperature, pressure, relative humidity, and (optionally) seawater salinity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
rh Numeric

Relative humidity in %

required
sp Numeric

If specified, the saturation vapor pressure is corrected to its "above seawater" value using salinity in PSU

None

Returns:

Type Description
Numeric

Mixing ratio in kg/kg

Source code in src/pytoast/utils/air_thermo.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def mixing_ratio(t: Numeric, p: Numeric, rh: Numeric, sp: Numeric | None = None) -> Numeric:
    """Water vapor mixing ratio given temperature, pressure, relative humidity,
    and (optionally) seawater salinity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    rh : Numeric
        Relative humidity in %
    sp : Numeric, optional
        If specified, the saturation vapor pressure is corrected to its "above seawater"
        value using salinity in PSU

    Returns
    -------
    Numeric
        Mixing ratio in kg/kg
    """
    e = water_vapor_pressure(t, p, rh, sp)
    return 0.622 * e / (p - e)

p_mbar2pa

p_mbar2pa(p)

Convert pressure from millibar to Pascal.

Source code in src/pytoast/utils/air_thermo.py
33
34
35
def p_mbar2pa(p: Numeric) -> Numeric:
    """Convert pressure from millibar to Pascal."""
    return p * 100

potential_temperature

potential_temperature(t, z)

Potential temperature, i.e. the temperature an air parcel would have if brought adiabatically to a reference level at the surface.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
z Numeric

Height above the surface in meters.

required

Returns:

Type Description
Numeric

Potential temperature in Celcius

Source code in src/pytoast/utils/air_thermo.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
def potential_temperature(t: Numeric, z: Numeric) -> Numeric:
    """Potential temperature, i.e. the temperature an air parcel would have if
    brought adiabatically to a reference level at the surface.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    z : Numeric
        Height above the surface in meters.

    Returns
    -------
    Numeric
        Potential temperature in Celcius
    """
    cp = specific_heat(t)
    theta = t + (g / cp) * z
    return theta

relative_humidity_from_specific_humidity

relative_humidity_from_specific_humidity(t, p, q, t_freeze=None)

Relative humidity (%) given temperature, pressure, specific humidity, and (optionally) freezing temperature

t : Numeric Air temperature in Celcius p : Numeric Atmospheric pressure in millibar q : Numeric Specific humidity in kg/kg t_freeze: Numeric, optional If specific, the saturation vapor pressure is corrected to account for ice conditions

Returns:

Type Description
Numeric

Relative humidity in %

Source code in src/pytoast/utils/air_thermo.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
def relative_humidity_from_specific_humidity(
    t: Numeric, p: Numeric, q: Numeric, t_freeze: Numeric | None = None
) -> Numeric:
    """Relative humidity (%) given temperature, pressure, specific humidity, and (optionally) freezing temperature

    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    q : Numeric
        Specific humidity in kg/kg
    t_freeze: Numeric, optional
        If specific, the saturation vapor pressure is corrected to account for ice conditions

    Returns
    -------
    Numeric
        Relative humidity in %

    """
    e_s = saturation_vapor_pressure(t, p, t_freeze=t_freeze)
    vapor_pressure = q * p / (0.622 + 0.378 * q)
    return 100 * vapor_pressure / e_s

saturation_specific_humidity

saturation_specific_humidity(t, p, sp=None, t_freeze=None)

Specific humidity given temperature, pressure, relative humidity, and (optionally) seawater salinity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
sp Numeric

If specified, the saturation vapor pressure is corrected to its "above seawater" value using salinity in PSU

None
t_freeze Numeric | None

If specific, the saturation vapor pressure is corrected to account for ice conditions

None

Returns:

Type Description
Numeric

Specific humidity in kg/kg

Source code in src/pytoast/utils/air_thermo.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def saturation_specific_humidity(
    t: Numeric, p: Numeric, sp: Numeric | None = None, t_freeze: Numeric | None = None
) -> Numeric:
    """Specific humidity given temperature, pressure, relative humidity, and
    (optionally) seawater salinity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    sp : Numeric, optional
        If specified, the saturation vapor pressure is corrected to its "above seawater"
        value using salinity in PSU
    t_freeze: Numeric, optional
        If specific, the saturation vapor pressure is corrected to account for ice conditions

    Returns
    -------
    Numeric
        Specific humidity in kg/kg
    """
    e_s = saturation_vapor_pressure(t, p, sp, t_freeze)
    q_s = 0.622 * e_s / (p - 0.378 * e_s)
    return q_s

saturation_vapor_pressure

saturation_vapor_pressure(t, p, sp=None, t_freeze=None)

Saturation vapor pressure given pressure, temperature, and (optionally) seawater salinity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
sp Numeric

If specified, the saturation vapor pressure is corrected to its "above seawater" value using salinity in PSU

None
t_freeze Numeric | None

If specified, the saturation vapor pressure is corrected to account for ice conditions

None

Returns:

Type Description
Numeric

Saturation vapor pressure in millibar

Source code in src/pytoast/utils/air_thermo.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def saturation_vapor_pressure(
    t: Numeric, p: Numeric, sp: Numeric | None = None, t_freeze: Numeric | None = None
) -> Numeric:
    """Saturation vapor pressure given pressure, temperature, and (optionally)
    seawater salinity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    sp : Numeric, optional
        If specified, the saturation vapor pressure is corrected to its "above seawater"
        value using salinity in PSU
    t_freeze: Numeric, optional
        If specified, the saturation vapor pressure is corrected to account for ice conditions

    Returns
    -------
    Numeric
        Saturation vapor pressure in millibar
    """
    e_s = 6.1121 * (1.0007 + 3.46e-6 * p) * np.exp(17.502 * t / (240.97 + t))

    if t_freeze is not None:
        t = np.asarray(t, dtype=float)
        p = np.asarray(p, dtype=float)
        e_s = np.asarray(e_s, dtype=float)
        t_freeze = np.asarray(t_freeze, dtype=float)
        ice_idx = t < t_freeze
        if np.any(ice_idx):
            e_s[ice_idx] = (
                6.1115 * np.exp(22.452 * t[ice_idx] / (t[ice_idx] + 272.55)) * (1.0003 + 4.18e-6 * p[ice_idx])
            )

    if sp is not None:
        return e_s * (1 - 5.37e-04 * sp)
    else:
        return e_s

specific_heat

specific_heat(t)

Specific heat capacity of air at constant pressure.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required

Returns:

Type Description
Numeric

Specific heat capacity in J/(kg K)

Source code in src/pytoast/utils/air_thermo.py
302
303
304
305
306
307
308
309
310
311
312
313
314
315
def specific_heat(t: Numeric) -> Numeric:
    """Specific heat capacity of air at constant pressure.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius

    Returns
    -------
    Numeric
        Specific heat capacity in J/(kg K)
    """
    return 1005.6 + 0.0172 * t + 0.000392 * t**2

specific_humidity

specific_humidity(t, p, rh, sp=None)

Specific humidity given temperature, pressure, relative humidity, and (optionally) seawater salinity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
rh Numeric

Relative humidity in %

required
sp Numeric

If specified, the saturation vapor pressure is corrected to its "above seawater" value using salinity in PSU

None

Returns:

Type Description
Numeric

Specific humidity in kg/kg

Source code in src/pytoast/utils/air_thermo.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def specific_humidity(t: Numeric, p: Numeric, rh: Numeric, sp: Numeric | None = None) -> Numeric:
    """Specific humidity given temperature, pressure, relative humidity, and
    (optionally) seawater salinity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    rh : Numeric
        Relative humidity in %
    sp : Numeric, optional
        If specified, the saturation vapor pressure is corrected to its "above seawater"
        value using salinity in PSU

    Returns
    -------
    Numeric
        Specific humidity in kg/kg
    """
    e = water_vapor_pressure(t, p, rh, sp)
    q = 0.622 * e / (p - 0.378 * e)
    return q

t_c2kelvin

t_c2kelvin(t)

Convert temperature from Celsius to Kelvin.

Source code in src/pytoast/utils/air_thermo.py
28
29
30
def t_c2kelvin(t: Numeric) -> Numeric:
    """Convert temperature from Celsius to Kelvin."""
    return t + T0

virtual_temperature

virtual_temperature(t, p, rh, sp=None)

Virtual temperature given temperature, pressure, relative humidity, and (optionally) seawater salinity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
rh Numeric

Relative humidity in %

required
sp Numeric

If specified, the saturation vapor pressure is corrected to its "above seawater" value using salinity in PSU

None

Returns:

Type Description
Numeric

Virtual temperature in Celcius

Source code in src/pytoast/utils/air_thermo.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
def virtual_temperature(t: Numeric, p: Numeric, rh: Numeric, sp: Numeric | None = None) -> Numeric:
    """Virtual temperature given temperature, pressure, relative humidity, and
    (optionally) seawater salinity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    rh : Numeric
        Relative humidity in %
    sp : Numeric, optional
        If specified, the saturation vapor pressure is corrected to its "above seawater"
        value using salinity in PSU

    Returns
    -------
    Numeric
        Virtual temperature in Celcius
    """
    q = specific_humidity(t, p, rh, sp)
    t_v = t * (1 + 0.61 * q)
    return t_v

water_vapor_density

water_vapor_density(t, p, rh, sp=None)

Water vapor density given temperature, pressure, relative humidity, and (optionally) seawater salinity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
rh Numeric

Relative humidity in %

required
sp Numeric

If specified, the saturation vapor pressure is corrected to its "above seawater" value using salinity in PSU

None

Returns:

Type Description
Numeric

Water vapor density in kg/m^3

Source code in src/pytoast/utils/air_thermo.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def water_vapor_density(t: Numeric, p: Numeric, rh: Numeric, sp: Numeric | None = None) -> Numeric:
    """Water vapor density given temperature, pressure, relative humidity, and
    (optionally) seawater salinity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    rh : Numeric
        Relative humidity in %
    sp : Numeric, optional
        If specified, the saturation vapor pressure is corrected to its "above seawater"
        value using salinity in PSU

    Returns
    -------
    Numeric
        Water vapor density in kg/m^3
    """
    e = water_vapor_pressure(t, p, rh, sp)
    return 100 * e / (R_v * t_c2kelvin(t))

water_vapor_pressure

water_vapor_pressure(t, p, rh, sp=None)

Water vapor pressure given temperature, pressure, relative humidity, and (optionally) seawater salinity.

Parameters:

Name Type Description Default
t Numeric

Air temperature in Celcius

required
p Numeric

Atmospheric pressure in millibar

required
rh Numeric

Relative humidity in %

required
sp Numeric

If specified, the saturation vapor pressure is corrected to its "above seawater" value using salinity in PSU

None

Returns:

Type Description
Numeric

Water vapor pressure in millibar

Source code in src/pytoast/utils/air_thermo.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def water_vapor_pressure(t: Numeric, p: Numeric, rh: Numeric, sp: Numeric | None = None) -> Numeric:
    """Water vapor pressure given temperature, pressure, relative humidity, and
    (optionally) seawater salinity.

    Parameters
    ----------
    t : Numeric
        Air temperature in Celcius
    p : Numeric
        Atmospheric pressure in millibar
    rh : Numeric
        Relative humidity in %
    sp : Numeric, optional
        If specified, the saturation vapor pressure is corrected to its "above seawater"
        value using salinity in PSU

    Returns
    -------
    Numeric
        Water vapor pressure in millibar
    """
    e_s = saturation_vapor_pressure(t, p, sp)
    return (rh / 100) * e_s