コード例 #1
0
def test_rename_cmip6(xname, yname, zname, missing_dim):
    xlen, ylen, zlen = (10, 5, 6)
    ds = create_test_ds(xname, yname, zname, xlen, ylen, zlen)

    if missing_dim == "x":
        ds = ds.drop_dims(xname)
    elif missing_dim == "y":
        ds = ds.drop_dims(yname)
    elif missing_dim == "z":
        ds = ds.drop_dims(zname)

    ds_renamed = rename_cmip6(ds, cmip6_renaming_dict())
    assert set(ds_renamed.dims).issubset(set(["x", "y", "lev"]))
    if missing_dim not in ["x", "y"]:
        assert (set(ds_renamed.coords) - set(ds_renamed.dims)) == set(
            ["lon", "lat"])
    if not missing_dim == "x":
        assert xlen == len(ds_renamed.x)
    if not missing_dim == "y":
        assert ylen == len(ds_renamed.y)
    if not missing_dim == "z":
        assert zlen == len(ds_renamed.lev)

    # test exceptions and error handling
    with pytest.warns(UserWarning):
        ds_renamed = rename_cmip6(ds, {})

    with pytest.raises(ValueError):
        ds_renamed = rename_cmip6(ds, {"x": "x"})
コード例 #2
0
def test_rename_cmip6_worst_case(xname, yname):
    xlen, ylen, zlen = (10, 5, 6)
    ds = create_test_ds(xname, yname, "lev", xlen, ylen, zlen)

    print(ds.lon)
    # now rename only some of the coordinates to the correct naming
    ds = ds.assign_coords({
        "lon":
        ds.lon.reset_coords(drop=True).rename({
            xname: "x",
            yname: "y"
        })
    })
    ds_renamed = rename_cmip6(ds, cmip6_renaming_dict())

    assert set(ds_renamed.dims) == set(["x", "y", "lev"])
コード例 #3
0
def test_rename_cmip6(xname, yname, zname, missing_dim):
    xlen, ylen, zlen = (10, 5, 6)
    ds = create_test_ds(xname, yname, zname, xlen, ylen, zlen)

    if missing_dim == "x":
        ds = ds.isel({xname: 0}).squeeze()
    elif missing_dim == "y":
        ds = ds.isel({yname: 0}).squeeze()
    elif missing_dim == "z":
        ds = ds.isel({zname: 0}).squeeze()

    ds_renamed = rename_cmip6(ds, cmip6_renaming_dict())
    assert set(ds_renamed.dims).issubset(set(["x", "y", "lev"]))
    if not missing_dim == "x":
        assert xlen == len(ds_renamed.x)
    if not missing_dim == "y":
        assert ylen == len(ds_renamed.y)
    if not missing_dim == "z":
        assert zlen == len(ds_renamed.lev)
コード例 #4
0
def test_renaming_dict_entry_keys(model):
    if 'AWI' not in model:  # excluding the unstructured awi model
        # check that all required coords are there
        for co in required_coords:
            assert co in cmip6_renaming_dict()[model].keys()
        # check that (if present) x and y contain lon and lat entries
        if 'x' in cmip6_renaming_dict()[model].keys():
            assert 'lon' in cmip6_renaming_dict()[model]['x']
        if 'y' in cmip6_renaming_dict()[model].keys():
            assert 'lat' in cmip6_renaming_dict()[model]['y']

        # check that there are no extra entries
        assert len(
            set(cmip6_renaming_dict()[model].keys()) -
            set(required_coords + additonal_coords)) == 0
コード例 #5
0
def test_renaming_dict_entry_keys(model):
    if "AWI" not in model:  # excluding the unstructured awi model
        # check that all required coords are there
        for co in required_coords:
            assert co in cmip6_renaming_dict()[model].keys()
        # check that (if present) x and y contain lon and lat entries
        if "x" in cmip6_renaming_dict()[model].keys():
            assert "lon" in cmip6_renaming_dict()[model]["x"]
        if "y" in cmip6_renaming_dict()[model].keys():
            assert "lat" in cmip6_renaming_dict()[model]["y"]

        # check that there are no extra entries
        assert (len(
            set(cmip6_renaming_dict()[model].keys()) -
            set(required_coords + additonal_coords)) == 0)
コード例 #6
0
def test_rename_cmip6(xname, yname, zname, missing_dim):
    xlen, ylen, zlen = (10, 5, 6)
    ds = create_test_ds(xname, yname, zname, xlen, ylen, zlen)

    if missing_dim == "x":
        ds = ds.drop_dims(xname)
    elif missing_dim == "y":
        ds = ds.drop_dims(yname)
    elif missing_dim == "z":
        ds = ds.drop_dims(zname)

    ds_renamed = rename_cmip6(ds, cmip6_renaming_dict())
    assert set(ds_renamed.dims).issubset(set(["x", "y", "lev"]))
    if missing_dim not in ["x", "y"]:
        assert (set(ds_renamed.coords) - set(ds_renamed.dims)) == set(
            ["lon", "lat"])
    if not missing_dim == "x":
        assert xlen == len(ds_renamed.x)
    if not missing_dim == "y":
        assert ylen == len(ds_renamed.y)
    if not missing_dim == "z":
        assert zlen == len(ds_renamed.lev)
コード例 #7
0
def test_renaming_dict_keys():
    # check that each model has an entry
    rename_dict = cmip6_renaming_dict()
    assert set(list(rename_dict.keys())) == set(list(all_models))
コード例 #8
0
def test_renaming_dict_keys():
    # check that each model has an entry
    rename_dict = cmip6_renaming_dict()
    print(set(all_models) - set(rename_dict.keys()))
    assert set(all_models).issubset(set(rename_dict.keys()))