Python中的Cutout2D

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

我正在对拥有的.fits图像使用Cutout2D,即使我指定对象中心的像素值,它也会切出一个完全不同的星系,当我检查其位置时,它甚至不在边界内我的原始图像。我的代码:

从astropy.io导入适合将numpy导入为np从astropy.table导入表导入操作系统从astropy.nddata.utils导入Cutout2D

#read in the fits file
insciim = fits.open('/home/myname/science_image.fits')
indata = fits.getdata('/home/myname/science_image.fits')

#Read in the header
hdr = fits.getheader('/home/myname/science_image.fits')
hdr["CTYPE1"] = "RA---TAN-SIP"
hdr["CTYPE2"] = "DEC--TAN-SIP"

#working from a copy to avoid overwriting the images
sciim = np.copy(insciim)
data = np.copy(indata)

xray_sources = '/home/myname/xray_catalogue.csv' #file path to the xray sources catalgoue 
xray_table = Table.read(xray_sources, format="ascii") #imports it as a table into python 

ID = np.array(xray_table['name']) #puts the IDs into a numpy array
ID.astype(str) #makes the array into strings

x_pix = np.array(xray_table['x_pixel'])
x_pix.astype(float)

y_pix = np.array(xray_table['y_pixel'])
y_pix.astype(float)

coordinates = merge(x_pix, y_pix)

size = (200, 200) #size I want the image to be in pixels

cut_test = Cutout2D(data, (8227, 2803), size)

img_hdu = fits.PrimaryHDU(cut_test.data, header=hdr)
img_hdu.writeto("/home/myname/test_galaxy.fits", overwrite=True) 

我想要的星系集中在(3480.136,2771.585)的像素值上,但是当我在DS9中查看切口时,它甚至不在我的原始图像上。有什么方法可以防止这种情况发生吗?

python astropy fits
1个回答
0
投票

可能与您的问题无关。但是,在剪切之后,您的标头应进行相应的更改-也就是说,原始标头不再适合您的新剪切数据。使用hdu.header.update(cutout.wcs.to_header())更新标题。

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