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