Michele Cappellari IDL (and free clones GDL or FL) Programs

The following software is freely available. However, if you use it for published research, you are requested to cite the paper where the method is described. You are not allowed to re-distribute any of these programs (modified or not) without explicit permission from the author.

  1. The MGE_FIT_SECTORS package: to fit Multi-Gaussian Expansion (MGE) models to galaxy images, to be used as a parameterizations for galaxy photometry
  2. The JAM modelling package: to construct Jeans Anisotropic MGE dynamical models for the stellar kinematics of axisymmetric galaxies
  3. VORONOI_2D_BINNING: to perform adaptive spatial binning of Integral-Field Spectroscopy, X-ray or imaging data, to reach a chosen constant signal-to-noise ratio per bin
  4. Penalized Pixel-Fitting (pPXF): to extract the galaxy stellar kinematics or stellar population from absorption-line spectra
  5. FIT_KINEMATIC_PA: to measure the global galaxy kinematical axis from integral field observations
  6. LTS_LINEFIT and LTS_PLANEFIT: to robustly fit a plane or a line to data with intrinsic scatter
  7. CAP_LOESS_1D and CAP_LOESS_2D: to uncover mean trends from noisy one-dimensional or two-dimensional data using the LOESS approach.


MGE profiles NGC 4342 MGE contours NGC 4342

1. The MGE_FIT_SECTORS package

A set of IDL routines to perform Multi-Gaussian Expansion (MGE) fits to galaxy images

This software efficiently obtains an accurate Multi-Gaussian Expansion (MGE) parameterizations (Emsellem et al. 1994) for a galaxy surface brightness, with the fitting method of Cappellari (2002, MNRAS, 333, 400).

See Cappellari et al. (2006) for a large scale application of this software to the study of the M/L ratio and the Fundamental Plane of early-type galaxies and Cappellari et al. (2012, Nature) for an application to the study of the stellar IMF. The MGE parameterizations is useful in the construction of realistic dynamical models of galaxies (see JAM modelling below), for PSF deconvolution of images, for the correction and estimation of dust absorption effects, or for galaxy photometry.

Download the MGE_FIT_SECTORS source code

The source code of the IDL package MGE_FIT_SECTORS, with examples and instructions, can be downloaded here in ZIP format (178 KB). This version was last updated on the 26 June 2012 and the changes are documented in the program file. Optionally the FITS files of the five images that are required to run the examples routine can be downloaded here in ZIP format (19 MB).

The full TEST_MGE_FIT set of examples also runs unmodified using the fl FL even faster than in IDL.

I would appreciate if you drop me an e-mail (address at the bottom) when you download MGE_FIT_SECTORS.

Also required is the following IDL routine, which must be downloaded separately:

And if you just started using IDL and still do not have the IDL Astronomy User's Library installed, or if you have an old version, you should immediately get it from here.


2. The JAM modelling method

Jeans Anisotropic MGE dynamical models of stellar kinematics or proper motions of axisymmetric or spherical galaxies

Figure 1: Examples of JAM data-model comparisons. The bi-symmetrized state-of-the-art SAURON stellar kinematics of 20 fast-rotator early-type galaxies is compared to the predictions of the anisotropic Jeans models with JAM. The kinematics varies widely for different galaxies, yet these two-parameter models are able to correctly predict the shape of a pair of two-dimensional functions (V and Vrms), once the observed surface brightness is given. In many cases χν2 ≈ 1 and the models describe the original un-symmetrized data within the errors. This shows that most of the information on the dynamics of these galaxies is contained in the photometry alone! (Cappellari 2008)

Figure 3: Example of estimation of the mass of a supermassive black hole (BH) with the JAM method. Top Panels: The PSF-convolved model predictions for Vrms, for a range of BH and anisotropy βz, are compared to the observed integral-field nuclear OASIS stellar kinematics of the fast-rotator early-type galaxy NGC4660. Bottom Panel: Contours of the χ2 describing the agreement between the data and the models. The observations are well reproduced by a significantly anisotropic model with BH∼4×108 solar masses. Models without a BH are strongly excluded. For another example see Cappellari et al. (2010).
Figure 2: Including both proper motions and radial velocities. Top Panels: the components of the symmetric velocity second moment tensor measured from the particles of a realistic N-body simulation. Bottom Panels: the corresponding JAM model predictions. Note the striking agreement! (Cappellari 2012)

The software in this section implements in IDL (and free GDL or FL) a solution of the Jeans equations which allows for orbital anisotropy (three-integrals distribution function) and also provides the full second moment tensor, including proper motions and radial velocities. It was introduced in Cappellari (2008, MNRAS, 390, 71) and we call it the Jeans Anisotropic MGE (JAM) modelling method, as it uses the Multi-Gaussian Expansion parameterization (Emsellem et al. 1994) for the galaxy surface brightness.

