Code Duplication    Length = 19-19 lines in 3 locations

metpy/calc/tests/test_thermo.py 3 locations

@@ 540-558 (lines=19) @@
537
    tmp[3, :] = 288.
538
    rh = np.ones((4, 5, 5))
539
    rh[0, :] = 100.
540
    rh[1, :] = 80.
541
    rh[2, :] = 40.
542
    rh[3, :] = 20.
543
    relh = rh * units.percent
544
    tmpk = tmp * units.kelvin
545
    isentlev = [296.] * units.kelvin
546
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, relh)
547
    truerh = 100. * units.percent
548
    assert_almost_equal(isentprs[1], truerh, 3)
549
550
551
def test_isentropic_pressure_tmp_out():
552
    """Test calculation of isentropic pressure function, temperature output."""
553
    lev = [100000., 95000., 90000., 85000.] * units.Pa
554
    tmp = np.ones((4, 5, 5))
555
    tmp[0, :] = 296.
556
    tmp[1, :] = 292.
557
    tmp[2, :] = 290.
558
    tmp[3, :] = 288.
559
    tmpk = tmp * units.kelvin
560
    isentlev = [296.] * units.kelvin
561
    isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True)
@@ 504-522 (lines=19) @@
501
    lev = [100000., 95000., 90000., 85000.] * units.Pa
502
    tmp = np.ones((4, 5, 5))
503
    tmp[0, :] = 296.
504
    tmp[1, :] = 292.
505
    tmp[2, :] = 290
506
    tmp[3, :] = 288.
507
    tmpk = tmp * units.kelvin
508
    isentlev = [296.] * units.kelvin
509
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
510
    trueprs = 1000. * units.hPa
511
    assert_almost_equal(isentprs[0].shape, (1, 5, 5), 3)
512
    assert_almost_equal(isentprs[0], trueprs, 3)
513
514
515
def test_isentropic_pressure_p_increase():
516
    """Test calculation of isentropic pressure function, p increasing order."""
517
    lev = [85000, 90000., 95000., 100000.] * units.Pa
518
    tmp = np.ones((4, 5, 5))
519
    tmp[0, :] = 288.
520
    tmp[1, :] = 290.
521
    tmp[2, :] = 292.
522
    tmp[3, :] = 296.
523
    tmpk = tmp * units.kelvin
524
    isentlev = [296.] * units.kelvin
525
    isentprs = isentropic_interpolation(isentlev, lev, tmpk)
@@ 468-486 (lines=19) @@
465
    """Tests that CAPE is zero with no LFC."""
466
    p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar
467
    temperature = np.array([22.2, 24.6, 22., 20.4, 18., -10.]) * units.celsius
468
    dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
469
    parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC')
470
    cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof)
471
    assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6)
472
    assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6)
473
474
475
def test_find_append_zero_crossings():
476
    """Tests finding and appending zero crossings of an x, y series."""
477
    x = np.arange(11) * units.hPa
478
    y = np.array([3, 2, 1, -1, 2, 2, 0, 1, 0, -1, 2]) * units.degC
479
    x2, y2 = _find_append_zero_crossings(x, y)
480
481
    x_truth = np.array([0., 1., 2., 2.5, 3., 3.33333333, 4., 5.,
482
                        6., 7., 8., 9., 9.33333333, 10.]) * units.hPa
483
    y_truth = np.array([3, 2, 1, 0, -1, 0, 2, 2, 0, 1, 0, -1, 0, 2]) * units.degC
484
    assert_array_almost_equal(x2, x_truth, 6)
485
    assert_almost_equal(y2, y_truth, 6)
486
487
488
def test_most_unstable_parcel():
489
    """Tests calculating the most unstable parcel."""