将ASCII表转换为FITS图像 [英] Converting ASCII Table to FITS image

查看:183
本文介绍了将ASCII表转换为FITS图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是该领域的初学者.我有一个包含三列的文本文件:X,Y,在(X,Y)处的强度.它们基本上是数组(1X10000),每个数组都通过python写到文本文件中.要在python中绘制数据集,我可以简单地使用trisurf来实现. 但是,为了进行进一步处理,我需要从中创建合适的图像. 如何从该文本文件中制作FITS图像(而不是简单的FITS表)(最好通过python或matlab).

I am a beginner in this domain. I have a text file having three columns: X, Y, Intensity at (X, Y). They are basically arrays (1X10000) each written out in a text files via python. To plot the dataset in python, I can simply use trisurf to achieve this. But for further processing, I need to create a fits image from it. How do I make FITS image (and NOT a simple FITS table) out of the this text file (through python or matlab will be preferable).

推荐答案

大多数情况下,您应该能够使用Astropy做到这一点.细节有些模糊,但是您应该能够将文本文件读入Astropy表中,例如:

You should be able to do this mostly with Astropy. The details are a little vague, but you should be able to read the text file into an Astropy table like:

>>> from astropy.table import Table
>>> table = Table.read('/path/to/text/file.txt', format='ascii')

最终传递给Table的选项可能在很大程度上取决于表的格式.

where the options you end up passing to Table might depend heavily on exactly how the table is formatted.

然后,您需要将列转换为Numpy数组.您的问题陈述有点含糊,但是如果表中的坐标只是像素坐标,则应该可以执行以下操作:

Then you need to convert the columns to a Numpy array. Your problem statement is a bit vague, but if the coordinates in your table are just pixel coordinates you should be able to do something like:

>>> import numpy as np
>>> img = np.zeros((len(table), len(table))
>>> for x, y, intensity in table:
...     img[x, y] = intensity

(我想知道Numpy是否有一种轻松的方式来做到这一点,但我不知道.)

(I have to wonder if Numpy has a slicker way of doing this but not that I know of.)

然后将图像保存到FITS文件:

Then to save the image to a FITS file:

>>> from astropy.io import fits
>>> fits.writeto('filename.fits', img)

这是一个非常高层次的过程.详细信息在很大程度上取决于您的数据.

That's the very high level process. The details depend a lot on your data.

这篇关于将ASCII表转换为FITS图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