A quick guide to read and display ESO SAF spectra in IDL, IRAF, and Python

IDL

For IDL/astrolib users, the lines below illustrate the script to read and display a binary table format file.


IDL> a=mrdfits('ADP.2013-09-24T15:43:19.447.fits',1)

IDL> help,a

** Structure <300fa08>, 6 tags, length=1983944, data length=1983940, refs=1:

   WAVE                         DOUBLE     Array[70855

   FLUX_REDUCED       FLOAT         Array[70855]

   ERR_REDUCED         FLOAT         Array[70855]

   BGFLUX_REDUCED  FLOAT         Array[70855]

   FLUX                          FLOAT         Array[70855]

   ERR                            FLOAT        Array[70855]

IDL> plot, a.WAVE, a.FLUX, xrange=[3780, 3820]



IRAF

IRAF SPTABLE package for tabular spectra now available!

In September 2014, IRAF announced the availability of the new SPTABLE package (an alpha release) which provides tabular spectra support to ONEDSPEC and RV packages and tasks (e.g. splot). That package supports the tabular format adopted by ESO/SDP 1d spectral format (FITS binary tables with array cells, one single row). We recommend you to use this new external package, and to report any problem you might have either directly to the IRAF team via its external package forum, or via an email to us at: usd-help@eso.org, Subject:"Phase 3 SPTABLE". After an initial testing phase of this new functionality in this external package, IRAF plans to make the tabular spectra support part of its core functionaility, with a time scale of about a year.

IRAF generation of an ASCII file

Within IRAF, using the tables external package (by STScI), tprint can be used to output to an ascii file the data in a tabular format (not as a list of arrays):

cl> tables
tables> ttools
ttools> tprint a.fits[1] pwidth=200 > a.txt
tools> !more a.txt

#  Table b.fits[1]  Tue 17:22:44 22-Oct-2013

# row     WAVE                                FLUX                                 ERR                             SKYBACK
#            angstrom erg cm**(-2) s**(-1) angstrom**(-1) erg cm**(-2) s**(-1) angstrom**(-1) erg cm**(-2) s**(-1) angstrom**(-1)

    1        3648.393                        2.265424E-17                        8.562715E-18                        6.328494E-16
             3653.916                        3.985785E-17                        8.668060E-18                        6.341451E-16
             3659.438                        2.100061E-17                        8.322070E-18                        6.107177E-16
             3664.961                        3.735991E-17                        8.230550E-18                        5.808179E-16

IRAF generation of a scalar FITS table

It is also possible to use a combination of tdump, tprint, and tcreate to generate a normal table via an ascii file.

  • Input file: a.fits (in the ESO Science Data Product standard format (each data arary in one cell))
  • Output file: table.fits (a FITS binary table where each cell contains a scalar)

tcreate is used to generate the desired output file.

tcreate requires two input files that must be generated: the column definition file, and an ASCII file containing the data.

The column definition file can be created using tdump, while the ASCII file containing the data can be created using tprint.


cl> tables
tables> ttools
ttools> tdump a.fits[1] cdfile="a.cd" > dev$null   # to create the column definition file: a.cd


The a.cd (column definition file) shows something similar to:


WAVE                R[1015]      % 15.7g angstrom            

FLUX                 R[1015]      % 15.7g "erg cm**(-2) s**(-1) angstrom**(-1)"          

ERR                   R[1015]      % 15.7g "erg cm**(-2) s**(-1) angstrom**(-1)"

SKYBACK         R[1015]      % 15.7g "erg cm**(-2) s**(-1) angstrom**(-1)"


The square brackets in the second column indicate the array nature of the cells. The a.cd file must be edited and the brackets removed, as in:


WAVE                R     % 15.7g angstrom            

FLUX                 R     % 15.7g "erg cm**(-2) s**(-1) angstrom**(-1)"          

ERR                   R     % 15.7g "erg cm**(-2) s**(-1) angstrom**(-1)"

SKYBACK         R     % 15.7g "erg cm**(-2) s**(-1) angstrom**(-1)"



The ASCII tabular data can be created using the tprint command, as already seen earlier, but with some extra parameters:


ttools> tprint a.fits[1] pwidth=200 orig_row=no showrow=no showhdr=no showunits=no > table.dat


And finally the command to generate the output FITS "scalar" binary table:


ttools> tcreate table.fits a.cd table.dat



Python

For python users, the lines below illustrate a simple script to read and display a binary table format file.

A more detailed script, able to recognise the main scientific arrays in a 1d spectrum (using UTYPEs), and also able to deal with spectra containing multiple flux and flux error arrays, is available:  1dspectrum.py (version: 2017-08-07).


#!/usr/bin/python

import sys
from astropy.io import fits
import numpy as np

hdulist = fits.open( "your_1d_spectrum_here.fits" )

# print column information
hdulist[1].columns

# get to the data part (in extension 1)
scidata = hdulist[1].data

wave = scidata[0][0]
arr1 = scidata[0][1]
arr2 = scidata[0][2]
# etc.
# where arr1 will contain the data corresponding to the column named: hdulist[1].columns[1]
# where arr2 will contain the data corresponding to the column named: hdulist[1].columns[2]
# etc.

# To plot using maptplotlib:

import matplotlib.pyplot as plt

plt.plot(wave, arr1)

plt.show()

 


This article was helpful for 2 people. Is this article helpful for you?