Completed
Pull Request — master (#487)
by
unknown
54s
created

precipitable_water()   B

Complexity

Conditions 1

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
cc 1
c 4
b 0
f 2
dl 0
loc 41
rs 8.8571
1
# Copyright (c) 2008-2015 MetPy Developers.
2
# Distributed under the terms of the BSD 3-Clause License.
3
# SPDX-License-Identifier: BSD-3-Clause
4
"""Contains calculation of various derived indicies."""
5
import numpy as np
6
7
from ..calc import mixing_ratio, saturation_vapor_pressure
8
from ..calc.tools import get_layer
9
from ..constants import g, rho_l
10
from ..package_tools import Exporter
11
from ..units import units
12
13
exporter = Exporter(globals())
14
15
16
def precipitable_water(dewpt, p, top=400 * units('hPa')):
17
    r"""Calculate precipitable water through the depth of a sounding.
18
19
    Default layer depth is sfc-400 hPa. Formula used is from p. 170 in
20
    An Introduction to Atmospheric Thermodynamics by Anastasios A. Tsonis
21
    (2007):
22
23
    \begin{align}
24
    \frac{1}{pg} \int\limits_0^d x \,dp
25
    \end{align}
26
27
    Tsonis, A. A., 2008: An introduction to atmospheric thermodynamics.
28
    Cambridge Univ. Press, Cambridge.
29
30
    Parameters
31
    ----------
32
    dewpt : array-like
33
        Atmospheric dewpoint profile
34
    p : array-like
35
        Atmospheric pressure profile
36
    top: `pint.Quantity`
37
        The top of the layer, specified in pressure.
38
39
    Returns
40
    -------
41
    `pint.Quantity'
42
        The precipitable water in the layer, in inches
43
44
    """
45
    pw_layer, dewpt_layer = get_layer(p, dewpt, depth=p[0] - top)
46
47
    w = mixing_ratio(saturation_vapor_pressure(dewpt_layer), pw_layer)
48
49
    sort_inds = np.argsort(pw_layer)
50
    pw_layer = pw_layer[sort_inds]
51
    w = w[sort_inds]
52
53
    pw = pw = np.trapz(w, pw_layer) / (g * rho_l)
54
    pw = ((pw.magnitude * 100) * units('meter')).to('inches')
55
56
    return pw
57