Code to determine sfh parameters of galaxy populations with emcee
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit ahead, 5 commits behind rjsmethurst:master.
Latest commit c2dea0c Sep 5, 2016 @astopy astopy committed on GitHub Merge pull request #3 from rjsmethurst/patch-1
Failed to load latest commit information.
m05_lookup_nuv.npy m05 lookup table, 74% complete Sep 15, 2014
nuv_look_up_ssfr.npy lookup tables Jul 10, 2014


A python code to determine the quenched star formation history parameters of a galaxy using the MCMC algorithm emcee ( Please ensure this module is installed and can be imported into your Python installation.

The sample function implements the emcee EnsembleSampler function for the galaxy colours input. Burn-in is run and calculated for the length specified before the sampler is reset and then run for the length of steps specified.


u_r : Observed u-r colour of a galaxy; k-corrected. Single value.

err_u_r : Error on the observed u-r colour of a galaxy. Single value.

nuv_u : Observed nuv-u colour of a galaxy; k-corrected. Single value.

err_nuv_u : Error on the observed nuv-u colour of a galaxy. Single value.

z : Observed redshfit of a galaxy. Single value.

dr8 : Sloan ID DR8 number - can be any identification number for a galaxy.

ra : Right ascension of galaxy in degrees. Used for identification.

dec : Declination of galaxy in degrees. Used for identification.


s : Array of shape (nsteps * nwalkers, 2) containing the positions of the walkers at all steps for all 4 parameters.

fig : s plotted as contours and integrated over to a each one dimensional histogram with median values and 1sigma values either side. The module is necessary to produce these plots and is provided in the starfpy repository. It can also be downloaded here: or with pip install triangle_plot at the command line.

Running the code

Data inputs occur with the file, all necessary functions are in the file. The code can be run as follows:

    python u_r, err_u_r, nuv_u, err_nuv_u, z, dr8, ra, dec

For example:

    python 2.2564125061 0.0635264205263 1.66131782532 0.12668874395 0.033525165 1237661968496984320 163.734802246 41.4984283447

Returns the 50th percentile of the walker positions from emcee for the quenched star formation history parameters [t, tau] as:

    Best fit [t, tau] values found by starpy for input parameters are : [9.3231936694250255, 1.287285042079878]

if using the look up tables provided in the repository.

The posterior function gives you the option of using either the look up tables provided (nuv_look_up_ssfr.npy and ur_look_up_ssfr.npy), a look up table which you have created for NUV-u and u-r or using the SPS model you specify to calculate the colour from an SED each time a new [tq, tau] value is generated by the MCMC chain.

The u-r and NUV-u look up tables provided were generated for 50 observed ages, 100 tau and 100 quenching time values for an exponential quenching SFH model using the expsfh function in Using these look up tables or ones generated by the user will ensure run time is ~3 minutes for one galaxy as opposed to ~3 hours.

You can generate your own look up table in two colours with bu specifying an SPS model (again takes a LONG time).

If you wish to specify an SPS model it must be in a readable format for starpy. You can therefore extract the either the BC03 or M05 SPS models into ASCII files with the or files which use the raw files as downloaded from or respectively.

If you use this code in your research please cite this paper: Smethurst et al. 2015, MNRAS, 450, 435 and acknowledge:

"This work has made use of the StarPy star formation history Python code described in Smethurst et al. (2015)."


Apache 2.