示例#1
0
def test_basic(cloud_texture_cube):
    """Test output type and metadata"""
    expected_dims = ["projection_y_coordinate", "projection_x_coordinate"]
    expected_aux = {
        coord.name()
        for coord in cloud_texture_cube.coords(dim_coords=False)
    }
    expected_attributes = {
        "institution": "unknown",
        "source": "IMPROVER",
        "title": "unknown",
    }
    cubes = [cloud_texture_cube]
    result = ShowerCondition()(CubeList(cubes))
    dim_coords = [coord.name() for coord in result.coords(dim_coords=True)]
    aux_coords = {coord.name() for coord in result.coords(dim_coords=False)}

    assert result.name() == "precipitation_is_showery"
    assert result.units == "1"
    assert result.shape == (3, 3)
    assert result.data.dtype == FLOAT_DTYPE
    assert aux_coords == expected_aux
    assert dim_coords == expected_dims
    assert result.attributes == expected_attributes
示例#2
0
def process(*cubes: cli.inputcube):
    """
    Determine the shower condition from global or UK data depending on input fields

    Args:
        cubes (iris.cube.CubeList):
            List of cubes to input into shower diagnosis. These should
            contain probabilities of EITHER cloud texture from a high-resolution model,
            OR cloud area fraction and convective ratio from a low-resolution model.

    Returns:
        iris.cube.Cube:
            Binary (0/1) "precipitation is showery"

    """
    from iris.cube import CubeList
    from improver.precipitation_type.shower_condition import ShowerCondition

    return ShowerCondition()(CubeList(cubes))
示例#3
0
def test_missing_threshold(cloud_texture_cube):
    """Test error if the required threshold is missing"""
    cubes = [cloud_texture_cube[0]]
    with pytest.raises(ValueError, match="contain required threshold"):
        ShowerCondition()(CubeList(cubes))
示例#4
0
def test_too_few_inputs(cloud_cube):
    """Test error if too few inputs are provided"""
    cubes = [cloud_cube]
    with pytest.raises(ValueError, match="Incomplete inputs"):
        ShowerCondition()(CubeList(cubes))
示例#5
0
def test_too_many_inputs(cloud_texture_cube, cloud_cube, conv_ratio_cube):
    """Test default behaviour using UK tree if all fields are provided"""
    cubes = [cloud_texture_cube, cloud_cube, conv_ratio_cube]
    result = ShowerCondition()(CubeList(cubes))
    np.testing.assert_allclose(result.data, EXPECTED_UK)
示例#6
0
def test_global_tree(cloud_cube, conv_ratio_cube):
    """Test correct shower diagnosis using global decision tree"""
    cubes = [cloud_cube, conv_ratio_cube]
    result = ShowerCondition()(CubeList(cubes))
    np.testing.assert_allclose(result.data, EXPECTED_GLOBAL)
示例#7
0
def test_uk_tree(cloud_texture_cube):
    """Test correct shower diagnosis using UK decision tree"""
    cubes = [cloud_texture_cube]
    result = ShowerCondition()(CubeList(cubes))
    np.testing.assert_allclose(result.data, EXPECTED_UK)