def write_params_to_yml(kwargs, output_file='grizli.auto_script.yml',
    verbose=True):
    """
    Write grizli parameters to a file
    """
    import time
    import yaml
    import grizli
    try:
        phot_apertures = kwargs['multiband_catalog_args']['phot_apertures']
        kwargs['multiband_catalog_args']['phot_apertures'] = None
    except:
        phot_apertures = None
    try:
        filter_kernel = kwargs['multiband_catalog_args']['detection_params'][
            'filter_kernel']
        kwargs['multiband_catalog_args']['detection_params']['filter_kernel'
            ] = None
    except:
        filter_kernel = None
    fp = open(output_file, 'w')
    fp.write('# {0}\n'.format(time.ctime()))
    fp.write('# Grizli version = {0}\n'.format(grizli.__version__))
    for k in kwargs:
        try:
            d = {k: kwargs[k].copy()}
        except:
            d = {k: kwargs[k]}
        yaml.dump(d, stream=fp, default_flow_style=False)
    fp.close()
    if phot_apertures is not None:
        kwargs['multiband_catalog_args']['phot_apertures'] = phot_apertures
    if filter_kernel is not None:
        kwargs['multiband_catalog_args']['detection_params']['filter_kernel'
            ] = filter_kernel
    if verbose:
        print('\n# Write parameters to {0}\n'.format(output_file))
