Exemplo n.º 1
0
def test_precipitable_water():
    """Test precipitable water with observed sounding."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
    pw = precipitable_water(data.variables['dewpoint'][:], data.variables['pressure'][:])
    truth = (0.8899441949243486 * units('inches')).to('millimeters')
    assert_array_equal(pw, truth)
Exemplo n.º 2
0
def test_bulk_shear():
    """Test bulk shear with observed sounding."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
    u, v = bulk_shear(data.variables['pressure'][:], data.variables['u_wind'][:],
                      data.variables['v_wind'][:], heights=data.variables['height'][:],
                      depth=6000 * units('meter'))
    truth = [29.899581266946115, -14.389225800205509] * units('knots')
    assert_almost_equal(u.to('knots'), truth[0], 8)
    assert_almost_equal(v.to('knots'), truth[1], 8)
Exemplo n.º 3
0
def test_bunkers_motion():
    """Test Bunkers storm motion with observed sounding."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
    motion = concatenate(bunkers_storm_motion(data.variables['pressure'][:],
                         data.variables['u_wind'][:], data.variables['v_wind'][:],
                         data.variables['height'][:]))
    truth = [1.4537892577864744, 2.0169333025630616, 10.587950761120482, 13.915130377372801,
             6.0208700094534775, 7.9660318399679308] * units('m/s')
    assert_almost_equal(motion.flatten(), truth, 8)
Exemplo n.º 4
0
def test_bulk_shear_elevated():
    """Test bulk shear with observed sounding and a base above the surface."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
    u, v = bulk_shear(data.variables['pressure'][:], data.variables['u_wind'][:],
                      data.variables['v_wind'][:], heights=data.variables['height'][:],
                      bottom=data.variables['height'][0] + 3000 * units('meter'),
                      depth=3000 * units('meter'))
    truth = [0.9655943923302139, -3.8405428777944466] * units('m/s')
    assert_almost_equal(u, truth[0], 8)
    assert_almost_equal(v, truth[1], 8)
Exemplo n.º 5
0
def test_mean_pressure_weighted():
    """Test pressure-weighted mean wind function with vertical interpolation."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
    u, v = mean_pressure_weighted(data.variables['pressure'][:],
                                  data.variables['u_wind'][:],
                                  data.variables['v_wind'][:],
                                  heights=data.variables['height'][:],
                                  depth=6000 * units('meter'))
    assert_almost_equal(u, 6.0208700094534775 * units('m/s'), 7)
    assert_almost_equal(v, 7.966031839967931 * units('m/s'), 7)
Exemplo n.º 6
0
def test_mean_pressure_weighted_elevated():
    """Test pressure-weighted mean wind function with a base above the surface."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC', source='wyoming')
    u, v = mean_pressure_weighted(data.variables['pressure'][:],
                                  data.variables['u_wind'][:],
                                  data.variables['v_wind'][:],
                                  heights=data.variables['height'][:],
                                  depth=3000 * units('meter'),
                                  bottom=data.variables['height'][0] + 3000 * units('meter'))
    assert_almost_equal(u, 8.270829843626476 * units('m/s'), 7)
    assert_almost_equal(v, 1.7392601775853547 * units('m/s'), 7)
Exemplo n.º 7
0
def test_precipitable_water_no_bounds():
    """Test precipitable water with observed sounding and no bounds given."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0),
                                  'DDC',
                                  source='wyoming')
    dewpoint = data.variables['dewpoint'][:]
    pressure = data.variables['pressure'][:]
    inds = pressure >= 400 * units.hPa
    pw = precipitable_water(dewpoint[inds], pressure[inds])
    truth = (0.8899441949243486 * units('inches')).to('millimeters')
    assert_array_equal(pw, truth)
Exemplo n.º 8
0
def test_high_alt_wyoming():
    """Test Wyoming data that starts at pressure less than 925 hPa."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2010, 12, 9, 12),
                                  'BOI',
                                  source='wyoming')

    assert_almost_equal(data.variables['pressure'][2], 890.0 * units('hPa'), 2)
    assert_almost_equal(data.variables['temperature'][2], 5.4 * units.degC, 2)
    assert_almost_equal(data.variables['dewpoint'][2], 3.9 * units.degC, 2)
    assert_almost_equal(data.variables['u_wind'][2], -0.42 * units.knot, 2)
    assert_almost_equal(data.variables['v_wind'][2], 5.99 * units.knot, 2)
Exemplo n.º 9
0
def test_iastate():
    """Test that we properly parse data from Iowa State archive."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 7, 30, 12),
                                  'KDEN',
                                  source='iastate')

    assert_almost_equal(data.variables['pressure'][3], 838.0 * units('hPa'), 2)
    assert_almost_equal(data.variables['temperature'][3], 17.0 * units.degC, 2)
    assert_almost_equal(data.variables['dewpoint'][3], 15.2 * units.degC, 2)
    assert_almost_equal(data.variables['u_wind'][3], 1.72 * units.knot, 2)
    assert_almost_equal(data.variables['v_wind'][3], 2.46 * units.knot, 2)
Exemplo n.º 10
0
def test_wyoming():
    """Test that we are properly parsing data from the wyoming archive."""
    with UseSampleData():
        data = get_upper_air_data(datetime(1999, 5, 4, 0),
                                  'OUN',
                                  source='wyoming')

    assert_almost_equal(data.variables['pressure'][5], 867.9 * units('hPa'), 2)
    assert_almost_equal(data.variables['temperature'][5], 17.4 * units.degC, 2)
    assert_almost_equal(data.variables['dewpoint'][5], 14.3 * units.degC, 2)
    assert_almost_equal(data.variables['u_wind'][5], 6.60 * units.knot, 2)
    assert_almost_equal(data.variables['v_wind'][5], 37.42 * units.knot, 2)
Exemplo n.º 11
0
def test_bulk_shear_no_depth():
    """Test bulk shear with observed sounding and no depth given. Issue #568."""
    with UseSampleData():
        data = get_upper_air_data(datetime(2016, 5, 22, 0),
                                  'DDC',
                                  source='wyoming')
    u, v = bulk_shear(data.variables['pressure'][:],
                      data.variables['u_wind'][:],
                      data.variables['v_wind'][:],
                      heights=data.variables['height'][:])
    truth = [20.225018939, 22.602359692] * units('knots')
    assert_almost_equal(u.to('knots'), truth[0], 8)
    assert_almost_equal(v.to('knots'), truth[1], 8)
Exemplo n.º 12
0
import matplotlib.pyplot as plt
import numpy as np

from metpy.calc import resample_nn_1d
from metpy.io import get_upper_air_data
from metpy.io.upperair import UseSampleData
from metpy.plots import SkewT
from metpy.units import units

###########################################

# Change default to be better for skew-T
plt.rcParams['figure.figsize'] = (9, 9)

with UseSampleData():  # Only needed to use our local sample data
    # Download and parse the data
    dataset = get_upper_air_data(datetime(2013, 1, 20, 12), 'OUN')

p = dataset.variables['pressure'][:]
T = dataset.variables['temperature'][:]
Td = dataset.variables['dewpoint'][:]
u = dataset.variables['u_wind'][:]
v = dataset.variables['v_wind'][:]

###########################################
skew = SkewT()

# Plot the data using normal plotting functions, in this case using
# log scaling in Y, as dictated by the typical meteorological plot
skew.plot(p, T, 'r')