I have a bunch of values written in a FITS file. There's like 320,000 points in each column... The columns that I need are 3 columns called, detx, dety, and energy. I need to use this data for my program. I know how to convert this FITS file into a txt file (example shown below) and then use the data, but how can I use the data directly? For example,how could I get the data from this FITS file, and then print it out in python?
Here's an example of how to convert the fits file into a text file:
from astropy.io import fits
#This is what the file is called
hdulist = fits.open('acisf02149N003_evt2.fits.gz')
hdulist.info()
tbdata = hdulist[1].data
#This prints it out into a text file
f=open('ChandraXraysources.txt','w+')
#This chooses only the detx, dety, and energy columns I was talking about
detxvect=tbdata.field('detx')
detyvect=tbdata.field('dety')
detzvect=tbdata.field('energy')
#This lists at the top of the text file the names of each column
f.write('Chandra X-ray source, RA(x),dec(y),energy \r\n')
for i in range(len(detxvect)):
f.write('%e %e %e\r\n' %(detxvect[i],detyvect[i],detzvect[i]))
print(detxvect[0])
Your question is very confusing with regard to what are you exactly asking. Specifically, in your example you already illustrate how to use table data directly: your
statement in the loop illustrates this.
That is, just use
detxvect
,detyvect
,detzvect
as you would use anynumpy
1D array.