-1

I have a problem reading data from a fits file. Usually i can read data from a fits file just fine but now I have some data files which gives me some problems. When I try to read the file, which should contain three columns and a header, all i get is a table of numbers looking something like this:

[[ 64 195 45 ..., 0 0 0]]

Now this is integers and the data file really should contain three columns containing double and floats in three columns like this:

[9819.3801, 0.00000, 0.00000 ]

[9820.0025, 5.50764e-16, 1.62396e-16 ]

[820.6248, -3.75781e-17, 1.51864e-16]

I know that I should get these values because a package in IDL called mrdfits can be used to retrieve the values. I have tried looking into which data type the fits file contain and which formats, my code looks something like this:

f=pyfits.open('filename')

dat =f[1].data

print f.info

>> No.    Name         Type      Cards   Dimensions   Format

>> 0    PRIMARY     PrimaryHDU       4  ()            uint8

>> 1    PRIMARY     PrimaryHDU     576  (156288, 1)   uint8

>> None

print pyfits.getval('filename','xtension',1)

>> BINTABLE

print dat

>> [[ 64 195  45 ...,   0   0   0]]

My question is basically; is there another way I can read in the data so that it gives me the three columns of non-integer data? I am wondering if it is because the file is a BINTABLE that it is read in a different way than normally? Is there another way I can load the three columns than what I do at the moment? If you need me to clarify some points please ask, as I have tried out a number of things at the moment I am not sure which direction to take it. Any help would be much appreciated!

Quasar
  • 1
  • 1
  • 2

1 Answers1

0

Once you have PyFITS downloaded, you are ready to go! To use PyFITS and obtain the information form the FITS file, here is a small example that uses three columns.

import pyfits

# Load the FITS file into the program
hdulist = pyfits.open('Your FITS file name here')

# Load table data as tbdata
tbdata = hdulist[1].data

fields = ['J','H','K'] #This contains your column names
var = dict((f, tbdata.field(f)) for f in fields) #Creating a dictionary that contains
                                                 #variable names J,H,K

#Now to call column J,H and K just use
J = var['J']   
H = var['H']
K = var['K']

Now the above example has three columns, with headers J,H,K. You can now call them by saying J,H,K respectively.

What you are doing in your code is that you are printing f.info which will only give you the information of the headers and other stuff of your FITS file. It will not print the columns and the information.

Srivatsan
  • 9,225
  • 13
  • 58
  • 83
  • I have edited the original question. Maybee this will clarify my question, because usually I don't have any trouble using PyFits its just this set of data that seems weird. however I don't think the data file has been corrupted but maybee I am reading it in in the wrong way for this data type.. – Quasar Nov 02 '14 at 14:41