Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_precipitable_water():
"""Test precipitable water with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
pw = precipitable_water(data['dewpoint'], data['pressure'],
top=400 * units.hPa)
truth = (0.8899441949243486 * units('inches')).to('millimeters')
assert_array_equal(pw, truth)
def test_delete_masked_points():
"""Test deleting masked points."""
a = ma.masked_array(np.arange(5), mask=[False, True, False, False, False])
b = ma.masked_array(np.arange(5), mask=[False, False, False, True, False])
expected = np.array([0, 2, 4])
a, b = _delete_masked_points(a, b)
assert_array_equal(a, expected)
assert_array_equal(b, expected)
def test_geostrophic_3d():
"""Test geostrophic wind calculation with 3D array."""
z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100.
# Using g as the value for f allows it to cancel out
z3d = np.dstack((z, z)) * units.meter
ug, vg = geostrophic_wind(z3d, g.magnitude / units.sec,
100. * units.meter, 100. * units.meter, dim_order='xy')
true_u = np.array([[-2, 0, 2]] * 3) * units('m/s')
true_v = -true_u.T
true_u = concatenate((true_u[..., None], true_u[..., None]), axis=2)
true_v = concatenate((true_v[..., None], true_v[..., None]), axis=2)
assert_array_equal(ug, true_u)
assert_array_equal(vg, true_v)
def test_geostrophic_geopotential():
"""Test geostrophic wind calculation with geopotential."""
z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100. * units('m^2/s^2')
ug, vg = geostrophic_wind(z, 1 / units.sec, 100. * units.meter, 100. * units.meter,
dim_order='xy')
true_u = np.array([[-2, 0, 2]] * 3) * units('m/s')
true_v = -true_u.T
assert_array_equal(ug, true_u)
assert_array_equal(vg, true_v)
def test_ageostrophic_geopotential_future():
"""Test ageostrophic wind calculation with future input variable order."""
z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100. * units('m^2/s^2')
u = v = np.array([[0, 0, 0]] * 3) * units('m/s')
uag, vag = ageostrophic_wind_future(z, u, v, 1 / units.sec, 100. * units.meter,
100. * units.meter, dim_order='xy')
u_true = np.array([[2, 0, -2]] * 3) * units('m/s')
v_true = -u_true.T
assert_array_equal(uag, u_true)
assert_array_equal(vag, v_true)
def test_stretching_deformation_asym():
"""Test stretching deformation calculation with a complicated field."""
u = np.array([[2, 4, 8], [0, 2, 2], [4, 6, 8]]) * units('m/s')
v = np.array([[6, 4, 8], [2, 6, 0], [2, 2, 6]]) * units('m/s')
st = stretching_deformation(u, v, 1 * units.meters, 2 * units.meters, dim_order='yx')
true_st = np.array([[4., 0.5, 12.5], [4., 1.5, -0.5], [1., 5.5, -4.5]]) / units.sec
assert_array_equal(st, true_st)
# Now try for yx ordered
st = stretching_deformation(u.T, v.T, 1 * units.meters, 2 * units.meters,
dim_order='xy')
assert_array_equal(st, true_st.T)
def test_heat_index_invalid():
"""Test heat index for values that should be masked."""
temp = np.array([80, 88, 92, 79, 30, 81]) * units.degF
rh = np.array([40, 39, 2, 70, 50, 39]) * units.percent
hi = heat_index(temp, rh)
mask = np.array([False, False, False, True, True, False])
assert_array_equal(hi.mask, mask)
def test_angle_to_direction_full():
"""Test the `full` keyword argument, expecting unabbrieviated output."""
expected_dirs = [
'North', 'North North East', 'North East', 'East North East',
'East', 'East South East', 'South East', 'South South East',
'South', 'South South West', 'South West', 'West South West',
'West', 'West North West', 'North West', 'North North West'
]
output_dirs = angle_to_direction(FULL_CIRCLE_DEGREES, full=True)
assert_array_equal(output_dirs, expected_dirs)
def test_angle_to_direction_level_3():
"""Test array of angles in degree."""
expected_dirs = DIR_STRS[:-1] # UND at -1
output_dirs = angle_to_direction(FULL_CIRCLE_DEGREES, level=3)
assert_array_equal(output_dirs, expected_dirs)
def test_no_ageostrophic_geopotential_future():
"""Test the updated ageostrophic wind function."""
z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100. * units('m^2/s^2')
u = np.array([[-2, 0, 2]] * 3) * units('m/s')
v = -u.T
uag, vag = ageostrophic_wind_future(z, u, v, 1 / units.sec, 100. * units.meter,
100. * units.meter, dim_order='xy')
true = np.array([[0, 0, 0]] * 3) * units('m/s')
assert_array_equal(uag, true)
assert_array_equal(vag, true)