|
@@ 437-450 (lines=14) @@
|
| 434 |
|
def test_cape_cin_no_el(): |
| 435 |
|
"""Tests that CAPE works with no EL.""" |
| 436 |
|
p = np.array([959., 779.2, 751.3, 724.3]) * units.mbar |
| 437 |
|
temperature = np.array([22.2, 14.6, 12., 9.4]) * units.celsius |
| 438 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4]) * units.celsius |
| 439 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 440 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 441 |
|
assert_almost_equal(cape, 0.08750805 * units('joule / kilogram'), 6) |
| 442 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 443 |
|
|
| 444 |
|
|
| 445 |
|
def test_cape_cin_no_lfc(): |
| 446 |
|
"""Tests that CAPE is zero with no LFC.""" |
| 447 |
|
p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar |
| 448 |
|
temperature = np.array([22.2, 24.6, 22., 20.4, 18., -10.]) * units.celsius |
| 449 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 450 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 451 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 452 |
|
assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6) |
| 453 |
|
assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6) |
|
@@ 561-573 (lines=13) @@
|
| 558 |
|
rh[1, :] = 40. |
| 559 |
|
rh[2, :] = 80. |
| 560 |
|
rh[3, :] = 100. |
| 561 |
|
relh = rh * units.percent |
| 562 |
|
isentlev = 296. * units.kelvin |
| 563 |
|
isentprs = isentropic_interpolation(isentlev, lev, tmpk, relh) |
| 564 |
|
truerh = 100. * units.percent |
| 565 |
|
assert_almost_equal(isentprs[1], truerh, 3) |
| 566 |
|
|
| 567 |
|
|
| 568 |
|
def test_isentropic_pressure_interp(): |
| 569 |
|
"""Test calculation of isentropic pressure function.""" |
| 570 |
|
lev = [100000., 95000., 90000., 85000.] * units.Pa |
| 571 |
|
tmp = np.ones((4, 5, 5)) |
| 572 |
|
tmp[0, :] = 296. |
| 573 |
|
tmp[1, :] = 292. |
| 574 |
|
tmp[2, :] = 290 |
| 575 |
|
tmp[3, :] = 288. |
| 576 |
|
tmpk = tmp * units.kelvin |
|
@@ 525-537 (lines=13) @@
|
| 522 |
|
rh[2, :] = 40. |
| 523 |
|
rh[3, :] = 20. |
| 524 |
|
relh = rh * units.percent |
| 525 |
|
tmpk = tmp * units.kelvin |
| 526 |
|
isentlev = [296.] * units.kelvin |
| 527 |
|
isentprs = isentropic_interpolation(isentlev, lev, tmpk, relh) |
| 528 |
|
truerh = 100. * units.percent |
| 529 |
|
assert_almost_equal(isentprs[1], truerh, 3) |
| 530 |
|
|
| 531 |
|
|
| 532 |
|
def test_isentropic_pressure_tmp_out(): |
| 533 |
|
"""Test calculation of isentropic pressure function, temperature output.""" |
| 534 |
|
lev = [100000., 95000., 90000., 85000.] * units.Pa |
| 535 |
|
tmp = np.ones((4, 5, 5)) |
| 536 |
|
tmp[0, :] = 296. |
| 537 |
|
tmp[1, :] = 292. |
| 538 |
|
tmp[2, :] = 290. |
| 539 |
|
tmp[3, :] = 288. |
| 540 |
|
tmpk = tmp * units.kelvin |
|
@@ 489-501 (lines=13) @@
|
| 486 |
|
tmp[2, :] = 290 |
| 487 |
|
tmp[3, :] = 288. |
| 488 |
|
tmpk = tmp * units.kelvin |
| 489 |
|
isentlev = [296.] * units.kelvin |
| 490 |
|
isentprs = isentropic_interpolation(isentlev, lev, tmpk) |
| 491 |
|
trueprs = 1000. * units.hPa |
| 492 |
|
assert_almost_equal(isentprs[0].shape, (1, 5, 5), 3) |
| 493 |
|
assert_almost_equal(isentprs[0], trueprs, 3) |
| 494 |
|
|
| 495 |
|
|
| 496 |
|
def test_isentropic_pressure_p_increase(): |
| 497 |
|
"""Test calculation of isentropic pressure function, p increasing order.""" |
| 498 |
|
lev = [85000, 90000., 95000., 100000.] * units.Pa |
| 499 |
|
tmp = np.ones((4, 5, 5)) |
| 500 |
|
tmp[0, :] = 288. |
| 501 |
|
tmp[1, :] = 290. |
| 502 |
|
tmp[2, :] = 292. |
| 503 |
|
tmp[3, :] = 296. |
| 504 |
|
tmpk = tmp * units.kelvin |
|
@@ 453-465 (lines=13) @@
|
| 450 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 451 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 452 |
|
assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6) |
| 453 |
|
assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6) |
| 454 |
|
|
| 455 |
|
|
| 456 |
|
def test_find_append_zero_crossings(): |
| 457 |
|
"""Tests finding and appending zero crossings of an x, y series.""" |
| 458 |
|
x = np.arange(11) * units.hPa |
| 459 |
|
y = np.array([3, 2, 1, -1, 2, 2, 0, 1, 0, -1, 2]) * units.degC |
| 460 |
|
x2, y2 = _find_append_zero_crossings(x, y) |
| 461 |
|
|
| 462 |
|
x_truth = np.array([0., 1., 2., 2.5, 3., 3.33333333, 4., 5., |
| 463 |
|
6., 7., 8., 9., 9.33333333, 10.]) * units.hPa |
| 464 |
|
y_truth = np.array([3, 2, 1, 0, -1, 0, 2, 2, 0, 1, 0, -1, 0, 2]) * units.degC |
| 465 |
|
assert_array_almost_equal(x2, x_truth, 6) |
| 466 |
|
assert_almost_equal(y2, y_truth, 6) |
| 467 |
|
|
| 468 |
|
|