如何使用 Astropy 在 Python 中对齐 SDSS 天空图像?

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

我在对齐 SDSS 天空图像时遇到问题。我从 SDDS 下载了许多图像带。问题是我不知道如何对齐它们。

它们以 FITS 格式存储。每个图像由 5 个波段组成(

r
i
g
u
z
)。不幸的是,每张照片的方向略有不同,因此为了使用它们,我需要先将它们对齐。它们指向的信息存储在 FITS 标头中,坐标在
WCS - World Coordinate System
:

中给出
CRPIX1  float   X of reference pixel
CRPIX2  float   Y of reference pixel
CRVAL1  float   RA of reference pixel (deg)
CRVAL2  float   Dec of reference pixel (deg)
CD1_1   float   RA deg per column pixel
CD1_2   float   RA deg per row pixel
CD2_1   float   Dec deg per column pixel
CD2_2   float   Dec deg per row pixel

目标是将 4 个波段移动到与其他波段完全相同的点(例如

r
)。

我正在使用

Python
astropy
包来解决这个问题。到目前为止,这是我的代码:

from astropy.io import fits
from astropy.nddata import Cutout2D
from astropy.wcs import WCS
from astropy.coordinates import SkyCoord
from astropy.visualization import make_lupton_rgb
import matplotlib.pyplot as plt
from scipy.ndimage import shift, rotate

def align_spectral_bands(list_of_bands):
    g, i, r, u, z = tuple(sorted_list_of_bands)

    ref_file = fits.open(r)
    ref_header = ref_file[0].header
    ref_wcs = WCS(ref_header)
    ref_data = ref_file[0].data

    rotated_g = align_single(ref_header, g)
    rotated_r = align_single(ref_header, r)
    rotated_u = align_single(ref_header, u)
    rotated_i = align_single(ref_header, i)
    rotated_z = align_single(ref_header, z)

    <rest of function>
    

def align_single(ref_header, band_path):
    ref_wcs = WCS(ref_header)

    curr_band_file = fits.open(band_path)
    curr_header = curr_band_file[0].header
    curr_wcs = WCS(curr_header)
    curr_data = curr_band_file[0].data
    curr_shape = curr_data.shape

    target_ra = ref_header['CRVAL1']
    target_dec = ref_header['CRVAL2']

    target_coord = SkyCoord(target_ra, target_dec, unit='deg')
    cutout = Cutout2D(curr_data, target_coord, curr_data.shape, wcs=curr_wcs)
    cutout_header = cutout.wcs.to_header()
    res = cutout.data


    curr_band_file.close()

    return res

当我运行代码,然后使用

i
r
g
带绘制图像时,我得到如下结果。

第一张图像显示对齐后的数据,第二张图像显示未对齐的数据。正如你所看到的,结果比原始数据要好,但仍然不完美。

我尝试使用

np.roll()
和像
cutout_header['CRPIX1'] - ref_header['CRPIX1']
一样计算的偏移量,但这只会使情况变得更糟。

python astropy world-coordinates
1个回答
0
投票

我认为你正在寻找重投影。如果您有 WCS 协调 reproject 包!应该有帮助。

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