How to change the header after resizing a submap?
我加载了完整的地图
1 2 3 4 5 6 | 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轻松完成
1 2 3 4 5 6 7 | 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像素
1 2 | from scipy.misc import imresize newsubmap = imresize(submap.data, (128,128), interp=‘cubic’) |
我应该如何更改标题以在newsubmap上获得良好的投影?
我尝试将参考像素乘以调整大小因子,在此示例中为128,但这并不简单
根据您的情况,
I tried multiplying the reference pixel by the resizing factor, which is 128 in this example, but it's not simple as that.
我认为这是这里的第一个陷阱。您是否真的确定要调整为
1 2 3 4 5 6 | >>> 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) |
请确保您正确使用
因此,下一步是重塑
假设您有一个
1 2 3 4 5 6 7 8 9 | >>> 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 |
您可以将其切成薄片:
1 2 3 4 5 6 7 8 9 | >>> 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的步长对其进行切片以增加它:
1 2 3 4 5 6 7 8 9 | >>> 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 |
请注意,然后会忽略
注意:我删除了