|
@@ 333-340 (lines=8) @@
|
| 330 |
|
p = np.arange(10) * units.hPa |
| 331 |
|
y = np.arange(9) * units.degC |
| 332 |
|
with pytest.raises(ValueError): |
| 333 |
|
get_layer(p, y) |
| 334 |
|
|
| 335 |
|
|
| 336 |
|
def test_get_layer_invalid_depth_units(): |
| 337 |
|
"""Tests that error is raised when depth has invalid units.""" |
| 338 |
|
p = np.arange(10) * units.hPa |
| 339 |
|
y = np.arange(9) * units.degC |
| 340 |
|
with pytest.raises(ValueError): |
| 341 |
|
get_layer(p, y, depth=400 * units.degC) |
| 342 |
|
|
| 343 |
|
|
|
@@ 323-330 (lines=8) @@
|
| 320 |
|
1105.25854492, 1549.8079], dtype=np.float32) * units.meter |
| 321 |
|
|
| 322 |
|
p_layer, hgt_layer = get_layer(p[::-1], hgt[::-1], heights=hgt[::-1], |
| 323 |
|
depth=1000. * units.meter) |
| 324 |
|
assert_array_almost_equal(p_layer, true_p_layer, 4) |
| 325 |
|
assert_array_almost_equal(hgt_layer, true_hgt_layer, 4) |
| 326 |
|
|
| 327 |
|
|
| 328 |
|
def test_get_layer_ragged_data(): |
| 329 |
|
"""Tests that error is raised for unequal length pressure and data arrays.""" |
| 330 |
|
p = np.arange(10) * units.hPa |
| 331 |
|
y = np.arange(9) * units.degC |
| 332 |
|
with pytest.raises(ValueError): |
| 333 |
|
get_layer(p, y) |
|
@@ 343-352 (lines=10) @@
|
| 340 |
|
with pytest.raises(ValueError): |
| 341 |
|
get_layer(p, y, depth=400 * units.degC) |
| 342 |
|
|
| 343 |
|
|
| 344 |
|
@pytest.fixture |
| 345 |
|
def layer_test_data(): |
| 346 |
|
"""Provide test data for testing of layer bounds.""" |
| 347 |
|
pressure = np.arange(1000, 10, -100) * units.hPa |
| 348 |
|
temperature = np.linspace(25, -50, len(pressure)) * units.degC |
| 349 |
|
return pressure, temperature |
| 350 |
|
|
| 351 |
|
|
| 352 |
|
@pytest.mark.parametrize('pressure, variable, heights, bottom, depth, interp, expected', [ |
| 353 |
|
(layer_test_data()[0], layer_test_data()[1], None, None, 150 * units.hPa, True, |
| 354 |
|
(np.array([1000, 900, 850]) * units.hPa, |
| 355 |
|
np.array([25.0, 16.666666, 12.62262]) * units.degC)), |