コード例 #1
0
def test_wrong_threshold(multi_cloud_cube):
    """Test the process function with multi_cloud_cube where user defined
        diagnostic_threshold variable does not match threshold available in
        the cube"""
    wrong_threshold = 0.235
    plugin = FieldTexture(
        nbhood_radius=NB_RADIUS,
        textural_threshold=TEXT_THRESH,
        diagnostic_threshold=wrong_threshold,
    )
    with pytest.raises(ValueError, match=str(wrong_threshold)):
        plugin.process(multi_cloud_cube)
コード例 #2
0
def test_metadata_attributes(multi_cloud_cube, model_config):
    """Test that the metadata attributes in the output cube follows expected
        conventions after that plugin has completed"""
    expected_attributes = UK_ENS_ATTRS.copy()
    if model_config:
        fieldtexture_args = {"model_id_attr": "mosg__model_configuration"}
    else:
        expected_attributes.pop("mosg__model_configuration")
        fieldtexture_args = {}
    plugin = FieldTexture(
        nbhood_radius=NB_RADIUS,
        textural_threshold=TEXT_THRESH,
        diagnostic_threshold=DIAG_THRESH,
        **fieldtexture_args,
    )
    result = plugin.process(multi_cloud_cube)
    assert result.attributes == expected_attributes
コード例 #3
0
def ftex_plugin(
    nbhood_radius=NB_RADIUS,
    textural_threshold=TEXT_THRESH,
    diagnostic_threshold=DIAG_THRESH,
):
    """Create an instance of the FieldTexture plugin with standard arguments"""
    fieldtexture_instance = FieldTexture(
        nbhood_radius,
        textural_threshold,
        diagnostic_threshold,
    )
    return fieldtexture_instance
コード例 #4
0
def process(
    cube: cli.inputcube,
    *,
    nbhood_radius: float = 20000.0,
    textural_threshold: float = 0.05,
    diagnostic_threshold: float = 0.8125,
    model_id_attr: str = None,
):
    """Calculates field texture for a given neighbourhood radius.

       The field texture is an assessment of the transitions/edges within a
       neighbourhood of a grid point to indicate whether the field is rough
       or smooth.

    Args:
        cube (iris.cube.Cube):
            Cloud area fraction or precipitation rate cube where transitions between
            precipitating or cloudy regions and non-precipitating or cloudless
            regions will be diagnosed. Defaults set assuming cloud area fraction
            cube.

        nbhood_radius (float):
            The neighbourhood radius in metres within which the number of potential
            transitions should be calculated. This forms the denominator in the
            calculation of the ratio of actual to potential transitions that indicates a
            field's texture. A larger radius should be used for diagnosing larger-scale
            textural features. Default value set to 10000.0 assuming cloud area fraction
            cube.

        textural_threshold (float):
            A unit-less threshold value that defines the ratio value above which
            the field is considered rough and below which the field is considered
            smoother. Default value set to 0.05 assuming cloud area fraction cube.

        diagnostic_threshold (float):
            The diagnostic threshold for which field texture will be calculated.
            A ValueError is raised if this threshold is not present on the input
            cube. Default value set to 0.8125 corresponding to 6 oktas, assuming
            cloud area fraction cube.

        model_id_attr (str):
            Name of the attribute used to identify the source model for
            blending.

    Returns:
        iris.cube.Cube:
            A field texture cube containing values between 0 and 1, where 0
            indicates no transitions and 1 indicates the maximum number of
            possible transitions has been achieved, within the neighbourhood of
            the grid point.
    """

    from improver.precipitation_type.field_texture import FieldTexture

    field_texture = FieldTexture(
        nbhood_radius,
        textural_threshold,
        diagnostic_threshold,
        model_id_attr=model_id_attr,
    )(cube)
    return field_texture