|
@@ 410-418 (lines=9) @@
|
| 407 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 408 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 409 |
|
assert_almost_equal(cape, 0.0 * units('joule / kilogram'), 6) |
| 410 |
|
assert_almost_equal(cin, 0.0 * units('joule / kilogram'), 6) |
| 411 |
|
|
| 412 |
|
|
| 413 |
|
def test_find_append_zero_crossings(): |
| 414 |
|
"""Tests finding and appending zero crossings of an x, y series.""" |
| 415 |
|
x = np.arange(11) * units.hPa |
| 416 |
|
y = np.array([3, 2, 1, -1, 2, 2, 0, 1, 0, -1, 2]) * units.degC |
| 417 |
|
x2, y2 = _find_append_zero_crossings(x, y) |
| 418 |
|
|
| 419 |
|
x_truth = np.array([0., 1., 2., 2.5, 3., 3.33333333, 4., 5., |
| 420 |
|
6., 7., 8., 9., 9.33333333, 10.]) * units.hPa |
| 421 |
|
y_truth = np.array([3, 2, 1, 0, -1, 0, 2, 2, 0, 1, 0, -1, 0, 2]) * units.degC |
|
@@ 386-394 (lines=9) @@
|
| 383 |
|
temperature = np.array([22.2, 14.6, 12., 9.4, 7., -38.]) * units.celsius |
| 384 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius |
| 385 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]) |
| 386 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
| 387 |
|
assert_almost_equal(cape, 58.0368212 * units('joule / kilogram'), 6) |
| 388 |
|
assert_almost_equal(cin, -89.8073512 * units('joule / kilogram'), 6) |
| 389 |
|
|
| 390 |
|
|
| 391 |
|
def test_cape_cin_no_el(): |
| 392 |
|
"""Tests that CAPE works with no EL.""" |
| 393 |
|
p = np.array([959., 779.2, 751.3, 724.3]) * units.mbar |
| 394 |
|
temperature = np.array([22.2, 14.6, 12., 9.4]) * units.celsius |
| 395 |
|
dewpoint = np.array([19., -11.2, -10.8, -10.4]) * units.celsius |
| 396 |
|
parcel_prof = parcel_profile(p, temperature[0], dewpoint[0]).to('degC') |
| 397 |
|
cape, cin = cape_cin(p, temperature, dewpoint, parcel_prof) |
|
@@ 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 |
|
|
|
@@ 364-372 (lines=9) @@
|
| 361 |
|
assert_almost_equal(rh, 81.7219 * units.percent, 3) |
| 362 |
|
|
| 363 |
|
|
| 364 |
|
def test_mixing_ratio_from_specific_humidity(): |
| 365 |
|
"""Tests mixing ratio from specific humidity.""" |
| 366 |
|
q = 0.012 |
| 367 |
|
w = mixing_ratio_from_specific_humidity(q) |
| 368 |
|
assert_almost_equal(w, 0.01215, 3) |
| 369 |
|
|
| 370 |
|
|
| 371 |
|
def test_rh_specific_humidity(): |
| 372 |
|
"""Tests relative humidity from specific humidity.""" |
| 373 |
|
p = 1013.25 * units.mbar |
| 374 |
|
temperature = 20. * units.degC |
| 375 |
|
q = 0.012 |