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

precipitable_water()   B

Complexity

Conditions 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
dl 0
loc 37
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
6
from ..calc import mixing_ratio, saturation_vapor_pressure
7
from ..calc.tools import get_layer
8
from ..constants import g, rho_l
9
from ..package_tools import Exporter
10
from ..units import units
11
12
exporter = Exporter(globals())
13
14
15
def precipitable_water(dewpt, p, top=400 * units('hPa')):
16
    # Implementation of integral calculation based partly on SRH integral
17
    # approximation, as found in Markowski and Richardson (2013) or in
18
    # SharpPy
19
    r"""Calculate precipitable water through the depth of a sounding.
20
21
    Default layer depth is sfc-400 hPa. Formula used is from the AMS glossary:
22
23
    \begin{align}
24
    \frac{1}{pg} \int\limits_0^d x \,dp
25
    \end{align}
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 = get_layer(p, dewpt, depth=p[0] - top)
43
44
    w = mixing_ratio(saturation_vapor_pressure(pw_layer[1]), pw_layer[0])
45
46
    pw = (((w[:-1].magnitude + w[1:].magnitude) / 2.) *
47
          (pw_layer[0][:-1].magnitude - pw_layer[0][1:].magnitude) *
48
          (1. / (g * rho_l))).sum()
49
    pw = ((pw.magnitude * 100) * units('meter')).to('inches')
50
51
    return pw
52