Code Duplication    Length = 8-9 lines in 4 locations

metpy/calc/tests/test_thermo.py 4 locations

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