Code Duplication    Length = 8-9 lines in 4 locations

metpy/calc/tests/test_thermo.py 4 locations

@@ 410-418 (lines=9) @@
407
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
408
    assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6)
409
    assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6)
410
411
412
def test_find_append_zero_crossings():
413
    """Tests finding and appending zero crossings of an x, y series."""
414
    x = np.arange(11) * units.hPa
415
    y = np.array([3, 2, 1, -1, 2, 2, 0, 1, 0, -1, 2]) * units.degC
416
    x2, y2 = _find_append_zero_crossings(x, y)
417
418
    x_truth = np.array([0., 1., 2., 2.5, 3., 3.33333333, 4., 5.,
419
                        6., 7., 8., 9., 9.33333333, 10.]) * units.hPa
420
    y_truth = np.array([3, 2, 1, 0, -1, 0, 2, 2, 0, 1, 0, -1, 0, 2]) * units.degC
421
    assert_array_almost_equal(x2, x_truth, 6)
@@ 386-394 (lines=9) @@
383
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
384
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0])
385
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
386
    assert_almost_equal(cape, 58.0368212 * units('joule / kilogram'), 6)
387
    assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6)
388
389
390
def test_cape_cin_no_el():
391
    """Tests that CAPE works with no EL."""
392
    p = np.array([959., 779.2, 751.3, 724.3]) * units.mbar
393
    temperature = np.array([22.2, 14.6, 12., 9.4]) * units.celsius
394
    dewpoint = np.array([19., -11.2, -10.8, -10.4]) * units.celsius
395
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC')
396
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
397
    assert_almost_equal(cape, 0.08750805 * units('joule / kilogram'), 6)
@@ 179-186 (lines=8) @@
176
        lcl(1000. * units.mbar, 30. * units.degC, 20. * units.degC, max_iters=2)
177
178
179
def test_lfc_basic():
180
    """Test LFC calculation."""
181
    levels = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
182
    temperatures = np.array([22.2, 14.6, 12., 9.4, 7., -49.]) * units.celsius
183
    dewpoints = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
184
    l = lfc(levels, temperatures, dewpoints)
185
    assert_almost_equal(l[0], 727.468 * units.mbar, 2)
186
    assert_almost_equal(l[1], 9.705 * units.celsius, 2)
187
188
189
def test_no_lfc():
@@ 364-372 (lines=9) @@
361
362
363
def test_mixing_ratio_from_specific_humidity():
364
    """Tests mixing ratio from specific humidity."""
365
    q = 0.012
366
    w = mixing_ratio_from_specific_humidity(q)
367
    assert_almost_equal(w, 0.01215, 3)
368
369
370
def test_rh_specific_humidity():
371
    """Tests relative humidity from specific humidity."""
372
    p = 1013.25 * units.mbar
373
    temperature = 20. * units.degC
374
    q = 0.012
375
    rh = relative_humidity_from_specific_humidity(q, temperature, p)