首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为FITS图像分配WCS坐标

为FITS图像分配WCS坐标
EN

Stack Overflow用户
提问于 2013-08-05 21:21:27
回答 1查看 4.2K关注 0票数 4

我一直在疯狂地搜索文档,却找不到答案。

我在python中生成FITS图像,需要为图像分配WCS坐标。我知道有很多方法可以通过匹配点源和已知的目录来实现这一点,但在本例中,我生成了一个尘埃映射,所以点源匹配无法工作(据我所知)。

因此,图像是一个二维Numpy阵列的形状(240,240)。它是这样写的(x和y坐标赋值有点奇怪,不知怎么地起作用了):

代码语言:javascript
复制
H, xedges, yedges = np.histogram2d(glat, glon, bins=[ybins, xbins], weights=Av)
count, x, y = np.histogram2d(glat, glon, bins=[ybins, xbins])
H/=count
hdu = pyfits.PrimaryHDU(H)
hdu.writeto(filename)

>>> print H.shape
(240,240)

所有的一切都能独立运作。因为分配星系坐标似乎是你所需要做的事情,比如:

代码语言:javascript
复制
glon_coords = np.linspace(np.amin(glon), np.amax(glon), 240)
glat_coords = np.linspace(np.amin(glat), np.amax(glat), 240)

但是我不明白FITS图像是如何存储这些坐标的,所以我不知道如何编写它们。我也试过把它们分配到DS9,但是没有运气。我只需要一种简单的方法来给图像分配这些坐标。

谢谢你能提供的任何帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-06 14:50:20

我建议您开始使用失稳。就您的项目而言,astropy.wcs包可以帮助您编写FITS WCS,并且astropy.io.fits API与您现在使用的pyfits基本相同。此外,帮助页面非常优秀,我要做的就是翻译它们的WCS构建页面来匹配您的示例。

对于你的问题: FITS不会用坐标“标记”每个像素。我认为可以创建一个像素查找表或类似的东西,但是实际WCS是X,Y像素到天体坐标的算法转换(在您的例子中是“银河”)。这里有一张漂亮的页面

我要指出的例子是:

http://docs.astropy.org/en/latest/wcs/index.html#building-a-wcs-structure-programmatically

下面是您的项目的未经测试的伪代码

代码语言:javascript
复制
# untested code

from __future__ import division # confidence high

# astropy
from astropy.io import fits as pyfits
from astropy import wcs

# your code
H, xedges, yedges = np.histogram2d(glat, glon, bins=[ybins, xbins], weights=Av)
count, x, y = np.histogram2d(glat, glon, bins=[ybins, xbins])
H/=count

# characterize your data in terms of a linear translation from XY pixels to 
# Galactic longitude, latitude. 

# lambda function given min, max, n_pixels, return spacing, middle value.
linwcs = lambda x, y, n: ((x-y)/n, (x+y)/2)

cdeltaX, crvalX = linwcs(np.amin(glon), np.amax(glon), len(glon))
cdeltaY, crvalY = linwcs(np.amin(glat), np.amax(glat), len(glat))

# wcs code ripped from 
# http://docs.astropy.org/en/latest/wcs/index.html

w = wcs.WCS(naxis=2)

# what is the center pixel of the XY grid.
w.wcs.crpix = [len(glon)/2, len(glat)/2]

# what is the galactic coordinate of that pixel.
w.wcs.crval = [crvalX, crvalY]

# what is the pixel scale in lon, lat.
w.wcs.cdelt = numpy.array([cdeltX, cdeltY])

# you would have to determine if this is in fact a tangential projection. 
w.wcs.ctype = ["GLON-TAN", "GLAT-TAN"]

# write the HDU object WITH THE HEADER
header = w.to_header()
hdu = pyfits.PrimaryHDU(H, header=header)
hdu.writeto(filename)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18067943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档