Fri*_*rub 5 python astronomy python-2.7 astropy
这个问题一直困扰着我.我正在尝试处理一些.fits文件形式的大量数据(大约11000x9000像素).我需要做的是为天空中的许多物体创建一个"放大的"RA/Dec坐标图(理想情况下使用astropy.wcs),其中包含来自一个拟合文件和灰度(或来自另一个的热图)的轮廓.
我的问题是,每当我从图像切片数据(到我感兴趣的区域)时,我就失去了与天空坐标的关联.这意味着切片图像不在正确的位置.
我已经改编了一个来自astropy文档的示例来为您节省数据的痛苦.(注意:我希望轮廓覆盖的区域比图像更多,无论解决方案是什么,都应该对两个数据都有效)
这是我遇到的代码:
from matplotlib import pyplot as plt
from astropy.io import fits
from astropy.wcs import WCS
from astropy.utils.data import download_file
import numpy as np
fits_file = 'http://data.astropy.org/tutorials/FITS-images/HorseHead.fits'
image_file = download_file(fits_file, cache=True)
hdu = fits.open(image_file)[0]
wmap = WCS(hdu.header)
data = hdu.data
fig = plt.figure()
ax1 = fig.add_subplot(121, projection=wmap)
ax2 = fig.add_subplot(122, projection=wmap)
# Scale input image
bottom, top = 0., 12000.
data = (((top - bottom) * (data - data.min())) / (data.max() - data.min())) + bottom
'''First plot'''
ax1.imshow(data, origin='lower', cmap='gist_heat_r')
# Now plot contours
xcont = np.arange(np.size(data, axis=1))
ycont = np.arange(np.size(data, axis=0))
colors = ['forestgreen','green', 'limegreen']
levels = [2000., 7000., 11800.]
ax1.contour(xcont, ycont, data, colors=colors, levels=levels, linewidths=0.5, smooth=16)
ax1.set_xlabel('RA')
ax1.set_ylabel('Dec')
ax1.set_title('Full image')
''' Second plot '''
datacut = data[250:650, 250:650]
ax2.imshow(datacut, origin='lower', cmap=cmap)
ax2.contour(xcont, ycont, data, colors=colors, levels=levels, linewidths=0.5, smooth=16)
ax2.set_xlabel('RA')
ax2.set_ylabel('')
ax2.set_title('Sliced image')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我尝试使用我的切片块的WCS坐标来解决这个问题,但我不确定我是否可以在任何地方通过它!
pixcoords = wcs.wcs_pix2world(zip(*[range(250,650),range(250,650)]),1)
Run Code Online (Sandbox Code Playgroud)
好消息是:你可以简单地切片astropy.WCS,这使你的任务相对平凡:
...
wmapcut = wmap[250:650, 250:650] # sliced here
datacut = data[250:650, 250:650]
ax2 = fig.add_subplot(122, projection=wmapcut) # use sliced wcs as projection
ax2.imshow(datacut, origin='lower', cmap='gist_heat_r')
# contour has to be sliced as well
ax2.contour(np.arange(datacut.shape[0]), np.arange(datacut.shape[1]), datacut,
colors=colors, levels=levels, linewidths=0.5, smooth=16)
...
Run Code Online (Sandbox Code Playgroud)
如果您的文件具有不同的WCS,则可能需要进行一些重新投影(请参阅例如重新投影)
| 归档时间: |
|
| 查看次数: |
1326 次 |
| 最近记录: |