def merge_rate_distortions(results, rate_cols, distortion_cols):
    """
    Adds a `distortion_type` and `rate_type` index by melting over `distortion_cols` and `rate_cols`
    respectively. The values columns are resepectively `distortion_val`and `rate_val`.
    """
    results = results.melt(
        id_vars=rate_cols,
        value_vars=distortion_cols,
        ignore_index=False,
        var_name="distortion_type",
        value_name="distortion_val",
    ).set_index(["distortion_type"], append=True)

    results = results.melt(
        id_vars="distortion_val",
        value_vars=rate_cols,
        ignore_index=False,
        var_name="rate_type",
        value_name="rate_val",
    ).set_index(["rate_type"], append=True)
    return results