|
@@ 410-418 (lines=9) @@
|
| 407 |
|
y_truth = np.array([3, 2, 1, 0, -1, 0, 2, 2, 0, 1, 0, -1, 0, 2]) * units.degC |
| 408 |
|
assert_array_almost_equal(x2, x_truth, 6) |
| 409 |
|
assert_almost_equal(y2, y_truth, 6) |
| 410 |
|
|
| 411 |
|
|
| 412 |
|
def test_most_unstable_parcel(): |
| 413 |
|
"""Tests calculating the most unstable parcel.""" |
| 414 |
|
levels = np.array([1000., 959., 867.9]) * units.mbar |
| 415 |
|
temperatures = np.array([18.2, 22.2, 17.4]) * units.celsius |
| 416 |
|
dewpoints = np.array([19., 19., 14.3]) * units.celsius |
| 417 |
|
ret = most_unstable_parcel(levels, temperatures, dewpoints, depth=100 * units.hPa) |
| 418 |
|
assert_almost_equal(ret[0], 959.0 * units.hPa, 6) |
| 419 |
|
assert_almost_equal(ret[1], 22.2 * units.degC, 6) |
| 420 |
|
assert_almost_equal(ret[2], 19.0 * units.degC, 6) |
| 421 |
|
|
|
@@ 386-394 (lines=9) @@
|
| 383 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 384 |
|
assert_almost_equal(cape, 0.08750805 * units('joule / kilogram'), 6) |
| 385 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 386 |
|
|
| 387 |
|
|
| 388 |
|
def test_cape_cin_no_lfc(): |
| 389 |
|
"""Tests that CAPE is zero with no LFC.""" |
| 390 |
|
p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar |
| 391 |
|
temperature = np.array([22.2, 24.6, 22., 20.4, 18., -10.]) * units.celsius |
| 392 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 393 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 394 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 395 |
|
assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6) |
| 396 |
|
assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6) |
| 397 |
|
|
|
@@ 179-186 (lines=8) @@
|
| 176 |
|
"""Test LCL calculation convergence failure.""" |
| 177 |
|
with pytest.raises(RuntimeError): |
| 178 |
|
lcl(1000. * units.mbar, 30. * units.degC, 20. * units.degC, max_iters=2) |
| 179 |
|
|
| 180 |
|
|
| 181 |
|
def test_lfc_basic(): |
| 182 |
|
"""Test LFC calculation.""" |
| 183 |
|
levels = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar |
| 184 |
|
temperatures = np.array([22.2, 14.6, 12., 9.4, 7., -49.]) * units.celsius |
| 185 |
|
dewpoints = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 186 |
|
l = lfc(levels, temperatures, dewpoints) |
| 187 |
|
assert_almost_equal(l[0], 727.468 * units.mbar, 2) |
| 188 |
|
assert_almost_equal(l[1], 9.705 * units.celsius, 2) |
| 189 |
|
|