2013-08-05 3 views
4

나는 미친 듯이 문서를 검색해 왔으며이 문서에 대한 답을 찾을 수 없습니다.FITS 이미지에 WCS 좌표 지정

저는 파이썬에서 FITS 이미지를 생성 중이며 WCS 좌표를 이미지에 지정해야합니다. 포인트 소스를 알려진 카탈로그와 일치 시켜서이 작업을 수행하는 방법은 많이 있지만이 경우에는 먼지 맵을 생성하므로 포인트 소스 일치가 작동하지 않습니다 (가능한 한 멀리 말할 수 있음).

따라서 이미지는 2D Numpy 모양의 배열 (240,240)입니다. 그것은과 같이 작성 (x 및 y는 어떻게 든 작동 지정이 조금 이상하다 좌표)이야 : 모든 자체에서 잘 작동하는지

H, xedges, yedges = np.histogram2d(glat, glon, bins=[ybins, xbins], weights=Av) 
count, x, y = np.histogram2d(glat, glon, bins=[ybins, xbins]) 
H/=count 
hdu = pyfits.PrimaryHDU(H) 
hdu.writeto(filename) 

>>> print H.shape 
(240,240) 

. 은하 좌표를 할당하는 당신이해야 할 것 모두 같은 것입니다 같은 :

glon_coords = np.linspace(np.amin(glon), np.amax(glon), 240) 
glat_coords = np.linspace(np.amin(glat), np.amax(glat), 240) 

하지만이 FITS 이미지는이 좌표를 저장하는 방법을 이해하지 않는, 그래서 내가 그들을 작성하는 방법을 모르겠어요. SAO DS9에서도 할당 해 보았습니다 만 운은 없습니다. 이 좌표를 이미지에 할당하는 간단한 방법이 필요합니다.

도움을 주셔서 감사합니다.

답변

4

astropy을 사용 하시길 권합니다. 프로젝트 목적 상 astropy.wcs 패키지는 FITS WCS 헤더를 작성하는 데 도움을 줄 수 있으며 astropy.io.fits API는 기본적으로 현재 사용중인 패키지와 동일합니다. 또한 도움말 페이지가 우수하며 내가하려는 것은 WCS 구축 페이지를 귀하의 예에 맞게 번역하는 것입니다.

질문 : FITS는 각 픽셀에 좌표를 "태그 지정"하지 않습니다. 픽셀 룩업 테이블이나 그와 비슷한 것을 만들 수 있다고 가정합니다. 그러나 actual WCS은 X, Y 픽셀을 천체 좌표 (귀하의 경우에는 "은하계")로 변환합니다 (algorithmic). A nice page is here.

http://docs.astropy.org/en/latest/wcs/index.html#building-a-wcs-structure-programmatically

그리고 여기에 프로젝트에 대한 내 검증되지 않은 의사입니다 :

예 내가 당신을 가리킬 것이다는 여기

# untested code 

from __future__ import division # confidence high 

# astropy 
from astropy.io import fits as pyfits 
from astropy import wcs 

# your code 
H, xedges, yedges = np.histogram2d(glat, glon, bins=[ybins, xbins], weights=Av) 
count, x, y = np.histogram2d(glat, glon, bins=[ybins, xbins]) 
H/=count 

# characterize your data in terms of a linear translation from XY pixels to 
# Galactic longitude, latitude. 

# lambda function given min, max, n_pixels, return spacing, middle value. 
linwcs = lambda x, y, n: ((x-y)/n, (x+y)/2) 

cdeltaX, crvalX = linwcs(np.amin(glon), np.amax(glon), len(glon)) 
cdeltaY, crvalY = linwcs(np.amin(glat), np.amax(glat), len(glat)) 

# wcs code ripped from 
# http://docs.astropy.org/en/latest/wcs/index.html 

w = wcs.WCS(naxis=2) 

# what is the center pixel of the XY grid. 
w.wcs.crpix = [len(glon)/2, len(glat)/2] 

# what is the galactic coordinate of that pixel. 
w.wcs.crval = [crvalX, crvalY] 

# what is the pixel scale in lon, lat. 
w.wcs.cdelt = numpy.array([cdeltX, cdeltY]) 

# you would have to determine if this is in fact a tangential projection. 
w.wcs.ctype = ["GLON-TAN", "GLAT-TAN"] 

# write the HDU object WITH THE HEADER 
header = w.to_header() 
hdu = pyfits.PrimaryHDU(H, header=header) 
hdu.writeto(filename)