Code Duplication    Length = 13-14 lines in 5 locations

metpy/calc/tests/test_thermo.py 5 locations

@@ 437-450 (lines=14) @@
434
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC')
435
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
436
    assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6)
437
    assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6)
438
439
440
def test_find_append_zero_crossings():
441
    """Tests finding and appending zero crossings of an x, y series."""
442
    x = np.arange(11) * units.hPa
443
    y = np.array([3, 2, 1, -1, 2, 2, 0, 1, 0, -1, 2]) * units.degC
444
    x2, y2 = _find_append_zero_crossings(x, y)
445
446
    x_truth = np.array([0., 1., 2., 2.5, 3., 3.33333333, 4., 5.,
447
                        6., 7., 8., 9., 9.33333333, 10.]) * units.hPa
448
    y_truth = np.array([3, 2, 1, 0, -1, 0, 2, 2, 0, 1, 0, -1, 0, 2]) * units.degC
449
    assert_array_almost_equal(x2, x_truth, 6)
450
    assert_almost_equal(y2, y_truth, 6)
451
452
453
def test_most_unstable_parcel():
@@ 561-573 (lines=13) @@
558
    tmp[2, :] = 290
559
    tmp[3, :] = 288.
560
    tmpk = tmp * units.kelvin
561
    isentlev = [296., 297] * units.kelvin
562
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
563
    trueprs = 936.18057 * units.hPa
564
    assert_almost_equal(isentprs[0][1], trueprs, 3)
565
566
567
def test_isentropic_pressure_adition_args_interp():
568
    """Test calculation of isentropic pressure function, additional args."""
569
    lev = [100000., 95000., 90000., 85000.] * units.Pa
570
    tmp = np.ones((4, 5, 5))
571
    tmp[0, :] = 296.
572
    tmp[1, :] = 292.
573
    tmp[2, :] = 290.
574
    tmp[3, :] = 288.
575
    rh = np.ones((4, 5, 5))
576
    rh[0, :] = 100.
@@ 525-537 (lines=13) @@
522
    tmp[2, :] = 290.
523
    tmp[3, :] = 288.
524
    tmpk = tmp * units.kelvin
525
    isentlev = [296.] * units.kelvin
526
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True)
527
    truetmp = 296. * units.kelvin
528
    assert_almost_equal(isentprs[1], truetmp, 3)
529
530
531
def test_isentropic_pressure_p_increase_rh_out():
532
    """Test calculation of isentropic pressure function, p increasing order."""
533
    lev = [85000., 90000., 95000., 100000.] * units.Pa
534
    tmp = np.ones((4, 5, 5))
535
    tmp[0, :] = 288.
536
    tmp[1, :] = 290.
537
    tmp[2, :] = 292.
538
    tmp[3, :] = 296.
539
    tmpk = tmp * units.kelvin
540
    rh = np.ones((4, 5, 5))
@@ 489-501 (lines=13) @@
486
    tmp[2, :] = 292.
487
    tmp[3, :] = 296.
488
    tmpk = tmp * units.kelvin
489
    isentlev = [296.] * units.kelvin
490
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
491
    trueprs = 1000. * units.hPa
492
    assert_almost_equal(isentprs[0], trueprs, 3)
493
494
495
def test_isentropic_pressure_adition_args():
496
    """Test calculation of isentropic pressure function, additional args."""
497
    lev = [100000., 95000., 90000., 85000.] * units.Pa
498
    tmp = np.ones((4, 5, 5))
499
    tmp[0, :] = 296.
500
    tmp[1, :] = 292.
501
    tmp[2, :] = 290.
502
    tmp[3, :] = 288.
503
    rh = np.ones((4, 5, 5))
504
    rh[0, :] = 100.
@@ 453-465 (lines=13) @@
450
    assert_almost_equal(y2, y_truth, 6)
451
452
453
def test_most_unstable_parcel():
454
    """Tests calculating the most unstable parcel."""
455
    levels = np.array([1000., 959., 867.9]) * units.mbar
456
    temperatures = np.array([18.2, 22.2, 17.4]) * units.celsius
457
    dewpoints = np.array([19., 19., 14.3]) * units.celsius
458
    ret = most_unstable_parcel(levels, temperatures, dewpoints, depth=100 * units.hPa)
459
    assert_almost_equal(ret[0], 959.0 * units.hPa, 6)
460
    assert_almost_equal(ret[1], 22.2 * units.degC, 6)
461
    assert_almost_equal(ret[2], 19.0 * units.degC, 6)
462
463
464
def test_isentropic_pressure():
465
    """Test calculation of isentropic pressure function."""
466
    lev = [100000., 95000., 90000., 85000.] * units.Pa
467
    tmp = np.ones((4, 5, 5))
468
    tmp[0, :] = 296.