2017-09-04 81 views
-1

我有一個程序處理現有的FITS文件(xbulge-w1.fits),並將處理後的圖像保存到新的FITS(w1_resampled.fits)。我想將原始標題複製到新的標題中,以便它們處於相同的座標(即星系)。
我想用下面的代碼來做到這一點:從一個FITS文件複製空間中的標題從一個FITS文件到新創建的FITS文件

# 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條評論列出工作職能的程序,它只是我遇到問題的標題。當我在DS9打開w1_resampled.fits,頭部包含

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頭複製的數據。
如何將數據從一個標題複製到另一個標題?

+0

看(http://docs.astropy.org/en/stable/io/fits/api/files.html#astropy.io.fits。 writeto):'fits.writeto'的第二個參數是* data *,而不是頭。 – Evert

+0

類似地,['fits.getdata'](http://docs.astropy.org/en/stable/io/fits/api/files.html#astropy.io.fits.getdata)返回一個2元組的' (data,header)';你只把它分配給'header',所以我很驚訝你可以用字典形式使用'header',因爲它是一個元組。也許這行在你的實際代碼中有'fits.getheader'? – Evert

回答

-1

哦,我明白了。我太過於複雜了。這就是我需要做的:在[文件]

# 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) 
相關問題