Code Duplication    Length = 8-9 lines in 4 locations

metpy/calc/tests/test_thermo.py 4 locations

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