2016-08-02 5 views
4

이 문제는 당분간 저를 괴롭 히고 있습니다. 나는 (11000x9000 픽셀의 순서로) .fits 파일의 형태로되어있는 많은 양의 데이터를 처리하려고 노력 중이다. 내가해야할 일은 하나의 피트 파일에서 윤곽선을 가진 하늘의 많은 오브젝트와 그레이 스케일 (또는 다른 레이어에서 히트 맵)을 사용하여 RA/Dec 좌표 플롯 (이상적으로 astropy.wcs 사용)을 만드는 것입니다..stits 이미지를 트리밍하고 astropy Python에서 플로팅을위한 월드 좌표를 유지하려면 어떻게해야합니까?

내 문제는 내 관심 영역에 이미지에서 데이터를 슬라이스 때마다 나는 하늘 좌표와의 연관성을 잃는다는 것이다. 즉, 슬라이스 된 이미지가 올바른 위치에 있지 않음을 의미합니다.

저는 데이터의 고통을 덜어주기 위해 the astropy docs의 예를 적용했습니다.

:

The 'image' in the RH plot should be centered! 다음

내가에 문제가 있어요 코드입니다 : (주 나는 솔루션이 두 데이터에서 작동해야입니다 어떤 이미지보다 더 많은 영역을 커버하는 윤곽을 원하는)

from matplotlib import pyplot as plt 
from astropy.io import fits 
from astropy.wcs import WCS 
from astropy.utils.data import download_file 
import numpy as np 

fits_file = 'http://data.astropy.org/tutorials/FITS-images/HorseHead.fits' 
image_file = download_file(fits_file, cache=True) 
hdu = fits.open(image_file)[0] 
wmap = WCS(hdu.header) 
data = hdu.data 

fig = plt.figure() 
ax1 = fig.add_subplot(121, projection=wmap) 
ax2 = fig.add_subplot(122, projection=wmap) 
# Scale input image 
bottom, top = 0., 12000. 
data = (((top - bottom) * (data - data.min()))/(data.max() - data.min())) + bottom 


'''First plot''' 
ax1.imshow(data, origin='lower', cmap='gist_heat_r') 

# Now plot contours 
xcont = np.arange(np.size(data, axis=1)) 
ycont = np.arange(np.size(data, axis=0)) 
colors = ['forestgreen','green', 'limegreen'] 
levels = [2000., 7000., 11800.] 

ax1.contour(xcont, ycont, data, colors=colors, levels=levels, linewidths=0.5, smooth=16) 
ax1.set_xlabel('RA') 
ax1.set_ylabel('Dec') 
ax1.set_title('Full image') 

''' Second plot ''' 
datacut = data[250:650, 250:650] 
ax2.imshow(datacut, origin='lower', cmap=cmap) 
ax2.contour(xcont, ycont, data, colors=colors, levels=levels, linewidths=0.5, smooth=16) 

ax2.set_xlabel('RA') 
ax2.set_ylabel('') 
ax2.set_title('Sliced image') 
plt.show() 

내 슬라이스 덩어리의 WCS 코드를 사용하여이 문제를 해결해 보았습니다.하지만 어디에서나 통과 할 수 있는지 확실하지 않습니다.

pixcoords = wcs.wcs_pix2world(zip(*[range(250,650),range(250,650)]),1) 

답변

7

좋은 소식은 : 당신은 단순히 슬라이스 할 수 astropy.WCS뿐만 아니라 당신의 작업이 relativly 사소한 만드는 : 파일이 WCS 서로 다른 경우 당신이해야 할 수도 있습니다

... 

wmapcut = wmap[250:650, 250:650] # sliced here 
datacut = data[250:650, 250:650] 
ax2 = fig.add_subplot(122, projection=wmapcut) # use sliced wcs as projection 
ax2.imshow(datacut, origin='lower', cmap='gist_heat_r') 
# contour has to be sliced as well 
ax2.contour(np.arange(datacut.shape[0]), np.arange(datacut.shape[1]), datacut, 
      colors=colors, levels=levels, linewidths=0.5, smooth=16) 
... 

enter image description here

일부 재 투영 (예 : reproject 참조)

+0

이것은 매우 간결한 답변입니다 ('.shape [0]'을 사용하면 매우 멋지다!). 재 투척을 지적 해 주셔서 감사합니다. 나는 그것이 존재한다는 것을 몰랐고, 나는 확실히 그것을 필요로 할 것입니다! 하나 더; 이 위에 점을 흩어려고 노력하고 축 좌표가도에 매핑 된 것으로 나타나지 않습니다. 예를 들어, 'ax1.scatter (85.33, -2.5)'를 (85 20', -2 30 ')에 표시해야하지만 그것은 공정한 방법입니다. – FriskyGrub

+1

['pywcsgrid2'] (http://leejjoon.github.io/pywcsgrid2/)에는 좋은 재 투영 기능이 많이 있는데, 나는 'astropy.WCS'보다 조금 더 유연합니다. 곡선. 그것은 또한 합리적으로 잘 overplot 수 있습니다. – DathosPachy

+2

@FriskyGrub 분산 형 플롯을 오버레이하려면 다음 예제를 확인하십시오. https://wcsaxes.readthedocs.io/en/latest/overlays.html#world-coordinates. 나중에 문제가 발생하면 다른 질문을하십시오 (문제 당 하나의 문제를 다루는 것이 더 쉽습니다). 즉, 픽셀 좌표로 좌표를 지정하는 "변환"** 또는 **을 적용해야합니다. – MSeifert