def test_get_layer_float32(): """Test that get_layer works properly with float32 data.""" p = np.asarray([ 940.85083008, 923.78851318, 911.42022705, 896.07220459, 876.89404297, 781.63330078 ], np.float32) * units('hPa') hgt = np.asarray([ 563.671875, 700.93817139, 806.88098145, 938.51745605, 1105.25854492, 2075.04443359 ], dtype=np.float32) * units.meter true_p_layer = np.asarray([ 940.85083008, 923.78851318, 911.42022705, 896.07220459, 876.89404297, 831.86472819 ], np.float32) * units('hPa') true_hgt_layer = np.asarray([ 563.671875, 700.93817139, 806.88098145, 938.51745605, 1105.25854492, 1549.8079 ], dtype=np.float32) * units.meter p_layer, hgt_layer = get_layer(p, hgt, heights=hgt, depth=1000. * units.meter) assert_array_almost_equal(p_layer, true_p_layer, 4) assert_array_almost_equal(hgt_layer, true_hgt_layer, 4)
def test_get_layer(pressure, variable, heights, bottom, depth, interp, expected): """Tests get_layer functionality.""" p_layer, y_layer = get_layer(pressure, variable, heights=heights, bottom=bottom, depth=depth, interpolate=interp) assert_array_almost_equal(p_layer, expected[0], 5) assert_array_almost_equal(y_layer, expected[1], 5)
def test_get_layer_float32(flip_order): """Test that get_layer works properly with float32 data.""" p = np.asarray([940.85083008, 923.78851318, 911.42022705, 896.07220459, 876.89404297, 781.63330078], np.float32) * units('hPa') hgt = np.asarray([563.671875, 700.93817139, 806.88098145, 938.51745605, 1105.25854492, 2075.04443359], dtype=np.float32) * units.meter true_p_layer = np.asarray([940.85083008, 923.78851318, 911.42022705, 896.07220459, 876.89404297, 831.86472819], np.float32) * units('hPa') true_hgt_layer = np.asarray([563.671875, 700.93817139, 806.88098145, 938.51745605, 1105.25854492, 1549.8079], dtype=np.float32) * units.meter if flip_order: p = p[::-1] hgt = hgt[::-1] p_layer, hgt_layer = get_layer(p, hgt, heights=hgt, depth=1000. * units.meter) assert_array_almost_equal(p_layer, true_p_layer, 4) assert_array_almost_equal(hgt_layer, true_hgt_layer, 4)
def test_get_layer_invalid_depth_units(): """Tests that error is raised when depth has invalid units.""" p = np.arange(10) * units.hPa y = np.arange(9) * units.degC with pytest.raises(ValueError): get_layer(p, y, depth=400 * units.degC)
def test_get_layer_ragged_data(): """Tests that error is raised for unequal length pressure and data arrays.""" p = np.arange(10) * units.hPa y = np.arange(9) * units.degC with pytest.raises(ValueError): get_layer(p, y)
def test_get_layer(pressure, variable, heights, bottom, depth, interp, expected): """Test get_layer functionality.""" p_layer, y_layer = get_layer(pressure, variable, heights=heights, bottom=bottom, depth=depth, interpolate=interp) assert_array_almost_equal(p_layer, expected[0], 5) assert_array_almost_equal(y_layer, expected[1], 5)
def test_get_layer_invalid_depth_units(): """Test that an error is raised when depth has invalid units.""" p = np.arange(10) * units.hPa y = np.arange(9) * units.degC with pytest.raises(ValueError): get_layer(p, y, depth=400 * units.degC)
def test_get_layer_ragged_data(): """Test that an error is raised for unequal length pressure and data arrays.""" p = np.arange(10) * units.hPa y = np.arange(9) * units.degC with pytest.raises(ValueError): get_layer(p, y)