关于python:如何叠加两个.fits图像,每个图像具有不同的WCS /分辨率?

How do I overlay two .fits images each with different WCS / resolutions?

我正在尝试从对象的一个??图像绘制轮廓,例如在波段A中,在该对象的较低分辨率图像的顶部,例如波段Z。

这两张图片都很大,因此我必须为每个图片创建一个2D抠图。但是,波段Z中的图像比波段A中的像素少得多。因此,当我尝试在同一图中绘制它们时,波段Z中的图像根据像素尺寸绘制,因此在左下角非常小图(请参见下面链接中的图)。我需要两幅图像都是根据天文角度尺寸绘制的,而不是像素。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import numpy as np
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
from astropy.io import fits
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy.nddata import Cutout2D
from reproject import reproject_interp

# Read in .fits images and WCS information
image_a = fits.open("image_a.fits")
image_z = fits.open("image_z.fits")
wcs_a = WCS(image_a.header).celestial
wcs_z = WCS(image_z.header).celestial

# Define object RA and DEC
obj_coords = SkyCoord(ra=135.19081*u.degree, dec=0.68991393*u.degree, frame='fk5')

# Create 2D cutouts of the object in each band in a 6 by 6 arcsec box
size = u.Quantity((6, 6), u.arcsec)
stamp_a = Cutout2D(image_a.data, obj_coords, size, wcs=wcs_a)
stamp_z = Cutout2D(image_z.data, obj_coords, size, wcs=wcs_z)

# Plot the the stamp in band Z with contours from band A
ax = plt.subplot(projection = wcs_z)
plt.imshow(stamp_z.data, cmap='gray', origin='lower', alpha=1)
ax.contour(stamp_a.data, levels = [2*sigma,3*sigma,4*sigma,5*sigma],
colors='green')

结果图(单击我)

我也看到了一些有关使用reproject的信息。我尝试过,但我不认为我完全理解它,因为它只会导致一个很小的像素。这是我尝试的:

1
2
array, footprint = reproject_interp((stamp_a.data, wcs_a), image_z.header)
plt.imshow(array, origin='lower')

让我知道是否有任何我想回答的信息。在使用IDL几年之后,我上周刚切换到python,因此,如果它有点粗糙,我深表歉意。


如何使用重新投影的问题是您传递了(stamp_a.data, wcs_a),但是wcs_a是来自原始图像而不是来自图章的WCS。

您可以从Cutout2D图像中获得与您的图章相匹配的WCS对象。我认为更改为(stamp_a.data, stamp_a.wcs)将为您提供正确的结果。

您看过astropy.visualisation.wcsaxes吗?您可以在此处看到一个示例,该示例如何绘制图像,并使用不同的WCS对第二张图像进行轮廓绘制。如果这适合您,它将比手动使用Cutout2Dreproject更简单。

我不确定性能。如果图像很大,您可能仍希望像现在一样进行剪裁。如果内存/执行时间不是问题,则可以绘制整个图像,然后使用wcsaxes设置所需的范围(请参阅其教程文档)。

是否自己重新投影还是将matplotlibastropy.visualisation.wcsaxes放在幕后的问题也是一个问题。直接使用reproject会增加一些代码,更加复杂,但是可以使您对所使用的确切重投影方法(例如插值或较慢的通量守恒reproject_exact)有更多的控制,并且可能更容易完全理解正在发生的事情。