EzGal - UMKCgeg/Wiki GitHub Wiki

EzGal is a Python wrapper for stellar population synthesis models. It includes the models of Bruzual and Charlot, Maraston, Conroy, and others. It has online documentation here, which is very useful. This page is not a substitute for that, it's just a quick introduction that will show how to do the common tasks with EzGal.

Stellar Population Synthesis Models

Stellar population synthesis models combine our knowledge of stellar evolution and the observed spectra of stars to create model spectra of galaxies. Given a star formation history, we can calculate what a galaxy will look like as a function of time. Conceptually, that is what codes like EzGal calculate. We can determine the spectra or observed magnitudes of the galaxy at any point in time.

Installing EzGal

The easiest way to install EzGal is with pip, which can take GitHub URLs. Run the following:

pip install git+git://github.com/dpgettings/ezgal.git@master

This will take care of everything for you.

If that won't work for whatever reason, EzGal can be installed by running git clone https://github.com/dpgettings/ezgal.git in a terminal. It will download the code into the directory you are in. Make sure you download the code into a path that Python knows about, so you can import it. Follow the instructions here for info on making sure Python can import EzGal.

The default download comes with two of the most popular models. If you want more models, check the EzGal page here for instructions on how to get more. The downloads can take a while if you download all of them. You will likely only need the Bruzual and Charlot 2003 model set.

Also note that EzGal is only compatible with Python 2 at the moment. You'll also need to install PyFits (which is an outdated package, actually) with pip install pyfits

Error

After you install EzGal, when running it for the first time (see below for what you'll actually do), you might encounter an error. It will be related to PyFits, and will be complaining about something related to missing cards or header keywords. This error only affects the metadata in the models, which isn't that important and won't affect any of the outputs. You can find the lines of code in EzGal that causes the error, and comment our the lines that cause the error. Keep the function it's in, obviously, but there doesn't have to be anything in it (other than possibly a return statement). This error needs to be documented in more detail, since it can't be replicated at the moment. If you discover this error yourself, please update this section with more info.

Using EzGal

EzGal allows for the calculation of many different observables. As mentioned above, the two most important ones are magnitudes and spectra.

Using Models

EzGal comes with many premade models. The general format of the EzGal models (found in the ezgal/data/models directory) is "modelset_sfh_metallicity_imf.model". The most commonly used model set is Bruzual and Charlot 2003 (bc03). When it comes to the star formation history, "ssp" stands for simple stellar population, and is just an instantaneous burst of star formation at the galaxy's formation. The "exp" models are exponentially declining star formation histories, with the timescale parameter specified afterward. For example, a model with "exp_0.1" is it has an exponentially declining SFH that goes as , where 0.1 is in gigayears. Solar metallicity (z_0.02) is most commonly used, and Chabrier or Kroupa ("chab" or "krou") is the most commonly used IMF. If you're in any doubt, using bc03_ssp_z_0.02_chab.model (as we do in the examples below) is a good default choice.

You can also create models with a custom star formation history if non of the available options meet your needs. Check out the EzGal documentation on the subject for more info.

Magnitudes

The code below shows how to get magnitude predictions for different filters at many different redshifts.

import ezgal
import numpy as np

# create the model object
model = ezgal.ezgal("bc03_ssp_z_0.02_chab.model")

zf = 3.0                             # formation redshift
zs = np.arange(0.1, 1.000001, 0.1)   # observed redshifts

# normalize to Coma
model.set_normalization(filter='ks', mag=10.9, apparent=True, vega=True, z=0.023)

# Calculate the observables we want in AB mags
mags = model.get_apparent_mags(zf, filters=["sloan_r", "sloan_z", "ch1", "ch2"], 
                               zs=zs, ab=True)

Note: The normalization here is something you will need to do every time you use EzGal. Here, we define our object to be one on the knee of the luminosity function of Coma.

The output here (mags) will be a 2 dimensional array. The rows (first index) will be the magnitudes of the object in all the filters at a given redshift. So in our example, mags[0] would give us the r, z, ch1, and ch2 mags at z=0.1. To get the mag in a given filter at many redshifts, you can do something along the lines of the following:

ch1_mags = [mags[i][2] for i in range(10)]

We have 10 redshifts, which is why we do range(10).

Spectra

EzGal has an easy interface to get spectra, too. All we have to specify is the age we want to observe the galaxy at.

import ezgal

model = ezgal.ezgal("bc03_ssp_z_0.02_chab.model")
sed = model.get_sed(10, age_units="gyrs", units="Fv")

Note that this is the rest frame spectra. Different flux units are available. Fv is probably the most useful, since it's a simple conversion to get in microJanskys.

You can also get the rest frame spectra for a galaxy at a given redshift.

import ezgal

model = ezgal.ezgal("bc03_ssp_z_0.02_chab.model")
sed = model.get_sed_z(3, 1.0, units="Fv")

This gets the spectra of a galaxy at redshift 1.0 that formed at redshift 3.

To plot an SED, just get the wavelengths (or frequencies) of the model using model.ls (or model.vs). Then we can simply plot plt.plot(model.ls, sed). You will need to adjust the limits (and probably use log scaling), but that will plot the SED.