Code Duplication    Length = 8-9 lines in 4 locations

metpy/calc/tests/test_thermo.py 4 locations

@@ 410-418 (lines=9) @@
407
    """Tests the basic CAPE and CIN calculation."""
408
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
409
    temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius
410
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
411
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0])
412
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
413
    assert_almost_equal(cape, 58.0368212 * units('joule / kilogram'), 6)
414
    assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6)
415
416
417
def test_cape_cin_no_el():
418
    """Tests that CAPE works with no EL."""
419
    p = np.array([959., 779.2, 751.3, 724.3]) * units.mbar
420
    temperature = np.array([22.2, 14.6, 12., 9.4]) * units.celsius
421
    dewpoint = np.array([19., -11.2, -10.8, -10.4]) * units.celsius
@@ 386-394 (lines=9) @@
383
    p = 1013.25 * units.mbar
384
    temperature = 20. * units.degC
385
    w = 0.012
386
    rh = relative_humidity_from_mixing_ratio(w, temperature, p)
387
    assert_almost_equal(rh, 81.7219 * units.percent, 3)
388
389
390
def test_mixing_ratio_from_specific_humidity():
391
    """Tests mixing ratio from specific humidity."""
392
    q = 0.012
393
    w = mixing_ratio_from_specific_humidity(q)
394
    assert_almost_equal(w, 0.01215, 3)
395
396
397
def test_rh_specific_humidity():
@@ 179-186 (lines=8) @@
176
    """Test vapor pressure calculation."""
177
    assert_almost_equal(vapor_pressure(998. * units.mbar, 0.04963),
178
                        73.74925 * units.mbar, 5)
179
180
181
def test_lcl():
182
    """Test LCL calculation."""
183
    lcl_pressure, lcl_temperature = lcl(1000. * units.mbar, 30. * units.degC, 20. * units.degC)
184
    assert_almost_equal(lcl_pressure, 864.761 * units.mbar, 2)
185
    assert_almost_equal(lcl_temperature, 17.676 * units.degC, 2)
186
187
188
def test_lcl_convergence():
189
    """Test LCL calculation convergence failure."""
@@ 364-372 (lines=9) @@
361
    p = 1013.25 * units.mbar
362
    dry_bulb_temperature = 20. * units.degC
363
    wet_bulb_temperature = 18. * units.degC
364
    psychrometric_rh = relative_humidity_wet_psychrometric(dry_bulb_temperature,
365
                                                           wet_bulb_temperature, p)
366
    assert_almost_equal(psychrometric_rh, 82.8747 * units.percent, 3)
367
368
369
def test_wet_psychrometric_rh_kwargs():
370
    """Test calculation of relative humidity from wet and dry bulb temperatures."""
371
    p = 1013.25 * units.mbar
372
    dry_bulb_temperature = 20. * units.degC
373
    wet_bulb_temperature = 18. * units.degC
374
    coeff = 6.1e-4 / units.kelvin
375
    psychrometric_rh = relative_humidity_wet_psychrometric(dry_bulb_temperature,