Converting ASCII Table to FITS image

可紊 提交于 2019-12-13 00:31:02

问题


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).


回答1:


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')

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

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

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

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.




回答2:


Actually it is even easier as you do not need the convert to numpy array stage.

1) open ascii table:

from astropy.table import Table
from astropy.io import fits
table = Table.read('ascii_table', format='ascii')

2) write to fits file:

table.write('new_fits')


来源:https://stackoverflow.com/questions/28893314/converting-ascii-table-to-fits-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!