|
@@ 437-450 (lines=14) @@
|
| 434 |
|
"""Tests relative humidity from specific humidity.""" |
| 435 |
|
p = 1013.25 * units.mbar |
| 436 |
|
temperature = 20. * units.degC |
| 437 |
|
q = 0.012 |
| 438 |
|
rh = relative_humidity_from_specific_humidity(q, temperature, p) |
| 439 |
|
assert_almost_equal(rh, 82.7145 * units.percent, 3) |
| 440 |
|
|
| 441 |
|
|
| 442 |
|
def test_cape_cin(): |
| 443 |
|
"""Tests the basic CAPE and CIN calculation.""" |
| 444 |
|
p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar |
| 445 |
|
temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius |
| 446 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 447 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]) |
| 448 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 449 |
|
assert_almost_equal(cape, 58.0368212 * units('joule / kilogram'), 6) |
| 450 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 451 |
|
|
| 452 |
|
|
| 453 |
|
def test_cape_cin_no_el(): |
|
@@ 561-573 (lines=13) @@
|
| 558 |
|
tmp[3, :] = 288. |
| 559 |
|
tmpk = tmp * units.kelvin |
| 560 |
|
isentlev = [296.] * units.kelvin |
| 561 |
|
isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True) |
| 562 |
|
truetmp = 296. * units.kelvin |
| 563 |
|
assert_almost_equal(isentprs[1], truetmp, 3) |
| 564 |
|
|
| 565 |
|
|
| 566 |
|
def test_isentropic_pressure_p_increase_rh_out(): |
| 567 |
|
"""Test calculation of isentropic pressure function, p increasing order.""" |
| 568 |
|
lev = [85000., 90000., 95000., 100000.] * units.Pa |
| 569 |
|
tmp = np.ones((4, 5, 5)) |
| 570 |
|
tmp[0, :] = 288. |
| 571 |
|
tmp[1, :] = 290. |
| 572 |
|
tmp[2, :] = 292. |
| 573 |
|
tmp[3, :] = 296. |
| 574 |
|
tmpk = tmp * units.kelvin |
| 575 |
|
rh = np.ones((4, 5, 5)) |
| 576 |
|
rh[0, :] = 20. |
|
@@ 525-537 (lines=13) @@
|
| 522 |
|
tmp[3, :] = 296. |
| 523 |
|
tmpk = tmp * units.kelvin |
| 524 |
|
isentlev = [296.] * units.kelvin |
| 525 |
|
isentprs = isentropic_interpolation(isentlev, lev, tmpk) |
| 526 |
|
trueprs = 1000. * units.hPa |
| 527 |
|
assert_almost_equal(isentprs[0], trueprs, 3) |
| 528 |
|
|
| 529 |
|
|
| 530 |
|
def test_isentropic_pressure_adition_args(): |
| 531 |
|
"""Test calculation of isentropic pressure function, additional args.""" |
| 532 |
|
lev = [100000., 95000., 90000., 85000.] * units.Pa |
| 533 |
|
tmp = np.ones((4, 5, 5)) |
| 534 |
|
tmp[0, :] = 296. |
| 535 |
|
tmp[1, :] = 292. |
| 536 |
|
tmp[2, :] = 290. |
| 537 |
|
tmp[3, :] = 288. |
| 538 |
|
rh = np.ones((4, 5, 5)) |
| 539 |
|
rh[0, :] = 100. |
| 540 |
|
rh[1, :] = 80. |
|
@@ 489-501 (lines=13) @@
|
| 486 |
|
|
| 487 |
|
|
| 488 |
|
def test_most_unstable_parcel(): |
| 489 |
|
"""Tests calculating the most unstable parcel.""" |
| 490 |
|
levels = np.array([1000., 959., 867.9]) * units.mbar |
| 491 |
|
temperatures = np.array([18.2, 22.2, 17.4]) * units.celsius |
| 492 |
|
dewpoints = np.array([19., 19., 14.3]) * units.celsius |
| 493 |
|
ret = most_unstable_parcel(levels, temperatures, dewpoints, depth=100 * units.hPa) |
| 494 |
|
assert_almost_equal(ret[0], 959.0 * units.hPa, 6) |
| 495 |
|
assert_almost_equal(ret[1], 22.2 * units.degC, 6) |
| 496 |
|
assert_almost_equal(ret[2], 19.0 * units.degC, 6) |
| 497 |
|
|
| 498 |
|
|
| 499 |
|
def test_isentropic_pressure(): |
| 500 |
|
"""Test calculation of isentropic pressure function.""" |
| 501 |
|
lev = [100000., 95000., 90000., 85000.] * units.Pa |
| 502 |
|
tmp = np.ones((4, 5, 5)) |
| 503 |
|
tmp[0, :] = 296. |
| 504 |
|
tmp[1, :] = 292. |
|
@@ 453-465 (lines=13) @@
|
| 450 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 451 |
|
|
| 452 |
|
|
| 453 |
|
def test_cape_cin_no_el(): |
| 454 |
|
"""Tests that CAPE works with no EL.""" |
| 455 |
|
p = np.array([959., 779.2, 751.3, 724.3]) * units.mbar |
| 456 |
|
temperature = np.array([22.2, 14.6, 12., 9.4]) * units.celsius |
| 457 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4]) * units.celsius |
| 458 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 459 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 460 |
|
assert_almost_equal(cape, 0.08750805 * units('joule / kilogram'), 6) |
| 461 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 462 |
|
|
| 463 |
|
|
| 464 |
|
def test_cape_cin_no_lfc(): |
| 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 |