通过 'pizza wedge' 切片合并两个 FITS 文件?

Combine two FITS files by taking a 'pizza wedge' slice?

我想合并两个 FITS 文件,方法是从一个文件中取出一个片段并将其插入另一个文件。切片将基于从中心像素测量的角度,请参见下面的示例图像:

这可以使用 Astropy 完成吗?网站上有很多关于合并 FITS 的问题,但其中大部分与简单地将两个文件相加有关,而不是像这样合并段。

这是一种推荐的方法:

1.Read 在你的两个文件中

假设数据在 ImageHDU 数据数组中..

from astropy.io import fits

# read the numpy arrays out of the files 
# assuming they contain ImageHDUs
data1 = fits.getdata('file1.fits')
data2 = fits.getdata('file2.fits')

2。切出部分并将它们放入一个新的numpy数组

为新文件中的所需部分构建 indices1 和 indices2...一个简单的 numpy 索引,用于将缺失的部分填充到新的 numpy 数组中。

受到启发后https://whosebug.com/a/18354475/15531842

答案中定义的 sector_mask 函数使用 angular 个切片获取每个数组的索引。

mask = sector_mask(data1.shape, centre=(53,38), radius=100, angle_range=(280,340))
indices1 = ~mask
indices2 = mask

然后可以使用这些索引将数据传输到新数组中。

import numpy as np
newdata = np.zeros_like(data1)
newdata[indices1] = data1[indices1]
newdata[indices2] = data2[indices2]

如果坐标系是众所周知的,那么可以使用 astropy 的 Cutout2D class,尽管我无法弄清楚如何充分使用它。目前尚不清楚它是否可以根据给定的示例执行 angular 切片。请参见天文示例 https://docs.astropy.org/en/stable/nddata/utils.html#d-cutout-using-an-angular-size

3a。然后将新数组作为新文件写出。

如果新文件中不需要特殊的 header 信息。然后带有新图像的 numpy 数组可以用一行 astropy 代码写出到 FITS 文件。

# this is an easy way to write a numpy array to FITS file
# no header information is carried over
fits.writeto('file_combined.fits', data=newdata)

3b。将 FITS header 信息转移到新文件

如果希望携带 header 信息,则可以从 numpy 数组构建 ImageHDU 并将所需的 header 作为字典包含在内。

img_hdu = fits.ImageHDU(data=newdata, header=my_header_dict)

hdu_list = fits.HDUList()
hdu_list.append(fits.PrimaryHDU())
hdu_list.append(img_hdu)

hdu_list.writeto('file_combined.fits')