python - 如何使用 ccdproc 的 wcs_project 重新投影适合文件?
问题描述
我正在尝试堆叠一系列适合文件。我正在学习这个过程,我知道因为它们有不同的 wcs,所以我必须先调整它们的方向,然后再开始堆叠。我发现 ccdprocwcs_project
是一种合理处理此问题的方法。我试图遵循此页面上的最后一个示例。话虽如此,当我尝试运行时wcs_project
,我不断收到 wcs 错误。
我的代码如下:
target_image = fits.open(list_of_fits_files[1])
target_wcs = WCS(target_image[0]).celestial
reprojected = []
for fits_file in list_of_fits_files:
img = fits.open(fits_file)
new_image = wcs_project(img, target_wcs)
reprojected.append(new_image)
我的错误信息如下:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-189-2f3f9f278991> in <module>
9 for fits_file in list_of_fits_files:
10 img = fits.open(fits_file)
---> 11 new_image = wcs_project(img, target_wcs)
12 reprojected.append(new_image)
/anaconda3/lib/python3.6/site-packages/ccdproc/log_meta.py in wrapper(*args, **kwd)
90 # Grab the logging keyword, if it is present.
91 log_result = kwd.pop(_LOG_ARGUMENT, True)
---> 92 result = func(*args, **kwd)
93
94 if not log_result:
/anaconda3/lib/python3.6/site-packages/ccdproc/core.py in wcs_project(ccd, target_wcs, target_shape, order)
922 from reproject import reproject_interp
923
--> 924 if not (ccd.wcs.is_celestial and target_wcs.is_celestial):
925 raise ValueError('one or both WCS is not celestial.')
926
AttributeError: 'HDUList' object has no attribute 'wcs'
我搞砸了什么?我一直在尝试阅读 ccdproc,但没有太多示例。或者,如果有人建议更好的堆叠方法,请告诉我。
解决方案
在您的代码中,您写道:
for fits_file in list_of_fits_files:
img = fits.open(fits_file)
new_image = wcs_project(img, target_wcs)
但是返回的对象fits.open
是一个HDUList
对象(因此错误AttributeError: 'HDUList' object has no attribute 'wcs'
),它是存储在单个 FITS 文件中的一个或多个 HDU 的列表。但是,wcs_project
需要一个CCDData
包含实际图像数据的对象(可能来自任何来源,在您的情况下恰好是 FITS 文件)。
CCDData
您可以使用直接从 FITS 文件中读取 a CCDData.read('/path/to/image.fits')
,因此您可能想要编写如下内容:
img = CCDData.read(fits_file)
new_image = wcs_project(img, target_wcs)
如果您的 FITS 文件包含一个图像,CCDData.read()
应该能够猜出您要加载哪个图像。如果它包含多个图像,您可能需要指定要读取的扩展名;当从 FITS 文件读取时,CCDData.read
所有参数都与低级函数相同fits_ccddata_reader
,例如用于指定要读取的扩展 HDU。在大多数情况下,您不需要这样做,这取决于数据是什么。
推荐阅读
- python - Python 创建一个包含多个文件的临时目录
- google-slides - 在 android 上点击谷歌幻灯片不再有效
- javascript - nw.js:
不出现,如何让它显示? - javascript - 无法从 LocalStorage Jquery 获取数组
- racket - 如何定义子表单
- python - 有没有办法从 Odoo 中的单元测试功能打印特定报告?
- compiler-errors - 我可以通过 ESLint 使用 prettier 和 tsconfig for JS 的引用来模拟静态类型语言吗
- filebeat - 使用 filebeat 处理器时出现“缺少或无效条件”错误
- blockchain - 如何在 rinkeby 和 ropsten 上获取测试令牌
- r - 如何在 data.table 中保留日期格式