With the addition of the single extra parameter βz=1-(σzR)2, the simple and user-friendly JAM method provides a dramatic improvement over the less general but widely used two-integrals f(E,Lz) Jeans (1922) models. The JAM models provide good descriptions of state-of-the-art integral-field stellar kinematics of real galaxies (Figure 1). 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.

The JAM routines are designed for axisymmetric or spherical geometry, (i) they can provide the proper motion dispersion tensor (Figure 2), (ii) allow for the inclusion of dark matter, (iii) variable stellar M/L, (iv) supermassive black holes (BH; Figure 3), (v) spatially varying anisotropy and (vi) multiple kinematic components (Figure 4). The JAM package also includes a routine to compute the circular velocity from the MGE models. Some sample applications of the JAM method are given below:

To construct dynamical models with the JAM method one needs to describe the galaxies surface brightness via the Multi-Gaussian Expansion parametrization using my MGE_FIT_SECTORS package above.

Figure 3: JAM models examples of kinematically decoupled components. (a) Three-parameters JAM description of the SAURON stellar kinematics of the early-type galaxy NGC4550, which contains two counter-rotating stellar disks (Cappellari et al. 2007). To reproduce the observed velocity field, the flattest (q' < 0.25) Gaussians of the MGE model were assigned opposite rotation (κ < 0). (b) Same as in [a] but with the model orbits all rotating in the same direction. (c) Best fitting JAM model of NGC5308, with constant anisotropy (βz = 0.28 and κ = 1.02) (Cappellari 2008). (d) Same as in [c], but with a non-rotating bulge (κ = 0). (e) Same as in [c] but with an isotropic bulge (βz = 0) and an anisotropic disk (βz = 0.28). The best model has an oblate velocity ellipsoid, with the same strong anisotropy and the same rotation for both the bulge and the disk!

Download the JAM source code

The source code of the JAM modelling package in IDL (and free GDL or FL), with documentation and examples, can be downloaded here in ZIP format (45 KB). This version was last updated on 28 May 2012 and the changes are documented in the program files.

The full JAM package also runs in the free IDL clone FL, even faster than in IDL. With a small change to PLOT_VELFIELD, proper plotting can also be obtained. The computational part of all the JAM programs also runs correctly (albeit slower) under the free and open-source IDL clone GDL, with a couple of minor workarounds. Unfortunately the auxiliary plotting routine PLOT_VELFIELD does not currently work in GDL, and the /PLOT keyword cannot be used there. Ask me for help if you use JAM with GDL or FL.

I would appreciate if you drop me an e-mail (address at the bottom) when you download the JAM package.

Also required are the generic plotting routines SAURON_COLORMAP and PLOT_VELFIELD which can be found in this ZIP file.

And if you just started using IDL and still do not have the IDL Astronomy User's Library installed, or if you have an old version, you should immediately get it from here.


Cappellari & Copin (2003)
Left: Four-coloring of Voronoi binning; Middle: Unbinned versus Voronoi binned Integral-Field Spectroscopy (Cappellari & Copin 2003); Right: Voronoi binning of X-ray data (Sanders et al. 2004).

3. The Voronoi binning method

An IDL (and free GDL or FL) program to bin two-dimensional data to a constant signal-to-noise ratio per bin

The Voronoi Binning method of Cappellari & Copin (2003, MNRAS, 342, 345) optimally solves the problem of preserving the maximum spatial resolution of general two-dimensional data, given a constraint on the minimum signal-to-noise ratio.

The Voronoi binning method has been applied to a variety of types of data. A review of the concepts and applications to (i) X-ray data, (ii) integral-field spectroscopy, (iii) Fabry-Perot interferometry, (iv) N-body simulations, (v) standard images and (vi) other regularly or irregularly sampled data is given in Cappellari (2009).

Download the Voronoi Binning source code

The source code of the IDL (and free GDL or FL) program VORONOI_2D_BINNING, with examples and instructions, can be downloaded here in ZIP format (41 KB). This version was last updated on 15 May 2012 and the changes are documented in the program file. Some minor adaptations of the routine may be required to optimally use the method with different types of data. Please ask for suggestions if needed.

The Voronoi binning example included in the distribution also runs unmodified and without errors, except for graphical issues, under both free and open-source IDL clones GDL or FL.

I would appreciate if you drop me an e-mail (address at the bottom) when you download VORONOI_2D_BINNING.

This optional ZIP file contains the routines DISPLAY_BINS, DISPLAY_PIXELS, PLOT_VELFIELD and SAURON_COLORMAP which can be used to visualize Voronoi 2D-binned or unbinned data, either using interpolation, or by showing the actual bins like in the figures above.


4. Penalized Pixel-Fitting (pPXF)

An IDL (and free GDL or FL) program to extract the stellar kinematics or stellar population from absorption-line spectra of galaxies

ppxf_fit_NGC3379ppxf_fit_NGC4150ppxf_fit_NGC4278ppxf_fit_NGC4459
Figure 1: pPXF fit (red) to SAURON spectra (white) of NGC 3379, NGC 4150, NGC 4278 and NGC 4459 in the wavelength region 480-538nm. The fit residuals are plotted in green and the non-fitted gas emission lines in blue.

This software implements the Penalized Pixel-Fitting method (pPXF) developed by Cappellari & Emsellem (2004, PASP, 116, 138) to extract the stellar kinematics or stellar population from absorption-line spectra of galaxies, using a maximum penalized likelihood approach. The following key features are also implemented in the pPXF routine:

See Emsellem et al. (2004) and Cappellari et al. (2011) for two large-scale applications of the pPXF method to the measurement of the stellar kinematics of galaxies. Falcon-Barroso et al. (2004) present an example of using the optimal template generated by pPXF to extract the gas kinematics from galaxy spectra and to measure emission-corrected line-strength indexes. McDermid et al. (2006; their Fig. 3) use pPXF for spectral flux calibration, and extract the kinematics of a large galaxy sample. Cappellari et al. (2009) use pPXF to measure velocity dispersion of a sample of 9 passive early-type galaxies at redshift z~2.

Minimizing template mismatch with pPXF

The ability of the pPXF method to fit a large set of stellar templates together with the kinematics allows the template mismatch problem to be virtually eliminated. This is particularly useful given the current availability of large stellar libraries spanning wide ranges of physical parameters and having good spectral resolution. Excellent results have been obtained by using a few hundred template stars with pPXF, from which generally about 10-20 are selected by the program to provide detailed fits to high S/N galaxy spectra (e.g. the four panels of Figure 1 show pPXF fits to SAURON spectra using the full MILES stellar library). An extensive account of the available stellar libraries is maintained by David Montes. An incomplete list of libraries that have been succesfully used with pPXF for the kinematics extraction is given below:

pPXF for Population
Figure 2: Population with pPXF. The top panels show the pPXF fit to the SDSS DR8 spectrum of the early-type galaxy NGC4452, using as templates a subset of 26(Ages)×6([M/H])=156 MILES model spectra by Vazdekis et al. (2010). The bottom panels show the corresponding pPXF solution for the distribution of the mass fraction in different age and metallicity intervals. The Left Panel has no regularization and the resulting solution is difficult to interpret: it is dominated by a few model spectra with quite different characteristics. The Right Panel shows the smoothest solution consistent with the data. It has a quite extended distribution dominated in mass by an old stellar population and nearly solar mean metallicity. As expected, the so-called 2/3 rule age-metallicity degeneracy (magenta arrow) tends to produce constant mass fractions along lines of increasing [M/H] and decreasing Age.

Using pPXF to study stellar populations

It is perhaps not entirely obvious to pPXF users that when one uses as input templates a set of synthetic galaxy spectra, arranged in a grid of ages and metallicities, pPXF constitutes a state-of-the-art method to extract stellar population information from observed galaxy spectra. When used in this way pPXF is the most efficient and reliable public implementation of the so called "Full-Spectrum Fitting" method to study stellar populations, which is becoming a popular alternative to using line-strength indices, due to the availability of high-quality model spectra (e.g. Bruzual & Charlot 2003; Vazdekis et al. 2010; Maraston & Stromback 2011; Conroy & van Dokkum 2012).

A number of similar, but less optimized, implementations of the Full Spectrum Fitting method exist (e.g. STARLIGHT by Cid Fernandes et al. 2005; STECKMAP by Ocvirk, et al. 2006; VESPA by Tojeiro et al. 2007). Contrary to most of the available codes, pPXF also includes (keyword REGUL) the ability to enforce linear regularization to the problem (Press et al. 1992, Sec.18.5). This feature is essential to make sense of the derived star formation histories (SFH) of individual galaxies and to explore model degeneracies (see Figure 2).

See Cappellari et al. (2012, Nature) for a pPXF study of the M/L and IMF of stellar populations, and figure 20 of Onodera et al. (2012) for an application of pPXF to the study of the star formation history of passive galaxies at redshift z~2.

Extracting gas kinematics

If you are interested in both the stellar and gas kinematics, or if you want to clean the gas from a spectrum, to study the underlying stellar population, you may want to use pPXF in combination with GANDALF. Please acknowledge both the pPXF (Cappellari & Emsellem 2004) and the GANDALF (Sarzi et al. 2006) papers if you use the two programs together. See Oh et al. (2011) for a large-scale application of the pPXF and GANDALF combination.

Download the pPXF source code

The source code of the IDL (and free GDL or FL) program PPXF, with examples and instructions, can be downloaded here in ZIP format (210 KB). This version was last updated on the 15 November 2012 and the changes are documented in the program file. All users are recomended to upgrade to version 4.6 or later of PPXF. See the important note in the README file for a proper usage of pPXF!

The usage example included in the distribution also runs unmodified, including graphical output, under the free and open-source IDL clones GDL or FL.

The following two IDL routines are also required to run pPXF. They must be downloaded separately:

I would appreciate if you drop me an e-mail (address at the bottom) when you download pPXF.

And if you just started using IDL and still do not have the IDL Astronomy User's Library installed, or if you have an old version, you should immediately get it from here.


Best fitting symmetrized kinematics of NGC 2974

5. Fit kinematic PA

An IDL program to fit the global kinematic position-angle of galaxies

This software implements the method presented in Appendix C of Krajnovic et al. (2006, MNRAS, 366, 787) to measure the global kinematic position-angle (PA) from integral field observations of a galaxy stellar or gas kinematics.

See Cappellari et al. (2007) and Krajnovic et al. (2011) for two large scale application of this software to the study of the stellar kinematical misalignment of early-type galaxies. See Davor's Krajnovic page for the related Kinemetry package.

Download the FIT_KINEMATIC_PA source code

The source code of the IDL program FIT_KINEMATIC_PA, with examples and instructions, can be downloaded here in ZIP format (9 KB). This version was last updated on 23 March 2010 and the changes are documented in the program file. Also required are the generic plotting routines SAURON_COLORMAP and PLOT_VELFIELD which can be found in this ZIP file.

I would appreciate if you drop me an e-mail (address at the bottom) when you download FIT_KINEMATIC_PA.

And if you just started using IDL and still do not have the IDL Astronomy User's Library installed, or if you have an old version, you should immediately get it from here.


Figure 1: Fitting of the (M/L)-σ relation in the Virgo cluster using LTS_LINEFIT (from Cappellari et al. 2013a, MNRAS). The green outliers above the relation are automatically removed from the fit. They turn out to be background galaxies and for this reason they do not follow the cluster relation.

6. LTS_LINEFIT and LTS_PLANEFIT

Two IDL programs to robustly fit lines and planes to data with intrinsic scatter

This software implements the method presented in Sec. 3.2 of Cappellari et al. (2013a, MNRAS) to to perform extremely robust fit of lines or planes to data with large outliers (bada data) and significant but unknown intrinsic scatter.

The code combines the Least Trimmed Squares (LTS) robust technique of Rousseeuw & Driessen (2006) into a least-squares fitting algorithm which allows for intrinsic scatter. This method makes the fit converge to the correct solution even in the presence of a large number of catastrophic outliers (like in Figure 1), where the much simpler σ-clipping approach can converge to the wrong solution.

Download the LTS_LINEFIT and LTS_PLANEFIT source code

The source code of the IDL programs LTS_LINEFIT and LTS_PLANEFIT can be downloaded here in ZIP format (9 KB). This version was last updated on 16 May 2013 and the changes are documented in the program file.

I would appreciate if you drop me an e-mail (address at the bottom) when you download LTS_LINEFIT and LTS_PLANEFIT.

The following two IDL routine are also required to run the two programs. They must be downloaded separately:

And if you just started using IDL and still do not have the IDL Astronomy User's Library installed, or if you have an old version, you should immediately get it from here.


Application of the CAP_LOESS_2D routine to the recovery of two underlying functions from a noisy distribution of 200 scattered values.

7. CAP_LOESS_1D and CAP_LOESS_2D

Two IDL programs to recover mean trends from noisy data in one or two dimension

This software provides an improved implementation of the one-dimensional (Clevelend 1979) and two-dimensional (Cleveland & Devlin 1988) Locally Weighted Regression (LOESS) method to recover the mean trends of the population from noisy data in one or two dimensions. It includes a robust approach to deal with outliers (bad data).

These programs were implemented and used to produce the two-dimensional maps and the one-dimensional mean trends in Cappellari et al. (2013b, MNRAS).

Download the CAP_LOESS_1D and CAP_LOESS_2D source code

The source code of the IDL programs CAP_LOESS_1D and CAP_LOESS_2D can be downloaded here in ZIP format (5 KB). This version was last updated on 16 May 2013 and the changes are documented in the program file.

I would appreciate if you drop me an e-mail (address at the bottom) when you download the code.

And if you just started using IDL and still do not have the IDL Astronomy User's Library installed, or if you have an old version, you should immediately get it from here.


Comments and suggestions are welcome to the address e-mail

Latest changes: 16/MAY/2013 Go back to Michele Cappellari Homepage