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_isentropic_pressure():
451
    """Test calculation of isentropic pressure function."""
452
    lev = [100000., 95000., 90000., 85000.] * units.Pa
453
    tmp = np.ones((4, 5, 5))
@@ 561-573 (lines=13) @@
558
    tmp[1, :] = 292.
559
    tmp[2, :] = 290.
560
    tmp[3, :] = 288.
561
    rh = np.ones((4, 5, 5))
562
    rh[0, :] = 100.
563
    rh[1, :] = 80.
564
    rh[2, :] = 40.
565
    rh[3, :] = 20.
566
    relh = rh * units.percent
567
    tmpk = tmp * units.kelvin
568
    isentlev = [296., 297.] * units.kelvin
569
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, relh)
570
    truerh = 69.171 * units.percent
571
    assert_almost_equal(isentprs[1][1], truerh, 3)
572
573
574
def test_isentropic_pressure_tmp_out_interp():
575
    """Test calculation of isentropic pressure function, temperature output."""
576
    lev = [100000., 95000., 90000., 85000.] * units.Pa
@@ 525-537 (lines=13) @@
522
    tmp[1, :] = 290.
523
    tmp[2, :] = 292.
524
    tmp[3, :] = 296.
525
    tmpk = tmp * units.kelvin
526
    rh = np.ones((4, 5, 5))
527
    rh[0, :] = 20.
528
    rh[1, :] = 40.
529
    rh[2, :] = 80.
530
    rh[3, :] = 100.
531
    relh = rh * units.percent
532
    isentlev = 296. * units.kelvin
533
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, relh)
534
    truerh = 100. * units.percent
535
    assert_almost_equal(isentprs[1], truerh, 3)
536
537
538
def test_isentropic_pressure_interp():
539
    """Test calculation of isentropic pressure function."""
540
    lev = [100000., 95000., 90000., 85000.] * units.Pa
@@ 489-501 (lines=13) @@
486
    tmp[1, :] = 292.
487
    tmp[2, :] = 290.
488
    tmp[3, :] = 288.
489
    rh = np.ones((4, 5, 5))
490
    rh[0, :] = 100.
491
    rh[1, :] = 80.
492
    rh[2, :] = 40.
493
    rh[3, :] = 20.
494
    relh = rh * units.percent
495
    tmpk = tmp * units.kelvin
496
    isentlev = [296.] * units.kelvin
497
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, relh)
498
    truerh = 100. * units.percent
499
    assert_almost_equal(isentprs[1], truerh, 3)
500
501
502
def test_isentropic_pressure_tmp_out():
503
    """Test calculation of isentropic pressure function, temperature output."""
504
    lev = [100000., 95000., 90000., 85000.] * units.Pa
@@ 453-465 (lines=13) @@
450
def test_isentropic_pressure():
451
    """Test calculation of isentropic pressure function."""
452
    lev = [100000., 95000., 90000., 85000.] * units.Pa
453
    tmp = np.ones((4, 5, 5))
454
    tmp[0, :] = 296.
455
    tmp[1, :] = 292.
456
    tmp[2, :] = 290
457
    tmp[3, :] = 288.
458
    tmpk = tmp * units.kelvin
459
    isentlev = [296.] * units.kelvin
460
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
461
    trueprs = 1000. * units.hPa
462
    assert_almost_equal(isentprs[0].shape, (1, 5, 5), 3)
463
    assert_almost_equal(isentprs[0], trueprs, 3)
464
465
466
def test_isentropic_pressure_p_increase():
467
    """Test calculation of isentropic pressure function, p increasing order."""
468
    lev = [85000, 90000., 95000., 100000.] * units.Pa