Code Duplication    Length = 13-14 lines in 5 locations

metpy/calc/tests/test_thermo.py 5 locations

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