2016-11-07 79 views
3

我打开一个完整的地图如何在调整子图大小后更改标题?

from astropy.io import fits 
from astropy.wcs import wcs 

mapheader = fits.getheader(MapFile, 0) 
mapdata = fits.getdata(MapFile, 0) 
w = wcs.WCS(mapheader) 

和我从它 假设度 中心位于RA,DEC这可以通过使用CutOut2D

from astropy.nddata import Cutout2D 
from astropy import coordinates 
from astropy import units as u 

center = coordinates.SkyCoord(RA*u.deg, DEC*u.deg, frame='fk5') 
submap = Cutout2D(mapdata, center, size=16*u.pix, wcs=w) 
submapheader = submap.wcs.to_header() 

相关轻松完成一个平方子图不同的标题是它移动参考像素“CRPIX”

如果我调整图像的大小,例如,我做一个插值并从16个像素传递图像 至128像素

from scipy.misc import imresize 
newsubmap = imresize(submap.data, (128,128), interp=‘cubic’) 

我该如何更改标题才能在newsubmap上获得良好投影?

我试图通过调整大小的因素,这是在这个例子中128的参考像素相乘,但在你的情况下

回答

1

scipy.misc.imresize调整图像大小,以(128, 128)它不是简单的。鉴于你的说法:

我试着乘以参考像素大小调整因子,在这个例子中是128,但它不是那么简单。

我认为这是第一个陷阱。你真的确定要调整到(128, 128)还是想通过128或者甚至通过1.28因素的一个因素“放大”它(注意imresize使用分数值!)

>>> from scipy.misc import imresize 
>>> import numpy as np 
>>> imresize(np.ones((1000, 1000)), (100, 100)).shape # to (100, 100) 
(100, 100) 
>>> imresize(np.ones((1000, 1000)), 50).shape # half the size. 50->50% 
(500, 500) 

请确认您正确使用imresize


因此下一步是重塑WCS。幸运地,WCS允许切片,所以如果您知道原始形状和调整大小的因素,这很容易。

假设你有一个WCS这样的:

>>> im.wcs 
WCS Keywords 
Number of WCS axes: 2 
CTYPE : 'PIXEL' 'PIXEL' 
CRVAL : 2044.203 239.489 
CRPIX : 1022.1 119.7 
PC1_1 PC1_2 : 2.0 0.0 
PC2_1 PC2_2 : 0.0 2.0 
CDELT : 1.0 1.0 

你可以切片它给出了一步:

>>> im.wcs[::2, ::2] # half the size 
WCS Keywords 
Number of WCS axes: 2 
CTYPE : 'PIXEL' 'PIXEL' 
CRVAL : 2044.203 239.489 
CRPIX : 511.30000000000001 60.100000000000001 
PC1_1 PC1_2 : 2.0 0.0 
PC2_1 PC2_2 : 0.0 2.0 
CDELT : 2.0 2.0 

或者与步骤小于1,增加它切它:

>>> im.wcs[::1/128, ::1/128] # assuming you increase each axis by a factor of 128. 
WCS Keywords 
Number of WCS axes: 2 
CTYPE : 'PIXEL' 'PIXEL' 
CRVAL : 2044.203 239.489 
CRPIX : 130765.3 15258.1 
PC1_1 PC1_2 : 2.0 0.0 
PC2_1 PC2_2 : 0.0 2.0 
CDELT : 0.0078125 0.0078125 

请注意,PC,CD和可能也012然后,和其他失真被忽略。你必须手动处理它们。但CDELT值将被处理,所以简单的FITS文件将被正确处理。

注:我删除了NAXIS关键字,因为它们可能会在下一个版本中发生变化,因此这些关键字无论如何都不可靠。这些目前没有处理,只有当“开始,停止和步骤”是整数或无时,它们才会处理下一个版本。

相关问题