Code Duplication    Length = 8-9 lines in 4 locations

metpy/calc/tests/test_thermo.py 4 locations

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