首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将头从一个FITS文件复制到一个新创建的FITS文件

将头从一个FITS文件复制到一个新创建的FITS文件
EN

Stack Overflow用户
提问于 2017-09-04 00:06:49
回答 1查看 1.5K关注 0票数 0

我有一个处理现有的FITS文件(xbulge-w1.fits)的程序,并将处理后的图像保存到一个新的FITS (w1_resampled.fits)中。我想把标题从原始复制到新的,以便它们在相同的坐标(即银河)中。

我试图用以下代码来完成这个任务:

代码语言:javascript
复制
#   Open the FITS files as input image and mask
#   Process the images
#   Rescale image to galactic coordinates and display
#   Plot and save median filtered images as png, rescaled to galactic coordinates
#   Save as FITS files and close
#   Edit FITS headers to recenter images at galactic center
header = fits.getdata('xbulge-w1.fits', header=True)

header['COMMENT'] = 'Resampled with median filtered pixels'
header['IMAGEW'] = 877
header['IMAGEH'] = 901
header['WCSAXES'] = (2, 'Number of coordinate axes')
header['CRPIX1'] = 438.5
header['CRPIX2'] = 450.5                                                  
header['PC1_1'] = (-0.0333333333333, 'Coordinate transformation matrix element')
header['PC2_2'] = (0.0333333333333, 'Coordinate transformation matrix element')
header['CDELT1'] = (1., '[deg] Coordinate increment at reference point')
header['CDELT2'] = (1., '[deg] Coordinate increment at reference point')
header['CUNIT1'] = ('deg     ', 'Units of coordinate increment and value')
header['CUNIT2'] = ('deg     ', 'Units of coordinate increment and value')
header['CTYPE1'] = 'GLON-AIT'                
header['CTYPE2'] = 'GLAT-AIT'                                                            
header['CRVAL1'] = (0., '[deg] Coordinate value at reference point')
header['CRVAL2'] = (0., '[deg] Coordinate value at reference point')
header['LONPOLE'] = (0., '[deg] Native longitude of celestial pole')
header['LATPOLE'] = (90., '[deg] Native latitude of celestial pole')
header['RADESYS'] = ('ICRS    ', 'Equatorial coordinate system')

fits.writeto('w1_resampled.fits', header, overwrite=True)
fits.writeto('w2_resampled.fits', header, overwrite=True)

hdulist.close()
hdulist2.close()
hdulist3.close()

前5条注释列出了程序中的工作函数,这只是我很难理解的标题。当我在w1_resampled.fits中打开DS9时,标题包含

代码语言:javascript
复制
SIMPLE  =                    T / conforms to FITS standard                      
BITPIX  =                  -32 / array data type                                
NAXIS   =                    2 / number of array dimensions                     
NAXIS1  =                  877                                                  
NAXIS2  =                  901                                                  
EXTEND  =                    T                                                  
END  

而不是从xbulge-w1.fits头复制的数据。

如何将数据从一个标头复制到另一个头?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-04 21:26:18

哦,我明白了。我搞得太复杂了。我要做的就是:

代码语言:javascript
复制
#   Edit FITS headers to recenter images at galactic center
w1_resampled_header = w1header
w2_resampled_header = w2header

w1_resampled_header['CRPIX1'] = w1header['CRPIX1']
w1_resampled_header['CRPIX2'] = w1header['CRPIX2']
w2_resampled_header['CRPIX1'] = w2header['CRPIX1']
w2_resampled_header['CRPIX2'] = w2header['CRPIX2']                                                

#   Save as FITS files and close
fits.writeto('w1_resampled.fits',
             w1_resampled,
             w1_resampled_header,
             overwrite = True)
fits.writeto('w2_resampled.fits',
             w2_resampled,
             w2_resampled_header,
             overwrite = True)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46028846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档