我正在尝试根据Header
提供的纬度拼接拟合数组。但是,凭借我对Python的知识和astropy
的文档,我似乎无法这样做。我的代码是这样的:
from astropy.io import fits
import numpy as np
Wise1 = fits.open('Image1.fits')
im1 = Wise1[0].data
im1 = np.where(im1 > *latitude1, 0, im1)
newhdu = fits.PrimaryHDU(im1)
newhdulist = fits.HDUList([newhdu])
newhdulist.writeto('1b1_Bg_Removed_2.fits')
此处latitude1
将是以度为单位的值,在从标头调用后识别。所以我需要完成两件事:
答案 0 :(得分:3)
我想通过" splice"你是说"切出"或者"裁剪",根据您显示的示例。
astropy.nddata
有routine for world-coordinate-system-based (i.e., lat/lon or ra/dec) cutouts
但是,在您处理的简单情况下,您只需要每个像素的坐标。通过制作WCS来做到这一点:
from astropy import wcs
w = wcs.WCS(Wise1[0].header)
xx,yy = np.indices(im.shape)
lon,lat = w.wcs_pix2world(xx,yy,0)
newim = im[lat > my_lowest_latitude]
但是如果您想保留标题信息,那么使用剪切工具会更好,因为您不必手动管理它。
from astropy.nddata import Cutout2D
from astropy import coordinates
from astropy import units as u
# example coordinate - you'll have to figure one out that's in your map
center = coordinates.SkyCoord(mylon*u.deg, mylat*u.deg, frame='fk5')
# then make an array cutout
co = nddata.Cutout2D(im, center, size=[0.1,0.2]*u.arcmin, wcs=w)
# create a new FITS HDU
hdu = fits.PrimaryHDU(data=co.data, header=co.wcs.to_header())
# write to disk
hdu.writeto('cropped_file.fits')
示例用例位于astropy documentation。