Code Duplication    Length = 8-9 lines in 4 locations

metpy/calc/tests/test_thermo.py 4 locations

@@ 410-418 (lines=9) @@
407
    dewpoint = np.array([19., -11.2, -10.8, -10.4]) * units.celsius
408
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC')
409
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
410
    assert_almost_equal(cape, 0.08750805 * units('joule / kilogram'), 6)
411
    assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6)
412
413
414
def test_cape_cin_no_lfc():
415
    """Tests that CAPE is zero with no LFC."""
416
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
417
    temperature = np.array([22.2, 24.6, 22., 20.4, 18., -10.]) * units.celsius
418
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
419
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC')
420
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
421
    assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6)
@@ 386-394 (lines=9) @@
383
def test_rh_specific_humidity():
384
    """Tests relative humidity from specific humidity."""
385
    p = 1013.25 * units.mbar
386
    temperature = 20. * units.degC
387
    q = 0.012
388
    rh = relative_humidity_from_specific_humidity(q, temperature, p)
389
    assert_almost_equal(rh, 82.7145 * units.percent, 3)
390
391
392
def test_cape_cin():
393
    """Tests the basic CAPE and CIN calculation."""
394
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
395
    temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius
396
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
397
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0])
@@ 179-186 (lines=8) @@
176
    """Test LCL calculation convergence failure."""
177
    with pytest.raises(RuntimeError):
178
        lcl(1000. * units.mbar, 30. * units.degC, 20. * units.degC, max_iters=2)
179
180
181
def test_lfc_basic():
182
    """Test LFC calculation."""
183
    levels = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
184
    temperatures = np.array([22.2, 14.6, 12., 9.4, 7., -49.]) * units.celsius
185
    dewpoints = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
186
    l = lfc(levels, temperatures, dewpoints)
187
    assert_almost_equal(l[0], 727.468 * units.mbar, 2)
188
    assert_almost_equal(l[1], 9.705 * units.celsius, 2)
189
@@ 364-372 (lines=9) @@
361
    psychrometric_rh = relative_humidity_wet_psychrometric(dry_bulb_temperature,
362
                                                           wet_bulb_temperature, p,
363
                                                           psychrometer_coefficient=coeff)
364
    assert_almost_equal(psychrometric_rh, 82.9701 * units.percent, 3)
365
366
367
def test_rh_mixing_ratio():
368
    """Tests relative humidity from mixing ratio."""
369
    p = 1013.25 * units.mbar
370
    temperature = 20. * units.degC
371
    w = 0.012
372
    rh = relative_humidity_from_mixing_ratio(w, temperature, p)
373
    assert_almost_equal(rh, 81.7219 * units.percent, 3)
374
375