使用指定边界裁剪非常大的适合文件

问题描述 投票:0回答:1

我有一个大的适合文件(超过 30,000 x 30,000)像素。 IRAF 无法处理这种尺寸的图像。如何裁剪这种大小的文件,同时保留正确的标头信息,就像 IRAF 在使用其标准裁剪模式时所做的那样?

image crop astronomy fits astropy
1个回答
10
投票

您可以使用

astropy.io.fits
进行此类裁剪,尽管这还不是微不足道的。由于
astropy.io.fits
默认使用 内存映射,因此它应该能够处理任意大的文件(在一些实际限制内)。如果您需要非 Python 解决方案,请查看 here 了解有关邮票创建的详细信息。

from astropy.io import fits
from astropy import wcs
f = fits.open('file.fits')
w = wcs.WCS(f[0].header)
newf = fits.PrimaryHDU()
newf.data = f[0].data[100:-100,100:-100]
newf.header = f[0].header
newf.header.update(w[100:-100,100:-100].to_header())

还有一个方便的

Cutout2D
功能。它的用法可以在文档中看到,修改为包括WCS:

from astropy.nddata import Cutout2D
position = (49.7, 100.1)
shape = (40, 50)
cutout = Cutout2D(f[0].data, position, shape, wcs=w)

还有更多示例这里

© www.soinside.com 2019 - 2024. All rights reserved.