Completed
Pull Request — master (#487)
by
unknown
01:16
created

precipitable_water()   B

Complexity

Conditions 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 0 Features 2
Metric Value
cc 1
c 8
b 0
f 2
dl 0
loc 39
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 .thermo 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 check_units, units
12
13
exporter = Exporter(globals())
14
15
16
@exporter.export
17
@check_units('[temperature]', '[pressure]', '[pressure]')
18
def precipitable_water(dewpt, p, top=400 * units('hPa')):
19
    r"""Calculate precipitable water through the depth of a sounding.
20
21
    Default layer depth is sfc-400 hPa. Formula used is:
22
23
    \begin{align}
24
    \frac{1}{pg} \int\limits_0^d x \,dp
25
    \end{align}
26
27
    from [Tsonis2008]_, p. 170.
28
29
    Parameters
30
    ----------
31
    dewpt : array-like
32
        Atmospheric dewpoint profile
33
    p : array-like
34
        Atmospheric pressure profile
35
    top: `pint.Quantity`
36
        The top of the layer, specified in pressure.
37
38
    Returns
39
    -------
40
    `pint.Quantity'
41
        The precipitable water in the layer, in inches
42
43
    """
44
    pres_layer, dewpt_layer = get_layer(p, dewpt, depth=p[0] - top)
45
46
    w = mixing_ratio(saturation_vapor_pressure(dewpt_layer), pres_layer)
47
48
    sort_inds = np.argsort(pres_layer)
49
    pres_layer = pres_layer[sort_inds]
50
    w = w[sort_inds]
51
52
    pw = (np.trapz(w.magnitude, pres_layer.to('pascal').magnitude) / (g * rho_l))
53
54
    return (pw * (units('kilogram') / units('m*s^2'))).to('millimeters')
55