import copy


def firecrown_sanitize(config):
    """Sanitizes the input for firecrown, that is removes keys that firecrown
        doesn't recognize

    Parameters:
    ----------
    config : dict
        The dictinary that is ready for firecrown to munch on, but might have
        extra keys that are augur specific

    Returns:
    -------
    config : dict
       The input dictionary with unwanted keys removed
    """

    def delkeys(dic, keys):
        for k in keys:
            if k in dic:
                del dic[k]

    # removes keys that firecrown hates
    fconfig = copy.deepcopy(config)
    delkeys(fconfig, ["verbose", "augur"])
    for tcfg in fconfig["two_point"]["sources"].values():
        delkeys(
            tcfg,
            [
                "Nz_type",
                "Nz_center",
                "Nz_width",
                "Nz_sigmaz",
                "Nz_z0",
                "Nz_bin",
                "Nz_nbins",
                "Nz_alpha",
                "ellipticity_error",
                "number_density",
            ],
        )
    for tcfg in fconfig["two_point"]["statistics"].values():
        delkeys(tcfg, ["ell_edges", "theta_edges"])

    return fconfig