Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ combine_as_imports = true
combine_star = true

[tool.pytest.ini_options]
markers = "xfail_dask: marks tests as expected to fail with Dask arrays"
markers = [
"xfail_dask: marks tests as expected to fail with Dask arrays",
"network: make tests requiring access to the internet",
]
norecursedirs = "build docs .idea"
doctest_optionflags = "NORMALIZE_WHITESPACE"
mpl-results-path = "test_output"
Expand Down
1 change: 1 addition & 0 deletions tests/calc/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ def test_altimeter_to_sea_level_pressure_hpa(array_type):
assert_array_almost_equal(res, truth, 3)


@pytest.mark.network
def test_zoom_xarray():
"""Test zoom_xarray on 2D DataArray."""
data = xr.open_dataset(get_test_data('GFS_test.nc', False))
Expand Down
3 changes: 3 additions & 0 deletions tests/calc/test_calc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ def test_remove_nans():
assert_almost_equal(y_expected, y_test, 0)


@pytest.mark.network
@pytest.mark.parametrize('subset', (False, True))
@pytest.mark.parametrize('datafile, assign_lat_lon, no_crs, transpose',
[('GFS_test.nc', False, False, False),
Expand Down Expand Up @@ -1583,6 +1584,7 @@ def test_peak_persistence_minima(peak_data):
assert per == [((2, 3), np.inf), ((3, 0), 2)]


@pytest.mark.network
def test_find_peaks(peak_data):
"""Test find_peaks correctly identifies peaks."""
data = xr.open_dataset(get_test_data('GFS_test.nc', as_file_obj=False))
Expand All @@ -1596,6 +1598,7 @@ def test_find_peaks(peak_data):
assert_array_almost_equal(hgt.metpy.x[xind], [3.665191, 5.235988], 6)


@pytest.mark.network
def test_find_peaks_minima(peak_data):
"""Test find_peaks correctly identifies peaks."""
data = xr.open_dataset(get_test_data('GFS_test.nc', as_file_obj=False))
Expand Down
1 change: 1 addition & 0 deletions tests/calc/test_cross_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def test_absolute_momentum_given_xy(test_cross_xy):
assert_xarray_allclose(momentum, true_momentum)


@pytest.mark.network
def test_absolute_momentum_xarray_units_attr():
"""Test absolute momentum when `u` and `v` are DataArrays with a `units` attribute."""
data = xr.open_dataset(get_test_data('narr_example.nc', False))
Expand Down
21 changes: 21 additions & 0 deletions tests/calc/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from metpy.units import concatenate, units


@pytest.mark.network
def test_precipitable_water():
"""Test precipitable water with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -24,6 +25,7 @@ def test_precipitable_water():
assert_array_almost_equal(pw, truth, 4)


@pytest.mark.network
def test_precipitable_water_no_bounds():
"""Test precipitable water with observed sounding and no bounds given."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand Down Expand Up @@ -83,6 +85,7 @@ def test_precipitable_water_descriptive_bound_error():
precipitable_water(pressure, dewpoint, bottom=units.Quantity(999, 'hPa'))


@pytest.mark.network
def test_mean_pressure_weighted():
"""Test pressure-weighted mean wind function with vertical interpolation."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -95,6 +98,7 @@ def test_mean_pressure_weighted():
assert_almost_equal(v, 7.966031839967931 * units('m/s'), 7)


@pytest.mark.network
def test_mean_pressure_weighted_temperature():
"""Test pressure-weighted mean temperature function with vertical interpolation."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -105,6 +109,7 @@ def test_mean_pressure_weighted_temperature():
assert_almost_equal(t, 281.535035296836 * units('kelvin'), 7)


@pytest.mark.network
def test_mean_pressure_weighted_elevated():
"""Test pressure-weighted mean wind function with a base above the surface."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -118,6 +123,7 @@ def test_mean_pressure_weighted_elevated():
assert_almost_equal(v, 1.7392601775853547 * units('m/s'), 7)


@pytest.mark.network
def test_weighted_continuous_average():
"""Test pressure-weighted mean wind function with vertical interpolation."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -130,6 +136,7 @@ def test_weighted_continuous_average():
assert_almost_equal(v, 6.900543760612305 * units('m/s'), 7)


@pytest.mark.network
def test_weighted_continuous_average_temperature():
"""Test pressure-weighted mean temperature function with vertical interpolation."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -140,6 +147,7 @@ def test_weighted_continuous_average_temperature():
assert_almost_equal(t, 279.07450928270185 * units('kelvin'), 7)


@pytest.mark.network
def test_weighted_continuous_average_elevated():
"""Test pressure-weighted mean wind function with a base above the surface."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -153,6 +161,7 @@ def test_weighted_continuous_average_elevated():
assert_almost_equal(v, 1.616638856115755 * units('m/s'), 7)


@pytest.mark.network
def test_precipitable_water_xarray():
"""Test precipitable water with xarray input."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -163,6 +172,7 @@ def test_precipitable_water_xarray():
assert_almost_equal(pw, truth)


@pytest.mark.network
def test_bunkers_motion():
"""Test Bunkers storm motion with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -174,6 +184,7 @@ def test_bunkers_motion():
assert_almost_equal(motion.flatten(), truth, 8)


@pytest.mark.network
def test_corfidi_motion():
"""Test corfidi MCS motion with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -184,6 +195,7 @@ def test_corfidi_motion():
assert_almost_equal(motion_full.flatten(), truth_full, 8)


@pytest.mark.network
def test_corfidi_motion_override_llj():
"""Test corfidi MCS motion with overridden LLJ."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -204,13 +216,15 @@ def test_corfidi_motion_override_llj():
data['v_wind'], v_llj=10 * units('kt'))


@pytest.mark.network
def test_corfidi_corfidi_llj_unaivalable():
"""Test corfidi MCS motion where the LLJ is unailable."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
with pytest.raises(ValueError):
corfidi_storm_motion(data['pressure'][6:], data['u_wind'][6:], data['v_wind'][6:])


@pytest.mark.network
def test_corfidi_corfidi_cloudlayer_trimmed():
"""Test corfidi MCS motion where sounding does not include the entire cloud layer."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -221,6 +235,7 @@ def test_corfidi_corfidi_cloudlayer_trimmed():
assert_almost_equal(motion_no_top.flatten(), truth_no_top, 8)


@pytest.mark.network
def test_corfidi_motion_with_nans():
"""Test corfidi MCS motion with observed sounding with nans."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -235,6 +250,7 @@ def test_corfidi_motion_with_nans():
assert_almost_equal(motion_with_nans.flatten(), truth_with_nans, 8)


@pytest.mark.network
def test_bunkers_motion_with_nans():
"""Test Bunkers storm motion with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -250,6 +266,7 @@ def test_bunkers_motion_with_nans():
assert_almost_equal(motion.flatten(), truth, 8)


@pytest.mark.network
def test_bulk_shear():
"""Test bulk shear with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -261,6 +278,7 @@ def test_bulk_shear():
assert_almost_equal(v.to('knots'), truth[1], 8)


@pytest.mark.network
def test_bulk_shear_no_depth():
"""Test bulk shear with observed sounding and no depth given. Issue #568."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -271,6 +289,7 @@ def test_bulk_shear_no_depth():
assert_almost_equal(v.to('knots'), truth[1], 8)


@pytest.mark.network
def test_bulk_shear_elevated():
"""Test bulk shear with observed sounding and a base above the surface."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand Down Expand Up @@ -325,6 +344,7 @@ def test_sigtor_scalar():
assert_almost_equal(sigtor, truth, 6)


@pytest.mark.network
def test_critical_angle():
"""Test critical angle with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand All @@ -335,6 +355,7 @@ def test_critical_angle():
assert_almost_equal(ca, truth, 8)


@pytest.mark.network
def test_critical_angle_units():
"""Test critical angle with observed sounding and different storm motion units."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand Down
12 changes: 12 additions & 0 deletions tests/calc/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def test_advection_z_y():
assert_array_equal(a, truth)


@pytest.mark.network
def test_advection_4d_vertical(data_4d):
"""Test 4-d vertical advection with parsed dims."""
data_4d['w'] = -abs(data_4d['u'])
Expand Down Expand Up @@ -1029,6 +1030,7 @@ def test_potential_vorticity_baroclinic_isobaric_real_data():
assert_almost_equal(pvor, true_pv, 10)


@pytest.mark.network
def test_potential_vorticity_baroclinic_4d(data_4d):
"""Test potential vorticity calculation with latlon+xarray spatial handling."""
theta = potential_temperature(data_4d.pressure, data_4d.temperature)
Expand Down Expand Up @@ -1421,12 +1423,14 @@ def data_4d():
2.84689950e-05]]]]) * units('s^-1')


@pytest.mark.network
def test_vorticity_4d(data_4d):
"""Test vorticity on a 4D (time, pressure, y, x) grid."""
vort = vorticity(data_4d.u, data_4d.v)
assert_array_almost_equal(vort.data, true_vort4d, 12)


@pytest.mark.network
def test_absolute_vorticity_4d(data_4d):
"""Test absolute_vorticity on a 4D (time, pressure, y, x) grid."""
vort = absolute_vorticity(data_4d.u, data_4d.v)
Expand All @@ -1435,6 +1439,7 @@ def test_absolute_vorticity_4d(data_4d):
assert_array_almost_equal(vort.data, truth, 12)


@pytest.mark.network
def test_divergence_4d(data_4d):
"""Test divergence on a 4D (time, pressure, y, x) grid."""
div = divergence(data_4d.u, data_4d.v)
Expand Down Expand Up @@ -1478,6 +1483,7 @@ def test_divergence_4d(data_4d):
assert_array_almost_equal(div.data, truth, 12)


@pytest.mark.network
def test_shearing_deformation_4d(data_4d):
"""Test shearing_deformation on a 4D (time, pressure, y, x) grid."""
shdef = shearing_deformation(data_4d.u, data_4d.v)
Expand Down Expand Up @@ -1521,6 +1527,7 @@ def test_shearing_deformation_4d(data_4d):
assert_array_almost_equal(shdef.data, truth, 12)


@pytest.mark.network
def test_stretching_deformation_4d(data_4d):
"""Test stretching_deformation on a 4D (time, pressure, y, x) grid."""
stdef = stretching_deformation(data_4d.u, data_4d.v)
Expand Down Expand Up @@ -1564,6 +1571,7 @@ def test_stretching_deformation_4d(data_4d):
assert_array_almost_equal(stdef.data, truth, 10)


@pytest.mark.network
def test_total_deformation_4d(data_4d):
"""Test total_deformation on a 4D (time, pressure, y, x) grid."""
totdef = total_deformation(data_4d.u, data_4d.v)
Expand Down Expand Up @@ -1607,6 +1615,7 @@ def test_total_deformation_4d(data_4d):
assert_array_almost_equal(totdef.data, truth, 12)


@pytest.mark.network
def test_frontogenesis_4d(data_4d):
"""Test frontogenesis on a 4D (time, pressure, y, x) grid."""
theta = potential_temperature(data_4d.pressure, data_4d.temperature)
Expand Down Expand Up @@ -1657,6 +1666,7 @@ def test_frontogenesis_4d(data_4d):
assert_array_almost_equal(frnt.data, truth, 13)


@pytest.mark.network
def test_geostrophic_wind_4d(data_4d):
"""Test geostrophic_wind on a 4D (time, pressure, y, x) grid."""
u_g, v_g = geostrophic_wind(data_4d.height)
Expand Down Expand Up @@ -1772,6 +1782,7 @@ def test_geostrophic_wind_4d(data_4d):
assert_array_almost_equal(v_g.data, v_g_truth, 4)


@pytest.mark.network
def test_inertial_advective_wind_4d(data_4d):
"""Test inertial_advective_wind on a 4D (time, pressure, y, x) grid."""
u_g, v_g = geostrophic_wind(data_4d.height)
Expand Down Expand Up @@ -1860,6 +1871,7 @@ def test_inertial_advective_wind_4d(data_4d):
assert_array_almost_equal(v_i.data, v_i_truth, 4)


@pytest.mark.network
def test_q_vector_4d(data_4d):
"""Test q_vector on a 4D (time, pressure, y, x) grid."""
u_g, v_g = geostrophic_wind(data_4d.height)
Expand Down
3 changes: 3 additions & 0 deletions tests/interpolate/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_generate_grid_coords():
assert pts.flags['C_CONTIGUOUS'] # need output to be C-contiguous


@pytest.mark.network
def test_natural_neighbor_to_grid(test_data, test_grid):
r"""Test natural neighbor interpolation to grid function."""
xp, yp, z = test_data
Expand All @@ -167,6 +168,7 @@ def test_natural_neighbor_to_grid(test_data, test_grid):
interp_methods = ['cressman', 'barnes']


@pytest.mark.network
@pytest.mark.parametrize('method', interp_methods)
def test_inverse_distance_to_grid(method, test_data, test_grid):
r"""Test inverse distance interpolation to grid function."""
Expand Down Expand Up @@ -243,6 +245,7 @@ def test_interpolate_to_isosurface():
assert_array_almost_equal(truth, dt_theta)


@pytest.mark.network
@pytest.mark.parametrize('assume_units', [None, 'mbar'])
@pytest.mark.parametrize('method', interp_methods)
@pytest.mark.parametrize('boundary_coords', boundary_types)
Expand Down
5 changes: 5 additions & 0 deletions tests/interpolate/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_barnes_point(test_data):
assert_almost_equal(barnes_point(dists, values, 5762.7), 4.0871824)


@pytest.mark.network
def test_natural_neighbor_to_points(test_data, test_points):
r"""Test natural neighbor interpolation to grid function."""
xp, yp, z = test_data
Expand All @@ -109,6 +110,7 @@ def test_natural_neighbor_to_points(test_data, test_points):
assert_array_almost_equal(truth, img)


@pytest.mark.network
def test_inverse_distance_to_points_invalid(test_data, test_points):
"""Test that inverse_distance_to_points raises when given an invalid method."""
xp, yp, z = test_data
Expand All @@ -117,6 +119,7 @@ def test_inverse_distance_to_points_invalid(test_data, test_points):
inverse_distance_to_points(obs_points, z, test_points, kind='shouldraise', r=40)


@pytest.mark.network
@pytest.mark.parametrize('assume_units', [None, 'mbar'])
@pytest.mark.parametrize('method', ['cressman', 'barnes'])
def test_inverse_distance_to_points(method, assume_units, test_data, test_points):
Expand All @@ -138,6 +141,7 @@ def test_inverse_distance_to_points(method, assume_units, test_data, test_points
assert_array_almost_equal(truth, img)


@pytest.mark.network
def test_interpolate_to_points_invalid(test_data):
"""Test that interpolate_to_points raises when given an invalid method."""
xp, yp, z = test_data
Expand All @@ -150,6 +154,7 @@ def test_interpolate_to_points_invalid(test_data):
interpolate_to_points(obs_points, z, test_points, interp_type='shouldraise')


@pytest.mark.network
@pytest.mark.parametrize('assume_units', [None, 'mbar'])
@pytest.mark.parametrize('method', ['natural_neighbor', 'cressman', 'barnes', 'linear',
'nearest', 'rbf', 'cubic'])
Expand Down
Loading