Code Duplication    Length = 13-14 lines in 5 locations

metpy/calc/tests/test_thermo.py 5 locations

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