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

Con*_*orG 4 image crop astronomy fits astropy

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

kef*_*ich 6

你可以做这种裁剪astropy.io.fits,虽然它不是微不足道的.由于默认astropy.io.fits使用内存映射,它应该能够处理任意大的文件(在一些实际限制内).如果您需要非python解决方案,请查看此处了解有关邮票创建的详细信息.

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())
Run Code Online (Sandbox Code Playgroud)

另请参阅此pull请求,该请求实现了一个便利Cutout2D功能,尽管在astropy的已发布版本中尚未提供此功能.它的用法可以在文档中看到,修改为包含WCS:

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

还有更多的例子在这里

  • 问题和答案已经很老了,所以我只想补充一点,Cutout2D 长期以来一直处于 astropy 的稳定分支中,因此有关稳定的文档,请参见此处:https://docs.astropy.org/en/stable/api /astropy.nddata.utils.Cutout2D.html (2认同)