Code Duplication    Length = 13-14 lines in 5 locations

metpy/calc/tests/test_thermo.py 5 locations

@@ 437-450 (lines=14) @@
434
    y_truth = np.array([3, 2, 1, 0, -1, 0, 2, 2, 0, 1, 0, -1, 0, 2]) * units.degC
435
    assert_array_almost_equal(x2, x_truth, 6)
436
    assert_almost_equal(y2, y_truth, 6)
437
438
439
def test_most_unstable_parcel():
440
    """Tests calculating the most unstable parcel."""
441
    levels = np.array([1000., 959., 867.9]) * units.mbar
442
    temperatures = np.array([18.2, 22.2, 17.4]) * units.celsius
443
    dewpoints = np.array([19., 19., 14.3]) * units.celsius
444
    ret = most_unstable_parcel(levels, temperatures, dewpoints, depth=100 * units.hPa)
445
    assert_almost_equal(ret[0], 959.0 * units.hPa, 6)
446
    assert_almost_equal(ret[1], 22.2 * units.degC, 6)
447
    assert_almost_equal(ret[2], 19.0 * units.degC, 6)
448
449
450
def test_mucape_mucin_surface():
451
    """Tests the MUCAPE and MUCIN calculation when surface is most unstable."""
452
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
453
    temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius
@@ 561-573 (lines=13) @@
558
def test_isentropic_pressure_interp():
559
    """Test calculation of isentropic pressure function."""
560
    lev = [100000., 95000., 90000., 85000.] * units.Pa
561
    tmp = np.ones((4, 5, 5))
562
    tmp[0, :] = 296.
563
    tmp[1, :] = 292.
564
    tmp[2, :] = 290
565
    tmp[3, :] = 288.
566
    tmpk = tmp * units.kelvin
567
    isentlev = [296., 297] * units.kelvin
568
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
569
    trueprs = 936.18057 * units.hPa
570
    assert_almost_equal(isentprs[0][1], trueprs, 3)
571
572
573
def test_isentropic_pressure_adition_args_interp():
574
    """Test calculation of isentropic pressure function, additional args."""
575
    lev = [100000., 95000., 90000., 85000.] * units.Pa
576
    tmp = np.ones((4, 5, 5))
@@ 525-537 (lines=13) @@
522
def test_isentropic_pressure_tmp_out():
523
    """Test calculation of isentropic pressure function, temperature output."""
524
    lev = [100000., 95000., 90000., 85000.] * units.Pa
525
    tmp = np.ones((4, 5, 5))
526
    tmp[0, :] = 296.
527
    tmp[1, :] = 292.
528
    tmp[2, :] = 290.
529
    tmp[3, :] = 288.
530
    tmpk = tmp * units.kelvin
531
    isentlev = [296.] * units.kelvin
532
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True)
533
    truetmp = 296. * units.kelvin
534
    assert_almost_equal(isentprs[1], truetmp, 3)
535
536
537
def test_isentropic_pressure_p_increase_rh_out():
538
    """Test calculation of isentropic pressure function, p increasing order."""
539
    lev = [85000., 90000., 95000., 100000.] * units.Pa
540
    tmp = np.ones((4, 5, 5))
@@ 489-501 (lines=13) @@
486
def test_isentropic_pressure_p_increase():
487
    """Test calculation of isentropic pressure function, p increasing order."""
488
    lev = [85000, 90000., 95000., 100000.] * units.Pa
489
    tmp = np.ones((4, 5, 5))
490
    tmp[0, :] = 288.
491
    tmp[1, :] = 290.
492
    tmp[2, :] = 292.
493
    tmp[3, :] = 296.
494
    tmpk = tmp * units.kelvin
495
    isentlev = [296.] * units.kelvin
496
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
497
    trueprs = 1000. * units.hPa
498
    assert_almost_equal(isentprs[0], trueprs, 3)
499
500
501
def test_isentropic_pressure_adition_args():
502
    """Test calculation of isentropic pressure function, additional args."""
503
    lev = [100000., 95000., 90000., 85000.] * units.Pa
504
    tmp = np.ones((4, 5, 5))
@@ 453-465 (lines=13) @@
450
def test_mucape_mucin_surface():
451
    """Tests the MUCAPE and MUCIN calculation when surface is most unstable."""
452
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
453
    temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius
454
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
455
    mucape, mucin = mucape_cin(p, temperature, dewpoint)
456
    assert_almost_equal(mucape, 58.0368212 * units('joule / kilogram'), 6)
457
    assert_almost_equal(mucin, -89.8073512 * units('joule / kilogram'), 6)
458
459
460
def test_mucape_mucin():
461
    """Tests the MUCAPE and MUCIN calculation."""
462
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
463
    temperature = np.array([14.6, 22.2, 12., 9.4, 7., -38.]) * units.celsius
464
    dewpoint = np.array([19., 5.0, -10.8, -10.4, -10., -53.2]) * units.celsius
465
    mucape, mucin = mucape_cin(p, temperature, dewpoint)
466
    assert_almost_equal(mucape, 540.9049917 * units('joule / kilogram'), 6)
467
    assert_almost_equal(mucin, 0. * units('joule / kilogram'), 6)
468