【问题标题】:Combining Astropy FITS files?结合 Astropy FITS 文件?
【发布时间】:2020-03-03 16:16:54
【问题描述】:

所以我保存了一些 Astropy 拟合表(它们都具有相同的格式、列名等)。我想把所有这些 fit 文件合并成一个大的 fit 文件。

目前,我正在使用 astropy.io 的追加和更新功能,但无济于事。

任何帮助将不胜感激。

【问题讨论】:

    标签: python append concatenation astropy fits


    【解决方案1】:

    所以我现在可以使用它了。这就是我本质上所做的:

    # Read in the fits table you want to append 
    table = Table.read(input_file, format='fits')
    
    # Read in the large table you want to append to 
    base_table = Table.read('base_file.fits', format='fits')
    
    # Use Astropy's 'vstack' function and overwrite the file 
    concat_table = vstack([base_table,append_table])
    concat_table.write('base_file.fits', format='fits', overwrite=True)
    

    就我而言,每个表的所有列都是相同的。所以我只是遍历了所有的 fit 文件,并一次添加一个。可能还有其他方法可以做到这一点,但我发现这是最简单的。

    【讨论】:

    • 使用 table.vstack 是组合 FITS 表的正确方法。
    • 能否请您也发布您的循环?
    • 我使用了一个 bash 脚本来遍历文件,但是你可以很容易地在 python 中完成它。如果您想在 python 中遍历文件,请使用模块 os,并获取正确的文件,我通常使用 glob 模块。类似于:" for f in glob(os.path.join(folder_with_files), '*.fits'): ....."
    猜你喜欢
    • 2022-11-21
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    相关资源
    最近更新 更多