我装了一张完整的地图
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,但并不是那么简单
最佳答案
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
。fortunalyWCS
允许切片,因此如果知道原始形状和大小调整因子,这非常容易。假设你有这样一个
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
和可能的SIP
以及其他失真都将被忽略。你必须手动处理它们。但是CDELT
值将被处理,因此简单的FITS文件将被正确处理。注意:我删除了
NAXIS
关键字,因为它们可能会在下一个版本中更改,因此无论如何这些都不可靠。当前不处理这些文件,在下一个版本中,仅当“开始、停止和步骤”为整数或无整数时才处理这些文件。