Code Duplication    Length = 19-19 lines in 3 locations

metpy/calc/tests/test_thermo.py 3 locations

@@ 540-558 (lines=19) @@
537
    tmp[1, :] = 292.
538
    tmp[2, :] = 290.
539
    tmp[3, :] = 288.
540
    tmpk = tmp * units.kelvin
541
    isentlev = [296.] * units.kelvin
542
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True)
543
    truetmp = 296. * units.kelvin
544
    assert_almost_equal(isentprs[1], truetmp, 3)
545
546
547
def test_isentropic_pressure_p_increase_rh_out():
548
    """Test calculation of isentropic pressure function, p increasing order."""
549
    lev = [85000., 90000., 95000., 100000.] * units.Pa
550
    tmp = np.ones((4, 5, 5))
551
    tmp[0, :] = 288.
552
    tmp[1, :] = 290.
553
    tmp[2, :] = 292.
554
    tmp[3, :] = 296.
555
    tmpk = tmp * units.kelvin
556
    rh = np.ones((4, 5, 5))
557
    rh[0, :] = 20.
558
    rh[1, :] = 40.
559
    rh[2, :] = 80.
560
    rh[3, :] = 100.
561
    relh = rh * units.percent
@@ 504-522 (lines=19) @@
501
    tmp[1, :] = 290.
502
    tmp[2, :] = 292.
503
    tmp[3, :] = 296.
504
    tmpk = tmp * units.kelvin
505
    isentlev = [296.] * units.kelvin
506
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
507
    trueprs = 1000. * units.hPa
508
    assert_almost_equal(isentprs[0], trueprs, 3)
509
510
511
def test_isentropic_pressure_adition_args():
512
    """Test calculation of isentropic pressure function, additional args."""
513
    lev = [100000., 95000., 90000., 85000.] * units.Pa
514
    tmp = np.ones((4, 5, 5))
515
    tmp[0, :] = 296.
516
    tmp[1, :] = 292.
517
    tmp[2, :] = 290.
518
    tmp[3, :] = 288.
519
    rh = np.ones((4, 5, 5))
520
    rh[0, :] = 100.
521
    rh[1, :] = 80.
522
    rh[2, :] = 40.
523
    rh[3, :] = 20.
524
    relh = rh * units.percent
525
    tmpk = tmp * units.kelvin
@@ 468-486 (lines=19) @@
465
    assert_array_almost_equal(x2, x_truth, 6)
466
    assert_almost_equal(y2, y_truth, 6)
467
468
469
def test_most_unstable_parcel():
470
    """Tests calculating the most unstable parcel."""
471
    levels = np.array([1000., 959., 867.9]) * units.mbar
472
    temperatures = np.array([18.2, 22.2, 17.4]) * units.celsius
473
    dewpoints = np.array([19., 19., 14.3]) * units.celsius
474
    ret = most_unstable_parcel(levels, temperatures, dewpoints, depth=100 * units.hPa)
475
    assert_almost_equal(ret[0], 959.0 * units.hPa, 6)
476
    assert_almost_equal(ret[1], 22.2 * units.degC, 6)
477
    assert_almost_equal(ret[2], 19.0 * units.degC, 6)
478
479
480
def test_isentropic_pressure():
481
    """Test calculation of isentropic pressure function."""
482
    lev = [100000., 95000., 90000., 85000.] * units.Pa
483
    tmp = np.ones((4, 5, 5))
484
    tmp[0, :] = 296.
485
    tmp[1, :] = 292.
486
    tmp[2, :] = 290
487
    tmp[3, :] = 288.
488
    tmpk = tmp * units.kelvin
489
    isentlev = [296.] * units.kelvin