def rename_phony_dims(ds):
    """rename phony dims by the given DimensionNames

    Scans all variables in ds for the DimensionNames attribute and
    use this to decode "phony_dim_<num>" dimensions.

    Parameters
    ----------
    ds : {xarray.Dataset, xarray.DataArray}
        input dataset

    Returns
    -------
    {xarray.Dataset, xarray.DataArray}
        renamed dataset
    """

    ds = ds.copy()
    for key, var in ds.items():
        names = var.DimensionNames.split(",")
        ds[key] = var.rename(
            {phony_dim: name for phony_dim, name in zip(var.dims, names) if phony_dim.startswith("phony_dim")}
        )
        if hasattr(ds[key], "CodeMissingValue"):
            cmv = ds[key].CodeMissingValue
            int_cmv = int(cmv.split(".")[0])
            if ds[key].min() == int_cmv:
                print(f"Note: Variable `{key}' uses {int_cmv:d} instead if {cmv} as missing value.")
                ds[key] = ds[key].where(ds[key] != int_cmv)

    return ds