Пример #1
0
def test_embedded_level_name(file_path, modelvar_file_path):
    """
    embedded level type:

    * pl
    * surface
    * ml
    """
    test_cases = [
        TestCase(query=QueryOption(parameter="t", level_type="pl", level=850)),
        TestCase(
            query=QueryOption(parameter="t", level_type="sfc", level=None)),
    ]
    for test_case in test_cases:
        message = load_message_from_file(file_path, **asdict(test_case.query))
        assert message is not None
        eccodes.codes_release(message)

    test_cases = [
        TestCase(query=QueryOption(parameter="u", level_type="ml", level=10))
    ]
    for test_case in test_cases:
        message = load_message_from_file(modelvar_file_path,
                                         **asdict(test_case.query))
        assert message is not None
        eccodes.codes_release(message)
Пример #2
0
def test_type_of_level(file_path):
    test_cases = [
        TestCase(query=QueryOption(
            parameter="t", level_type="isobaricInhPa", level=850)),
        TestCase(query=QueryOption(
            parameter="t", level_type="isobaricInPa", level=50)),
        TestCase(query=QueryOption(
            parameter="asnow", level_type="surface", level=None)),
        TestCase(query=QueryOption(
            parameter="tmax", level_type="heightAboveGround", level=2)),
        TestCase(query=QueryOption(
            parameter="lcc", level_type="nominalTop", level=None)),
        TestCase(query=QueryOption(
            parameter="tciwv", level_type="atmosphere", level=None)),
        TestCase(query=QueryOption(
            parameter="prmsl", level_type="meanSea", level=None)),
        TestCase(query=QueryOption(parameter="t",
                                   level_type="depthBelowLandLayer",
                                   level={
                                       "first_level": 0,
                                       "second_level": 0.1
                                   }))
    ]

    for test_case in test_cases:
        message = load_message_from_file(file_path, **asdict(test_case.query))
        assert message is not None
        eccodes.codes_release(message)
Пример #3
0
def test_short_name(file_path):
    test_cases = [
        TestCase(query=QueryOption(parameter="t", level_type="pl", level=850))
    ]
    for test_case in test_cases:
        message = load_message_from_file(file_path, **asdict(test_case.query))
        assert message is not None
        eccodes.codes_release(message)
Пример #4
0
def test_scalar(file_path, modelvar_file_path):
    test_cases = [
        TestCase(
            query=QueryOption(parameter="t", level_type="pl", level=1.5),
            expected_keys=dict(typeOfLevel="isobaricInhPa", level=1)
        ),
        TestCase(
            query=QueryOption(parameter="t", level_type="isobaricInhPa", level=850),
            expected_keys=dict(typeOfLevel="isobaricInhPa", level=850)
        ),
        TestCase(
            query=QueryOption(parameter="tmax", level_type="heightAboveGround", level=2),
            expected_keys=dict(typeOfLevel="heightAboveGround", level=2)
        )
    ]

    for test_case in test_cases:
        message = load_message_from_file(
            file_path,
            **asdict(test_case.query)
        )
        assert message is not None
        for key, expected_value in test_case.expected_keys.items():
            assert eccodes.codes_get(message, key) == expected_value

        eccodes.codes_release(message)

    test_cases = [
        TestCase(
            query=QueryOption(parameter="u", level_type={"typeOfFirstFixedSurface": 131}, level=10),
            expected_keys=dict(typeOfFirstFixedSurface=131, level=10)
        )
    ]
    for test_case in test_cases:
        message = load_message_from_file(
            modelvar_file_path,
            **asdict(test_case.query)
        )
        assert message is not None
        for key, expected_value in test_case.expected_keys.items():
            assert eccodes.codes_get(message, key, ktype=int) == expected_value

        eccodes.codes_release(message)
Пример #5
0
def test_grib_key(modelvar_file_path):
    test_cases = [
        TestCase(query=QueryOption(parameter="u",
                                   level_type={"typeOfFirstFixedSurface": 131},
                                   level=10))
    ]
    for test_case in test_cases:
        message = load_message_from_file(modelvar_file_path,
                                         **asdict(test_case.query))
        assert message is not None
        eccodes.codes_release(message)
Пример #6
0
def test_numbers(file_path):
    """
    雷达组合反射率
    """
    test_cases = [
        TestCase(query=QueryOption(parameter={
            "discipline": 0,
            "parameterCategory": 16,
            "parameterNumber": 225,
        },
                                   level_type="pl",
                                   level=850))
    ]
    for test_case in test_cases:
        message = load_message_from_file(file_path, **asdict(test_case.query))
        assert message is not None
        eccodes.codes_release(message)
Пример #7
0
def test_dict(file_path):
    test_cases = [
        TestCase(
            query=QueryOption(parameter="vwsh", level_type="heightAboveGroundLayer", level={"first_level": 1000, "second_level": 0}),
            expected_keys=dict(typeOfLevel="heightAboveGroundLayer", level=1000)
        ),
        TestCase(
            query=QueryOption(parameter="t", level_type="depthBelowLandLayer", level={"first_level": 0.1, "second_level": 0.4}),
            expected_keys=dict(typeOfLevel="depthBelowLandLayer", level=0)
        )
    ]
    for test_case in test_cases:
        message = load_message_from_file(
            file_path,
            **asdict(test_case.query)
        )
        assert message is not None
        for key, expected_value in test_case.expected_keys.items():
            assert eccodes.codes_get(message, key) == expected_value

        eccodes.codes_release(message)
Пример #8
0
def test_none_level(file_path):
    test_cases = [
        TestCase(
            query=QueryOption(parameter="t", level_type="pl", level=None),
            expected_keys=dict(typeOfLevel="isobaricInhPa", level=1000),
        ),
        TestCase(
            query=QueryOption(parameter="vwsh", level_type="heightAboveGroundLayer", level=None),
            expected_keys=dict(typeOfLevel="heightAboveGroundLayer", level=1000)
        )
    ]
    for test_case in test_cases:
        message = load_message_from_file(
            file_path,
            **asdict(test_case.query)
        )
        assert message is not None
        for key, expected_value in test_case.expected_keys.items():
            assert eccodes.codes_get(message, key) == expected_value

        eccodes.codes_release(message)
Пример #9
0
def test_embedded_short_name(file_path):
    test_cases = [
        TestCase(query=QueryOption("DEPR", "pl", 850)),
        TestCase(query=QueryOption(
            {
                "discipline": 0,
                "parameterCategory": 0,
                "parameterNumber": 7,
            }, "pl", 850)),
    ]

    messages = []
    for test_case in test_cases:
        message = load_message_from_file(file_path, **asdict(test_case.query))
        assert message is not None
        messages.append(message)

    assert eccodes.codes_get(messages[0], "count") == eccodes.codes_get(
        messages[1], "count")

    for message in messages:
        eccodes.codes_release(message)