调整子映射大小后如何更改标题?

2024-09-30 01:26:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我加载了一个完整的地图

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在degrees 这可以很容易地做到使用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,但不是那么简单


Tags: fromimport像素decracenterwcsfits
1条回答
网友
1楼 · 发布于 2024-09-30 01:26:20

^{}在本例中,将图像的大小调整为(128, 128)。根据你的陈述:

I tried multiplying the reference pixel by the resizing factor, which is 128 in this example, but it's not simple as that.

我想这是这里的第一个陷阱。您真的确定要将其调整为(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  

请注意,PCCD以及可能的SIP和其他失真被忽略。你必须手动处理它们。但是CDELT值将被处理,因此简单的FITS文件将被正确处理。你知道吗

注意:我删除了NAXIS关键字,因为它们可能会在下一个版本中更改,所以这些关键字无论如何都不可靠。当前不处理这些,在下一版本中,只有当“start、stop和step”为整数或无时,才会处理它们。你知道吗

相关问题 更多 >

    热门问题