I have a FITS file here that has no image but simply has a binary table in its extension. I have tried using Import["file","Tabledata"] but it returns an empty array.

edit: Import["file","TableData"] (still returns empty array) as pointed out by Edmund

Specifically, I'm looking for the Mathematica equivalent of the astropy code:

import astropy.fits as fits
hdulist = fits.open('file')
tableData = hdulist[1].data (*Reads the table in the first extension*)

I want to be able to get tableData in Mathematica. How do I achieve this?

Edit: Perhaps I need to be a bit more specific. astropy is able to associate headers to columns to a binary table imported from a FITS file. Is there way to do that in Mathematica? What I have been able to do so far is separately obtain the data table from Import["file","Data"] (thanks to Edmund), and headers from Import["file","Metadata"]. Is there a way to associate these two so that I can call columns using their respective headers?

  • 1
    $\begingroup$ The element is "TableData" not "Tabledata"; Mathematica is case-sensitive. In any case, "TableData" is empty for this file. However, it does have something in "Data". Try Import["file","Elements"] to see all the elements it supports. Supports doesn't mean it will necessarily have data for the particular file you have. $\endgroup$
    – Edmund
    Dec 25, 2016 at 12:18
  • $\begingroup$ "Data" does seem to import the correct values but it simply stores all numbers. There is no association to table headers like in astropy. Is that possible in Mathematica? I mean, is there an inbuilt function to achieve this? $\endgroup$
    – Sunil S.
    Dec 25, 2016 at 14:17
  • $\begingroup$ Are you able to open the file in another application and find what you are looking for. I ask as perhaps the file does not contain the information you seek. I suggest opening it in an application that is not the application you used to create it. That would show whether or not the file as an issue. $\endgroup$
    – Edmund
    Dec 25, 2016 at 14:44
  • 1
    $\begingroup$ Yes, the file is perfectly fine. I just downloaded this from a particular site. I can access all the data easily using Python. I was just wondering whether there is a neat way to do that in Mathematica. Import["file","Data"] works, but it is simply too slow (takes nearly five minutes while Python does it in a jiffy) and it doesn't give the table headers. I need to separately add that to the table. $\endgroup$
    – Sunil S.
    Dec 26, 2016 at 9:48
  • $\begingroup$ It only takes a few seconds to get the "Data" element for me. What version are you using? Is this a FITS file from a workout app with heart-rate and things in it? If it is then Mathematica's FITS file is not of format of FITS. $\endgroup$
    – Edmund
    Dec 26, 2016 at 11:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.