|
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 (bulk_shear, bunkers_storm_motion, mean_pressure_weighted, |
|
9
|
|
|
precipitable_water) |
|
10
|
|
|
from metpy.io import get_upper_air_data |
|
11
|
|
|
from metpy.io.upperair import UseSampleData |
|
12
|
|
|
from metpy.testing import assert_almost_equal, assert_array_equal |
|
13
|
|
|
from metpy.units import concatenate, units |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
def test_precipitable_water(): |
|
17
|
|
|
"""Test precipitable water with observed sounding.""" |
|
18
|
|
|
with UseSampleData(): |
|
19
|
|
|
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming') |
|
20
|
|
|
pw = precipitable_water(data.variables['dewpoint'][:], data.variables['pressure'][:]) |
|
21
|
|
|
truth = (0.8899441949243486 * units('inches')).to('millimeters') |
|
22
|
|
|
assert_array_equal(pw, truth) |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
def test_mean_pressure_weighted(): |
|
26
|
|
|
"""Test pressure-weighted mean wind function with vertical interpolation.""" |
|
27
|
|
|
with UseSampleData(): |
|
28
|
|
|
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming') |
|
29
|
|
|
u, v = mean_pressure_weighted(data.variables['pressure'][:], |
|
30
|
|
|
data.variables['u_wind'][:], |
|
31
|
|
|
data.variables['v_wind'][:], |
|
32
|
|
|
heights=data.variables['height'][:], |
|
33
|
|
|
depth=6000 * units('meter')) |
|
34
|
|
|
assert_almost_equal(u, 6.0208700094534775 * units('m/s'), 7) |
|
35
|
|
|
assert_almost_equal(v, 7.966031839967931 * units('m/s'), 7) |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
View Code Duplication |
def test_mean_pressure_weighted_elevated(): |
|
|
|
|
|
|
39
|
|
|
"""Test pressure-weighted mean wind function with a base above the surface.""" |
|
40
|
|
|
with UseSampleData(): |
|
41
|
|
|
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming') |
|
42
|
|
|
u, v = mean_pressure_weighted(data.variables['pressure'][:], |
|
43
|
|
|
data.variables['u_wind'][:], |
|
44
|
|
|
data.variables['v_wind'][:], |
|
45
|
|
|
heights=data.variables['height'][:], |
|
46
|
|
|
depth=3000 * units('meter'), |
|
47
|
|
|
bottom=data.variables['height'][0] + 3000 * units('meter')) |
|
48
|
|
|
assert_almost_equal(u, 8.270829843626476 * units('m/s'), 7) |
|
49
|
|
|
assert_almost_equal(v, 1.7392601775853547 * units('m/s'), 7) |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
def test_bunkers_motion(): |
|
53
|
|
|
"""Test Bunkers storm motion with observed sounding.""" |
|
54
|
|
|
with UseSampleData(): |
|
55
|
|
|
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming') |
|
56
|
|
|
motion = concatenate(bunkers_storm_motion(data.variables['pressure'][:], |
|
57
|
|
|
data.variables['u_wind'][:], data.variables['v_wind'][:], |
|
58
|
|
|
data.variables['height'][:])) |
|
59
|
|
|
truth = [1.4537892577864744, 2.0169333025630616, 10.587950761120482, 13.915130377372801, |
|
60
|
|
|
6.0208700094534775, 7.9660318399679308] * units('m/s') |
|
61
|
|
|
assert_almost_equal(motion.flatten(), truth, 8) |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
View Code Duplication |
def test_bulk_shear(): |
|
|
|
|
|
|
65
|
|
|
"""Test bulk shear with observed sounding.""" |
|
66
|
|
|
with UseSampleData(): |
|
67
|
|
|
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming') |
|
68
|
|
|
u, v = bulk_shear(data.variables['pressure'][:], data.variables['u_wind'][:], |
|
69
|
|
|
data.variables['v_wind'][:], heights=data.variables['height'][:], |
|
70
|
|
|
depth=6000 * units('meter')) |
|
71
|
|
|
truth = [29.899581266946115, -14.389225800205509] * units('knots') |
|
72
|
|
|
assert_almost_equal(u.to('knots'), truth[0], 8) |
|
73
|
|
|
assert_almost_equal(v.to('knots'), truth[1], 8) |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
def test_bulk_shear_elevated(): |
|
77
|
|
|
"""Test bulk shear with observed sounding and a base above the surface.""" |
|
78
|
|
|
with UseSampleData(): |
|
79
|
|
|
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming') |
|
80
|
|
|
u, v = bulk_shear(data.variables['pressure'][:], data.variables['u_wind'][:], |
|
81
|
|
|
data.variables['v_wind'][:], heights=data.variables['height'][:], |
|
82
|
|
|
bottom=data.variables['height'][0] + 3000 * units('meter'), |
|
83
|
|
|
depth=3000 * units('meter')) |
|
84
|
|
|
truth = [0.9655943923302139, -3.8405428777944466] * units('m/s') |
|
85
|
|
|
assert_almost_equal(u, truth[0], 8) |
|
86
|
|
|
assert_almost_equal(v, truth[1], 8) |
|
87
|
|
|
|