def _clean_kwargs(**kwargs):
    """
    Returns a kwargs dictionary containing only the ones used by astroscrappy.
    We have to do this because astroscrappy doesn't properly sanitize its
    input
    """
    cosmic_args = ['sigclip', 'sigfrac', 'onjlim', 'pssl', 'gain', 'readnoise',
                   'satlevel', 'niter', 'sepmed', 'cleantype', 'fsmode',
                   'psfmodel', 'psfwhm', 'psfsize', 'psfk', 'psfbeta',
                   'verbose']
    cosmic_kwargs = {k: kwargs[k] for k in kwargs if k in cosmic_args}
    return cosmic_kwargs