core.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:goodman 作者: soar-telescope 项目源码 文件源码
def remove_conflictive_keywords(path, file_list):
    """Removes problematic keywords

    The blue camera has a set of keywords whose comments contain non-ascii
    characters, in particular the degree symbol. Those keywords are not
    needed in any stage of the data reduction therefore they are removed.
    The data will be overwritten with the keywords removed. The user will
    need to have backups of raw data.

    Notes:
        This function solves a problem with old data, new headers are compliant
        with the headers.

    Args:
        path (str): Path to the folder containing the files
        file_list (list): List of files to remove keywords

    """
    log_ccd.debug('Removing conflictive keywords in Blue Camera Headers')
    log_ccd.warning('Files will be overwritten')
    for blue_file in file_list:
        full_path = os.path.join(path, blue_file)
        log_ccd.debug('Processing file {:s}'.format(blue_file))
        try:
            data, header = fits.getdata(full_path,
                                        header=True,
                                        ignore_missing_end=True)

            keys_to_remove = ['PARAM0',
                              'PARAM61',
                              'PARAM62',
                              'PARAM63',
                              'NAXIS3']

            if data.ndim == 3:
                header['NAXIS'] = 2
                data = data[0]

                log_ccd.debug('Modified file to be 2D instead of 3D '
                              '(problematic)')

            for keyword in keys_to_remove:
                header.remove(keyword)

                log_ccd.debug('Removed conflictive keyword '
                              '{:s}'.format(keyword))

            log_ccd.debug('Updated headers')

            fits.writeto(full_path,
                         data,
                         header,
                         clobber=True)

        except KeyError as error:
            log_ccd.debug(error)


# spectroscopy specific functions
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号