Beispiel #1
0
def test_none(file_path, pl_levels):
    test_cases = [
        TestCase(query=QueryOption("u10m", "single", None),
                 expected_level_type="level",
                 expected_level=0),
        TestCase(query=QueryOption("tiw", None, None),
                 expected_level_type="level",
                 expected_level=0)
    ]

    for test_case in test_cases:
        field = load_field_from_file(file_path, **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert field.coords[
            test_case.expected_level_type] == test_case.expected_level

    test_cases = [
        TestCase(query=QueryOption("t", "pl", None),
                 expected_level_type="pl",
                 expected_level=pl_levels),
        TestCase(query=QueryOption("tsoil", None, None),
                 expected_level_type="level",
                 expected_level=[1000, 925, 850, 700]),
    ]

    for test_case in test_cases:
        field = load_field_from_file(file_path, **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert np.array_equal(
            np.sort(field.coords[test_case.expected_level_type].values),
            np.sort(test_case.expected_level))
Beispiel #2
0
def test_list(file_path, modelvar_file_path):
    test_cases = [
        TestCase(query=QueryOption("t", "pl", [1000, 850, 500]),
                 expected_level_type="pl",
                 expected_level=[1000, 850, 500]),
        TestCase(query=QueryOption("tsoil", "index", [0, 1, 2, 3]),
                 expected_level_type="level",
                 expected_level=[1000, 925, 850, 700])
    ]

    for test_case in test_cases:
        field = load_field_from_file(file_path, **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert np.array_equal(
            np.sort(field.coords[test_case.expected_level_type].values),
            np.sort(test_case.expected_level))

    test_cases = [
        TestCase(query=QueryOption("pip", "ml", [1, 20, 30, 50]),
                 expected_level_type="ml",
                 expected_level=[1, 20, 30, 50]),
        TestCase(query=QueryOption("qc", "index", [0, 1, 2, 3]),
                 expected_level_type="level",
                 expected_level=[1, 2, 3, 4])
    ]

    for test_case in test_cases:
        field = load_field_from_file(modelvar_file_path,
                                     **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert np.array_equal(
            np.sort(field.coords[test_case.expected_level_type].values),
            np.sort(test_case.expected_level))
Beispiel #3
0
def test_embedded_name(file_path, modelvar_file_path):
    test_cases = [
        TestCase(query=QueryOption("t", "pl", 250),
                 expected_level_type="pl",
                 expected_level=250),
        TestCase(query=QueryOption("u", "pl", 0.5),
                 expected_level_type="pl",
                 expected_level=0.5)
    ]

    for test_case in test_cases:
        field = load_field_from_file(file_path, **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert field.coords[
            test_case.expected_level_type] == test_case.expected_level

    test_cases = [
        TestCase(query=QueryOption("u", "ml", 30),
                 expected_level_type="ml",
                 expected_level=30),
        TestCase(query=QueryOption("w", "ml", 50),
                 expected_level_type="ml",
                 expected_level=50)
    ]

    for test_case in test_cases:
        field = load_field_from_file(modelvar_file_path,
                                     **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert field.coords[
            test_case.expected_level_type] == test_case.expected_level
Beispiel #4
0
def test_number(file_path):
    test_cases = [
        TestCase(query=QueryOption("t", "pl", 850),
                 expected_level_type="pl",
                 expected_level=850),
        TestCase(query=QueryOption("h", "pl", 500.0),
                 expected_level_type="pl",
                 expected_level=500.0),
        TestCase(query=QueryOption("q2", "index", 0),
                 expected_level_type="level",
                 expected_level=1000),
        TestCase(query=QueryOption("u", "index", 1),
                 expected_level_type="level",
                 expected_level=925),
        TestCase(query=QueryOption("tsoil", "index", 2),
                 expected_level_type="level",
                 expected_level=850),
        TestCase(query=QueryOption("q2m", "single", 0),
                 expected_level_type="level",
                 expected_level=0),
    ]

    for test_case in test_cases:
        field = load_field_from_file(file_path, **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert field.coords[
            test_case.expected_level_type] == test_case.expected_level
Beispiel #5
0
def test_string(file_path):
    test_cases = [
        TestCase(query=QueryOption("t", "pl", 850)),
        TestCase(query=QueryOption("u", "pl", 0.1)),
        TestCase(query=QueryOption("lcc", None, None)),
    ]

    for test_case in test_cases:
        field = load_field_from_file(
            file_path,
            **asdict(test_case.query)
        )
        assert field is not None
        assert field.name == test_case.query.parameter
Beispiel #6
0
def test_none(file_path):
    test_cases = [
        TestCase(query=QueryOption("tcc", None, None),
                 expected_level_type="level",
                 expected_level=0),
        TestCase(query=QueryOption("t2mx", None, None),
                 expected_level_type="level",
                 expected_level=0)
    ]

    for test_case in test_cases:
        field = load_field_from_file(file_path, **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert field.coords[
            test_case.expected_level_type] == test_case.expected_level
Beispiel #7
0
def test_index(file_path):
    test_cases = [
        TestCase(query=QueryOption("tsoil", "index", 0),
                 expected_level_type="level",
                 expected_level=1000),
        TestCase(query=QueryOption("tsoil", "index", 1),
                 expected_level_type="level",
                 expected_level=925),
        TestCase(query=QueryOption("tsoil", "index", 2),
                 expected_level_type="level",
                 expected_level=850),
        TestCase(query=QueryOption("tsoil", "index", 3),
                 expected_level_type="level",
                 expected_level=700)
    ]

    for test_case in test_cases:
        field = load_field_from_file(file_path, **asdict(test_case.query))
        assert field is not None
        assert field.name == test_case.query.parameter
        assert field.coords[
            test_case.expected_level_type] == test_case.expected_level