|
@@ 212-222 (lines=11) @@
|
| 209 |
|
assert_almost_equal(l[1], 10.6232 * units.celsius, 2) |
| 210 |
|
|
| 211 |
|
|
| 212 |
|
def test_lfc_equals_lcl(): |
| 213 |
|
"""Test LFC when there is no cap and the lfc is equal to the lcl.""" |
| 214 |
|
levels = np.array([912., 905.3, 874.4, 850., 815.1, 786.6, 759.1, |
| 215 |
|
748., 732.2, 700., 654.8]) * units.mbar |
| 216 |
|
temperatures = np.array([29.4, 28.7, 25.2, 22.4, 19.4, 16.8, |
| 217 |
|
14.3, 13.2, 12.6, 11.4, 7.1]) * units.celsius |
| 218 |
|
dewpoints = np.array([18.4, 18.1, 16.6, 15.4, 13.2, 11.4, 9.6, |
| 219 |
|
8.8, 0., -18.6, -22.9]) * units.celsius |
| 220 |
|
l = lfc(levels, temperatures, dewpoints) |
| 221 |
|
assert_almost_equal(l[0], 777.0333 * units.mbar, 2) |
| 222 |
|
assert_almost_equal(l[1], 15.8714 * units.celsius, 2) |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
def test_saturation_mixing_ratio(): |
|
@@ 199-209 (lines=11) @@
|
| 196 |
|
assert assert_nan(lfc_temperature, temperatures.units) |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
def test_lfc_inversion(): |
| 200 |
|
"""Test LFC when there is an inversion to be sure we don't pick that.""" |
| 201 |
|
levels = np.array([963., 789., 782.3, 754.8, 728.1, 727., 700., |
| 202 |
|
571., 450., 300., 248.]) * units.mbar |
| 203 |
|
temperatures = np.array([25.4, 18.4, 17.8, 15.4, 12.9, 12.8, |
| 204 |
|
10., -3.9, -16.3, -41.1, -51.5]) * units.celsius |
| 205 |
|
dewpoints = np.array([20.4, 0.4, -0.5, -4.3, -8., -8.2, -9., |
| 206 |
|
-23.9, -33.3, -54.1, -63.5]) * units.celsius |
| 207 |
|
l = lfc(levels, temperatures, dewpoints) |
| 208 |
|
assert_almost_equal(l[0], 706.0103 * units.mbar, 2) |
| 209 |
|
assert_almost_equal(l[1], 10.6232 * units.celsius, 2) |
| 210 |
|
|
| 211 |
|
|
| 212 |
|
def test_lfc_equals_lcl(): |
|
@@ 410-418 (lines=9) @@
|
| 407 |
|
assert_almost_equal(y2, y_truth, 6) |
| 408 |
|
|
| 409 |
|
|
| 410 |
|
def test_most_unstable_parcel(): |
| 411 |
|
"""Tests calculating the most unstable parcel.""" |
| 412 |
|
levels = np.array([1000., 959., 867.9]) * units.mbar |
| 413 |
|
temperatures = np.array([18.2, 22.2, 17.4]) * units.celsius |
| 414 |
|
dewpoints = np.array([19., 19., 14.3]) * units.celsius |
| 415 |
|
ret = most_unstable_parcel(levels, temperatures, dewpoints, depth=100 * units.hPa) |
| 416 |
|
assert_almost_equal(ret[0], 959.0 * units.hPa, 6) |
| 417 |
|
assert_almost_equal(ret[1], 22.2 * units.degC, 6) |
| 418 |
|
assert_almost_equal(ret[2], 19.0 * units.degC, 6) |
| 419 |
|
|
|
@@ 386-394 (lines=9) @@
|
| 383 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 384 |
|
|
| 385 |
|
|
| 386 |
|
def test_cape_cin_no_lfc(): |
| 387 |
|
"""Tests that CAPE is zero with no LFC.""" |
| 388 |
|
p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar |
| 389 |
|
temperature = np.array([22.2, 24.6, 22., 20.4, 18., -10.]) * units.celsius |
| 390 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 391 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 392 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 393 |
|
assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6) |
| 394 |
|
assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6) |
| 395 |
|
|
| 396 |
|
|
| 397 |
|
def test_find_append_zero_crossings(): |
|
@@ 375-383 (lines=9) @@
|
| 372 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 373 |
|
|
| 374 |
|
|
| 375 |
|
def test_cape_cin_no_el(): |
| 376 |
|
"""Tests that CAPE works with no EL.""" |
| 377 |
|
p = np.array([959., 779.2, 751.3, 724.3]) * units.mbar |
| 378 |
|
temperature = np.array([22.2, 14.6, 12., 9.4]) * units.celsius |
| 379 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4]) * units.celsius |
| 380 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 381 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 382 |
|
assert_almost_equal(cape, 0.08750805 * units('joule / kilogram'), 6) |
| 383 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 384 |
|
|
| 385 |
|
|
| 386 |
|
def test_cape_cin_no_lfc(): |
|
@@ 364-372 (lines=9) @@
|
| 361 |
|
assert_almost_equal(rh, 82.7145 * units.percent, 3) |
| 362 |
|
|
| 363 |
|
|
| 364 |
|
def test_cape_cin(): |
| 365 |
|
"""Tests the basic CAPE and CIN calculation.""" |
| 366 |
|
p = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar |
| 367 |
|
temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius |
| 368 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 369 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 370 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 371 |
|
assert_almost_equal(cape, 58.0368212 * units('joule / kilogram'), 6) |
| 372 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 373 |
|
|
| 374 |
|
|
| 375 |
|
def test_cape_cin_no_el(): |
|
@@ 179-186 (lines=8) @@
|
| 176 |
|
lcl(1000. * units.mbar, 30. * units.degC, 20. * units.degC, max_iters=2) |
| 177 |
|
|
| 178 |
|
|
| 179 |
|
def test_lfc_basic(): |
| 180 |
|
"""Test LFC calculation.""" |
| 181 |
|
levels = np.array([959., 779.2, 751.3, 724.3, 700., 269.]) * units.mbar |
| 182 |
|
temperatures = np.array([22.2, 14.6, 12., 9.4, 7., -49.]) * units.celsius |
| 183 |
|
dewpoints = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 184 |
|
l = lfc(levels, temperatures, dewpoints) |
| 185 |
|
assert_almost_equal(l[0], 727.468 * units.mbar, 2) |
| 186 |
|
assert_almost_equal(l[1], 9.705 * units.celsius, 2) |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
def test_no_lfc(): |