Code Duplication    Length = 8-10 lines in 3 locations

metpy/calc/tests/test_tools.py 3 locations

@@ 333-340 (lines=8) @@
330
@pytest.mark.parametrize('pressure, variable, heights, bottom, depth, interp, expected', [
331
    (layer_test_data()[0], layer_test_data()[1], None, None, 150 * units.hPa, True,
332
     (np.array([1000, 900, 850]) * units.hPa,
333
      np.array([25.0, 16.666666, 12.62262]) * units.degC)),
334
    (layer_test_data()[0], layer_test_data()[1], None, None, 150 * units.hPa, False,
335
     (np.array([1000, 900]) * units.hPa, np.array([25.0, 16.666666]) * units.degC)),
336
    (layer_test_data()[0], layer_test_data()[1], None, 2 * units.km, 3 * units.km, True,
337
     (np.array([794.85264282, 700., 600., 540.01696548]) * units.hPa,
338
      np.array([7.93049516, 0., -8.33333333, -13.14758845]) * units.degC))
339
])
340
def test_get_layer(pressure, variable, heights, bottom, depth, interp, expected):
341
    """Tests get_layer functionality."""
342
    p_layer, y_layer = get_layer(pressure, variable, heights=heights, bottom=bottom,
343
                                 depth=depth, interpolate=interp)
@@ 323-330 (lines=8) @@
320
321
322
@pytest.fixture
323
def layer_test_data():
324
    """Provide test data for testing of layer bounds."""
325
    pressure = np.arange(1000, 10, -100) * units.hPa
326
    temperature = np.linspace(25, -50, len(pressure)) * units.degC
327
    return pressure, temperature
328
329
330
@pytest.mark.parametrize('pressure, variable, heights, bottom, depth, interp, expected', [
331
    (layer_test_data()[0], layer_test_data()[1], None, None, 150 * units.hPa, True,
332
     (np.array([1000, 900, 850]) * units.hPa,
333
      np.array([25.0, 16.666666, 12.62262]) * units.degC)),
@@ 343-352 (lines=10) @@
340
def test_get_layer(pressure, variable, heights, bottom, depth, interp, expected):
341
    """Tests get_layer functionality."""
342
    p_layer, y_layer = get_layer(pressure, variable, heights=heights, bottom=bottom,
343
                                 depth=depth, interpolate=interp)
344
    assert_array_almost_equal(p_layer, expected[0], 5)
345
    assert_array_almost_equal(y_layer, expected[1], 5)
346
347
348
def test_log_interp_2d():
349
    """Test interpolating with log x-scale in 2 dimensions."""
350
    x_log = np.array([[1e3, 1e4, 1e5, 1e6], [1e3, 1e4, 1e5, 1e6]])
351
    y_log = np.log(x_log) * 2 + 3
352
    x_interp = np.array([5e3, 5e4, 5e5])
353
    y_interp_truth = np.array([20.0343863828, 24.6395565688, 29.2447267548])
354
    y_interp = log_interp(x_interp, x_log, y_log, axis=1)
355
    assert_array_almost_equal(y_interp[1], y_interp_truth, 7)