问题
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