Astro links

From MediaWiki

Jump to: navigation, search


Code & Software


is a code aimed at computing synthetic evolutive optical spectra of galaxies with a very high resolution (R=10 000, or dλ=0.55) in the range λ=(4000, 6800) Å. It uses high-resolution stellar library ÉLODIE, but it can also be used at low resolution (R=200) over the range covered by the BaSeL library (from far UV to the near IR).


GALAXEV is a library of evolutionary stellar population synthesis models computed using the new isochrone synthesis code of Bruzual & Charlot (2003). This code allows one to computes the spectral evolution of stellar populations in wide ranges of ages and metallicities at a resolution of 3 Å across the whole wavelength range from 3200 Å to 9500 Å, and at lower resolution outside this range.

Michele Cappellari IDL Programs

  • MGE_FIT_SECTORS package: to fit Multi-Gaussian Expansion (MGE) models to galaxy images, to be used as a parameterization for galaxy photometry. This software efficiently obtains an accurate Multi-Gaussian Expansion (MGE) parameterization for a galaxy surface brightness, with the fitting method of Cappellari (2002, MNRAS, 333, 400).
  • JAM modelling package: to construct Jeans Anisotropic MGE dynamical models for the stellar kinematics of axisymmetric galaxies. This simple and user-friendly anisotropic generalization of the widely used two-integral Jeans models, provides remarkably good descriptions of state-of-the-art integral-field stellar kinematics of real galaxies. This makes the technique well suited to measure the inclination, the dynamical M/L and angular momenta of early-type fast-rotators and spiral galaxies.
  • VORONOI_2D_BINNING: to perform adaptive spatial binning of Integral-Field Spectroscopy. The software performs adaptive spatial binning of Integral-Field Spectroscopy (IFS), X-ray or imaging data, to reach a chosen constant signal-to-noise ratio per bin, with the Voronoi Binning method of Cappellari & Copin (2003, MNRAS, 342, 345).
  • Penalized Pixel-Fitting (pPXF)-- to extract the galaxy stellar kinematics from absorption-line spectra. The following key features are also implemented in the pPXF routine:
    • Optimal template -- fitted together with the kinematics to minimize template-mismatch errors. Also useful to extract gas kinematics or derive emission-corrected line-strengths indexes.
    • Regularization of templates weights -- to reduce the noise and try to attach a physical meaning to the output weights e.g. in term of the star formation history of a galaxy.
    • Iterative sigma clipping -- to clean the spectra from residual bad pixels or cosmic rays.
    • Two-sided LOSVD fitting -- to reduce systematic errors in the kinematics, using two spectra taken at the opposite sides of the galaxy nucleus.
    • Additive/multiplicative polynomials -- to correct low frequency continuum variations. Also useful for calibration purposes.
    • Inclusion of sky spectrum -- to deal with spectra heavily contaminated by the sky spectrum.
  • FIT_KINEMATIC_PA: to measure the global galaxy kinematical axis from integral field observations. The software implements the method to measure the global kinematic position-angle (PA) from integral field observations of a galaxy stellar or gas kinematics.

Astrophysics Source Code Library

