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

precipitable_water()   B

Complexity

Conditions 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 2
Metric Value
cc 1
c 5
b 0
f 2
dl 0
loc 38
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 . import mixing_ratio, saturation_vapor_pressure
8
from .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:
20
21
    \begin{align}
22
    \frac{1}{pg} \int\limits_0^d x \,dp
23
    \end{align}
24
25
    from [Tsonis2008]_, p. 170.
26
27
    Parameters
28
    ----------
29
    dewpt : array-like
30
        Atmospheric dewpoint profile
31
    p : array-like
32
        Atmospheric pressure profile
33
    top: `pint.Quantity`
34
        The top of the layer, specified in pressure.
35
36
    Returns
37
    -------
38
    `pint.Quantity'
39
        The precipitable water in the layer, in inches
40
41
    """
42
    pw_layer, dewpt_layer = get_layer(p, dewpt, depth=p[0] - top)
43
44
    w = mixing_ratio(saturation_vapor_pressure(dewpt_layer), pw_layer)
45
46
    sort_inds = np.argsort(pw_layer)
47
    pw_layer = pw_layer[sort_inds]
48
    w = w[sort_inds]
49
50
    pw = np.trapz(w, pw_layer) / (g * rho_l)
51
    pw = ((pw.magnitude * 100) * units('meter')).to('inches')
52
53
    return pw
54