Code Duplication    Length = 13-14 lines in 5 locations

metpy/calc/tests/test_thermo.py 5 locations

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