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

test_mean_wind_pressure_weighted_elevated()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 13
loc 13
rs 9.4285
1
# Copyright (c) 2008-2017 MetPy Developers.
2
# Distributed under the terms of the BSD 3-Clause License.
3
# SPDX-License-Identifier: BSD-3-Clause
4
"""Test the `indices` module."""
5
6
from datetime import datetime
7
8
from metpy.calc import mean_wind_pressure_weighted, precipitable_water
9
from metpy.io import get_upper_air_data
10
from metpy.io.upperair import UseSampleData
11
from metpy.testing import assert_array_equal
12
from metpy.units import units
13
14
15
def test_precipitable_water():
16
    """Test precipitable water with observed sounding."""
17
    with UseSampleData():
18
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
19
    pw = precipitable_water(data.variables['dewpoint'][:], data.variables['pressure'][:])
20
    truth = (0.8899441949243486 * units('inches')).to('millimeters')
21
    assert_array_equal(pw, truth)
22
23
24 View Code Duplication
def test_mean_wind_pressure_weighted():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
    """Test pressure-weighted mean wind function with only obs."""
26
    with UseSampleData():
27
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
28
    mean6 = mean_wind_pressure_weighted(data.variables['u_wind'][:],
29
                                        data.variables['v_wind'][:],
30
                                        data.variables['pressure'][:],
31
                                        data.variables['height'][:],
32
                                        depth=6000 * units('meter'), obs_only=True)
33
    truth = [6.312839043118274, 7.97164506356538] * units('m/s')
34
    assert_array_equal(mean6[0], truth[0])
35
    assert_array_equal(mean6[1], truth[1])
36
37
38 View Code Duplication
def test_mean_wind_pressure_weighted_interp():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
39
    """Test pressure-weighted mean wind function with vertical interpolation."""
40
    with UseSampleData():
41
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
42
    mean6 = mean_wind_pressure_weighted(data.variables['u_wind'][:],
43
                                        data.variables['v_wind'][:],
44
                                        data.variables['pressure'][:],
45
                                        data.variables['height'][:],
46
                                        depth=6000 * units('meter'))
47
    truth = [6.0208700094534775, 7.966031839967931] * units('m/s')
48
    assert_array_equal(mean6[0], truth[0])
49
    assert_array_equal(mean6[1], truth[1])
50
51
52 View Code Duplication
def test_mean_wind_pressure_weighted_elevated():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
53
    """Test pressure-weighted mean wind function with a base above the surface."""
54
    with UseSampleData():
55
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
56
    mean6 = mean_wind_pressure_weighted(data.variables['u_wind'][:],
57
                                        data.variables['v_wind'][:],
58
                                        data.variables['pressure'][:],
59
                                        data.variables['height'][:],
60
                                        depth=3000 * units('meter'),
61
                                        bottom=3000 * units('meter'))
62
    truth = [8.270829843626476, 1.7392601775853547] * units('m/s')
63
    assert_array_equal(mean6[0], truth[0])
64
    assert_array_equal(mean6[1], truth[1])
65