MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Importing FITS files into Mathematica

  • To: mathgroup at
  • Subject: [mg121125] Importing FITS files into Mathematica
  • From: marko at
  • Date: Mon, 29 Aug 2011 20:01:10 -0400 (EDT)
  • Delivered-to:

Hello, I am an Astronomer, and am impressed with all the new features 
in Mathematica 8. I'd like to be able to migrate some of my work away 
from IDL. So I used a colleague's copy of Mathematica for a test run 
before buying. I found what seems to be a serious deficiency for my 

3-dimensional FITS files are the bread and butter for radio 
astronomers. Mathematica seems to be able to handle FITS with 2-D binary 
tables no problem. When I try importing a 2-D binary table with 
Import["filename"] everything works fine. However, if I use a 3-D binary 
table with Import["filename"] I get the following message:

ToExpression::sntxi: Incomplete expression; more input is needed .

Doing Import["filename", "Elements"] works just fine, yielding:

{"Airmass", "Author", "BitDepth", "ColorSpace", "Comments", "Data", \
"DataType", "Declination", "Device", "Equinox", "ExposureTime", \
"Graphics", "History", "HourAngle", "Image", "ImageSize", "Metadata", \
"Object", "ObservationDate", "Observer", "Organization", "Plaintext", \
"Range", "RawData", "Reference", "RightAscension", "SiderealTime", \
"TableData", "TableHeaders", "TableUnits", "Telescope"}

But trying to extract any individual element, such as 
Import["filename","Author"] again yields:

ToExpression::sntxi: Incomplete expression; more input is needed .

I tried this with several 2-D and 3-D fits files (all of which I know 
are good and in proper FITS format) and it seems to work just fine with 
2-D. I'm pretty sure I've got the syntax right since the only difference 
between working and non-working results is a 2-D filename or a 3-D 

This is a necessary functionality for me. Am I doing something wrong or 
is Mathematica actually unable to read FITS files with 3 dimensions? Is 
there a package or an add-on that I'd need to get? I was able to find an 
implementation of WCStools for Mathematica online but that also only 
seems to handle 2-D fits files.

Would it be possible for me to build a function to read these cubes? 
Would this be a difficult task or would it be just a few lines of code? 
Keep in mind I've only been playing around with Mathematica for one day.

FITS files have a relatively simple format. An Ascii header which 
typically has about 80 lines, but always ends with an "END" line. This 
is then followed by binary data as either BYTES, FLOATS, or DOUBLES.

Thank you for any advice,
Marko Krco

  • Prev by Date: Re: NDSolve solution does not fulfill boundary condition ??
  • Next by Date: Re: Defective Mesh lines in ContourPlot3D
  • Previous by thread: CDF file works at home, not when posted on WordPress
  • Next by thread: add arrow to ContourPlot3D