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.08750805 * units('joule / kilogram'), 6)
409
    assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6)
410
411
412
def test_cape_cin_no_lfc():
413
    """Tests that CAPE is zero with no LFC."""
414
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
415
    temperature = np.array([22.2, 24.6, 22., 20.4, 18., -10.]) * units.celsius
416
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
417
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC')
418
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
419
    assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6)
420
    assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6)
421
@@ 386-394 (lines=9) @@
383
    p = 1013.25 * units.mbar
384
    temperature = 20. * units.degC
385
    q = 0.012
386
    rh = relative_humidity_from_specific_humidity(q, temperature, p)
387
    assert_almost_equal(rh, 82.7145 * units.percent, 3)
388
389
390
def test_cape_cin():
391
    """Tests the basic CAPE and CIN calculation."""
392
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
393
    temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius
394
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
395
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0])
396
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
397
    assert_almost_equal(cape, 58.0368212 * 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
                                                           psychrometer_coefficient=coeff)
362
    assert_almost_equal(psychrometric_rh, 82.9701 * units.percent, 3)
363
364
365
def test_rh_mixing_ratio():
366
    """Tests relative humidity from mixing ratio."""
367
    p = 1013.25 * units.mbar
368
    temperature = 20. * units.degC
369
    w = 0.012
370
    rh = relative_humidity_from_mixing_ratio(w, temperature, p)
371
    assert_almost_equal(rh, 81.7219 * units.percent, 3)
372
373
374
def test_mixing_ratio_from_specific_humidity():
375
    """Tests mixing ratio from specific humidity."""