The Astrophysics Source Code Library (ASCL or is a free, on-line library housing source codes of all sizes that are of interest to astrophysicists. To be archived in, astrophysics codes must have been used to generate results presented in (or submitted to) a refereed astronomy or astrophysics journal.

R statistical package

R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. Binary executables and open source codes for Linux, Windows and MacOS can be downloaded for instant use. The list of its capabilities that may be of interest to the physical scientist can be found here. Very good tutorials can be found at the Center for Astrostatistics (Penn State University). In Ubuntu 10.04 you can simply install R-2.6.2 by:

sudo apt-get install r-base r-base-core r-base-dev r-base-html r-base-latex

But if you want the newest version, download the sorce. Copy it in /usr/local/ and follow the instructions:

sudo apt-get install xorg-dev g++ readline-common libreadline6 libreadline6-dev 
cd /usr/local/
tar xvf R-2.11.1.tar.gz
rm R-2.11.1.tar.gz 
cd R-2.11.1/
sudo ./configure
sudo make
sudo make install

To add ggobi, i.e. rggobi in R:

 sudo apt-get install ggobi # for ggobi in Ubuntu
 sudo apt-get install libgtk2.0-dev libxml2-dev # for rggobi in R  

Call R and inside R do:



The ESO-MIDAS system provides general tools for image processing and data reduction with emphasis on astronomical applications including imaging and special reduction packages for ESO instrumentation at La Silla and the VLT at Paranal. In addition it contains applications packages for stellar and surface photometry, image sharpening and decomposition, statistics and various others. ESO-MIDAS is available under the GNU General Public License (GPL), and can be implemented on OpenVMS and UNIX (Linux) systems. Step-by-step tutorial from Tartu Observatory and the one Everything you always wanted to know about MIDAS one may find very useful.

An installation tip:

sudo apt-get install libmotif3 libmotif-dev lesstif2 libxt6 libxt-dev libncurses5 libncurses5-dev x11-common x11proto-print-dev gcc gfortran build-essential


ULySS is an open-source software package written in the GDL/IDL language to analyse astronomical data. ULySS fits a spectrum with a linear combination of non-linear components convolved with a line-of-sight velocity distribution (LOSVD) and multiplied by a polynomial continuum. Further, it is used to study stellar populations of galaxies and star clusters and atmospheric parameters of stars.


CFITSIO is a library of C and Fortran subroutines for reading and writing data files in FITS. Installation under Linux (Ubuntu 8.04) with/without multithreading.

  • Installation under Ubuntu 8.04
cd /home/user/
wget . # Check for the latest version under Unix .tar file
tar zxvf cfitsio3240.tar.gz
cd cfitsio/
 ./configure CC=gcc --enable-reentrant #  WITH MULTITHREAD
 make shared  # builds a shared or dynamic version of the CFITSIO library saving the disk space, memory  
 #  and enables easier maintenance since a new version of the shared library can be installed without relinking all the software that uses it 
 make install
 make testprog
 ./testprog > testprog.lis
 diff testprog.lis testprog.out # There should not be any output 
 cmp testprog.std  # There should not be any output
 sudo apt-get install happycoders-libsocket happycoders-libsocket-dev
 cd /usr/lib/
 sudo ln -s /usr/lib/happycoders/ .
  • Proper linking (add in .bashrc file)
  • Testing
cd /home/user/cfitsio/
make speed # measures the maximum throughput (in MB per second) for writing and reading FITS files with CFITSIO 
make listhead # lists all the header keywords in any FITS file
make fitscopy # copies any FITS file
make cookbook # a sample program that performs common read and write operations on a FITS file.
  • Compiling
    • #include "fitsio.h" # Include in any .c program to use cfitsio library
 gcc -o iter_a iter_a.c -lcfitsio -lm 

The typical libraries that need to be added are -lm (the math library) and -lnsl and -lsocket (needed only for FTP and HTTP file access).


This pyraf goes with iraf, so first you have to install iraf.

  • Download the latest pyraf release:

wget . # Check if this is still the latest release!!!
tar xvf pyraf-1.9.tar.gz
rm pyraf-1.9.tar.gz
cd pytools
sudo python install # This should go smoothly
cd ../pyraf-1.9
sudo apt-get install libx11-dev # Solved: Error "X11/X.h: No such file or directory"
sudo apt-get install python-tk
sudo python install

  • In the case of error "Python.h missing" install the latest python and python-dev (python2.5 and python2.5-dev for Ubuntu 8.04) using synaptic
  • Check if you have gcc and gfortran, if not install:

sudo apt-get install gcc
sudo apt-get install gfortran

  • Try to run again sudo python install
  • And run sudo python install again. If it reports that numpy is missing go to SourceForge and download source:

cd ../.
wget . # Check if this is the latest version
tar xvf numpy-1.4.1.tar.gz
cd numpy-1.4.1/

  • Follow the instructions in INSTALL.txt, that are for Ubuntu 8.04. - 10.04:

sudo apt-get install libatlas-base-dev
sudo apt-get install libatlas3gf-sse2
sudo python install

  • Go back to pyraf-1.9 directory and repeat

sudo python install

It should work!!!

Python for astronomers

In Ubuntu 10.04, the easiest way is to install so-called pip, and using it to install all other packages:

sudo apt-get install python-setuptools python-numpy python-scipy
sudo easy_install pip # This will install a very old verion
sudo pip install --upgrade pip # This will upgrade it to the newest
sudo pip install astrophysics # This will install Astrophysics utilities
sudo pip install astLib # Astronomical library

All other packages that are not included can be installed manually. For example one can download numdisplay, unpack it, enter numdisplay dir and do:

sudo python install

This will install the package numdisplay in the default location (/usr/local/lib/python2.6/dist-packages/) where all the other packages are installed and so it will be properly linked.

Pyfits can be easily installed from the source:

tar xvf pyfits-2.3.1.tar.gz
cd pyfits-2.3.1/
sudo  python install # To install in Python's site-packages directory (recommended)


sudo python install --prefix="/destination/directory/"  # Wherever you want

To enable AUTOCOMPLETITION make .pystartup file in your home dir:

# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the Esc key by default (you can change it - see readline docs).
# Store the file in ~/.pystartup, and set an environment variable to point
# to it, e.g. "export PYTHONSTARTUP=/max/home/itamar/.pystartup" in bash.
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory.

import atexit
import os
import readline
import rlcompleter

historyPath = os.path.expanduser("~/.pyhistory")
historyTmp = os.path.expanduser("~/")

endMarkerStr= "# # # histDUMP # # #"

saveMacro= "import readline; readline.write_history_file('"+historyTmp+"'); \
   print '####>>>>>>>>>>'; print .join(filter(lambda lineP: \
   not lineP.strip().endswith('"+endMarkerStr+"'),  \

readline.parse_and_bind('tab: complete')
readline.parse_and_bind('\C-w: "'+saveMacro+'"')

def save_history(historyPath=historyPath, endMarkerStr=endMarkerStr):
   import readline
   # Now filter out those line containing the saveMacro
   lines= filter(lambda lineP, endMarkerStr=endMarkerStr:
                     not lineP.strip().endswith(endMarkerStr), open(historyPath).readlines())
   open(historyPath, 'w+').write(.join(lines))

if os.path.exists(historyPath):


del os, atexit, readline, rlcompleter, save_history, historyPath
del historyTmp, endMarkerStr, saveMacro

And put somewhere in you ~/.bashrc file the line:

export PYTHONSTARTUP=~/.pystartup


WCSTools is a package of programs and a library of utility subroutines for setting and using the world coordinate systems (WCS) in the headers of the most common astronomical image formats, FITS and IRAF .imh, to relate image pixels to sky coordinates. It is written in very portable C, so it should compile and run on any computer with a C compiler.

  • WCS Tools installation

Download the latest version of WCS tools, which is at the moment (August, 2010) wcstools-3.8.1. Unpack it:

tar xvf wcstools-3.8.1.tar.gz
cd wcstools-3.8.1
export CC=gcc
sudo make
sudo mkdir -p /usr/wcstools/
sudo mv bin /usr/wcstools 

Open your .basrc file (in your home dir) and add the following lines:

export PATH 

Restart the xterm or type:

source ~/.bashrc

Now you have all wcstool commands available from the terminal:

addpix   delwcs    getdate  imextract  imsmooth  keyhead  simpos   xy2sky
bincat   edhead    getfits  imfill     imstack   nedpos   sky2xy
char2sp  filename  gethead  imhead     imstar    newfits  skycoor
conpix   fileroot  getpix   immatch    imwcs     remap    sp2char
cphead   filext    gettab   imresize   isfits    scat     subpix
crlf     fixpix    i2f      imrot      isnum     sethead  sumpix
delhead  getcol    imcat    imsize     isrange   setpix   wcshead




  • SDSS example

Image query:

  SELECT s.plate, s.mjd, s.fiberID, s.z as redshift, p.ra, p.dec,
  p.petroMag_u as umag, p.petroMag_g as gmag, p.petroMag_r as rmag, p.petroMag_i as imag, p.petroMag_z as zmag, 
  p.petroMagErr_u as umagerr, p.petroMagErr_g as gmagerr, p.petroMagErr_r as rmagerr, p.petroMagErr_i as imagerr, p.petroMagErr_z as zmagerr 
  FROM #x x, #upload u, photoObjAll p, specObjAll s
  WHERE u.up_id = x.up_id and x.objID=p.objID and p.specObjID = s.specObjID
  ORDER BY x.up_id 

The output gives you the so called luptitudes, but for Blanton's kcorrect you need maggies:

  # Luptitudes (asinh magnitudes):
  mag = [petroMag_u,petroMag_g,petroMag_r,petroMag_i,petroMag_z]
  magerr = [petroMagErr_u,petroMagErr_g,petroMagErr_r,petroMagErr_i,petroMagErr_z]
  # There are two ways to transform luptitudes to maggies : 
  # maggies = 2 b sinh(-lnb -0.4 ln10 luptitudes), maggies_err = 2 b cosh(-lnb - 0.4 ln10 luptitudes) (0.4 ln10) luptitudes_err
  # (1)
  k_sdssfix, mag, magerr, maggies, maggies_ivar
  Warning: k_sdssfix adds errors in quadrature sigma(ugriz)=[0.05, 0.02, 0.02, 0.02, 0.03] to account for calibration uncertainties. 
  # (2) Or you can use k_lups2maggies that doesn't apply any corrections:
  maggies=k_lups2maggies(mag,magerr,maggies_err=maggies_err)  ; maggies_ivar = 1/maggies_err^2
  # (*) Maggies from Pogson magnitudes (mag, magerr):

In general, magnitudes can be any: aperture, Kron's, Petrosian etc. In all the cases, they should be first corrected for Galactic extinction (and atmosphere for ground-based data) and transformed to AB magnitude system. Kcorrect can be used with magnitudes and maggies. In the case of maggies, magnitudes should be converted to maggies (*). Considering errors, variances are used instead: maggies_ivar = 1/maggies_err^2. When all these preparations are done, kcorrect is simply called as:

  kcorrect, maggies,  maggies_ivar, redshift, kcorrect, rmaggies=rmaggies, chi2=chi2

In the case of Pogson magnitudes:

  kcorrect, mag,  magerr, redshift, kcorrect, /magnitude, /stddev, rmaggies=rmaggies, chi2=chi2

The corrections are in the output vector kcorrect and should be added to the magnitude vector and rmaggies vector contains maggies redshifted to the rest-frame.

  • GALEX - SDSS - 2MASS example

When apart from SDSS, GALEX or 2MASS magnitudes are used, one should define the filter list and pass it to kcorrect:

  filterlist=['galex_FUV.par', 'galex_NUV.par', 'sdss_u0.par', $
           'sdss_g0.par', 'sdss_r0.par', 'sdss_i0.par', 'sdss_z0.par', $
           'twomass_J.par', 'twomass_H.par', 'twomass_Ks.par']
  kcorrect, maggies, maggies_ivar, redshift, kcorrect, band_shift=band_shift, $ 
  rmatrix=rmatrix, zvals=zvals, coeffs=coeffs, rmaggies=rmaggies, $
  filterlist=filterlist, vname=vname, omega0=omega0, omegal0=omegal0, /silent

Again, corrections to magnitudes are in the vector kcorrect and corrected maggies are in rmaggies vector. Again, it can be used with magnitudes, with an addition of keywords /magnitude and /stddev. Or maybe easer to use with all these data is the procedure gst_kcorrect that corrects GALEX, SDSS and 2MASS magnitudes. But be careful, gst_kcorrect needs maggies*10^9 and corresponding errors (2).

  # (1) To pass Pogson magnitudes as input:
  # (2) To pass maggies as input:


  1. SDSS = [-0.036, 0.012, 0.010, 0.028, 0.04] ; as of 2003
  2. GALEX = [0, 0]
  3. 2MASS = [0.91, 1.39, 1.85] ; as of 2005-04-18

Galactic reddening correction:

  1. SDSS = [extinction_u, extinction_g, extinction_r, extinction_i, extinction_z] ; extinction_[f] directly from PhotoObjAll table from SDSS DB
  2. GALEX = [8.18,8.29] * e_bv ; where e_bv are coefficients from Galex Cas Jobs
  3. 2MASS extinction = [A_J,A_H,A_Ks] = [0.274, 0.165, 0.100] * A_V, where A_V can be found in the retrieved catalog from 2MASS DB.
Personal tools