instructsTut2

Tutorial 2: Photometric Redshifts
Due: Wednesday 15 April 2015, 11:59pm
Introduction
In this tutorial you will start off by reading in model SEDs and filter transmission curves, shift
the galaxy SED to arbitrary redshifts, convolve the model with the appropriate filter curve and
calculate the apparent magnitude in the various filters (part A). By doing so, you will be able
to build a ‘grid’ of model magnitudes for comparison with real data in order to estimate best-fit
photometric redshifts (part B).
The steps needed for this are relatively straightforward and this sheet will lead you through them.
However, you must be very careful to check that the results are sensible at each step or you will end
up with crazy answers at the final stage. It’s the GIGO principle (Garbage In = Garbage Out).
Hint: Plan your code carefully and write separate functions for routines you will use often or where
it makes sense to separate out a calculation. The more modular you make your code, the easier it
will be to track down mistakes (or skip more difficult sections and come back to fix later).
IMPORTANT NOTE ABOUT SAGEMATHCLOUD
If you’re working on sagemathcloud, there is a compatibility issue between their (old) version of
matplotlib and astropy. It means that, if you try to plot a quantity which has astropy units
associated with it, matplotlib will crash.
e.g.,
x = np.arange(0,1000,10)
y = x**2
xu = x*u.Angstrom
plot(xu,y)
will crash.
The quick workaround for this is to remove the units when plotting with the ”.value” modifier.
i.e., xu.value is the same as x here. So,
plot(xu.value,y)
1
will work.
This bug makes astropy units a little inconvenient on sagemathcloud, but I still encourage you
to try to learn to work with units. If you choose to work on your own machine and have recent
versions of astropy and matplotlib installed, you shouldn’t have this problem. You may submit
code from your own machine which fails to plot on sagemathcloud for this reason without penalty.
Part A: Building the models (Friday 27 March 2015)
The model SED
For simplicity we are just going to use a single SED-type. This is the Luminous Red Galaxy (LRG)
SED from Blanton & Roweis (2007) as mentioned in the lecture notes. The file lrg1 sed1.dat
A−1 ).
contains wavelength (˚
A), and fλ in cgs units (i.e. erg cm−2 s−1 ˚
Question 1).
Make a plot similar to those shown in the class notes showing fλ vs λ for the LRG SED.
Label the axes appropriately with units. Hint: \AA is ˚
A in case you haven’t met that before.
Plot the SDSS filter curves over the top. Hint: multiply the filter curve by some appropriate
factor for display purposes only. Make sure you don’t propagate this renormalisation any
further through your code. It’s just to check that everything look sensible at this stage.
Plot the product of the filter transmission curve and the galaxy SED. Hint: it would be a
good idea both here and throughout your code to interpolate the wavelengths onto one common
wavelength vector.
Calculating magnitudes
Question 2).
Write a routine to calculate the AB magnitude of a given SED through any of the SDSS
filters.
Hint: you will need to integrate the results of the previous question with the appropriate
normalisation constant for the AB system. All the equations you need for this can be found
in the class notes.
Extra hint: try to keep the code general and don’t “hardwire” in the SED used. You will want
to pass different SEDs in the next step.
What are the g,r,i,z magnitudes of the template LRG SED?
2
Redshifting the model
Question 3).
Write a routine to take the wavelength and flux, fλ , of the given model SED and return the
new wavelength and flux at an arbitrary redshift.
Hints: you will need to make changes to both the wavelength and the flux. The change in
wavelength should be trivial.
The change in flux will require much more thought! If you can’t manage this part of the
question, don’t worry. It will just affect your ability to answer one question in part B. You
can proceed through the whole tutorial without explicitly correcting for the normalisation
change with redshift in this routine. Try: Hogg astro-ph/9905116, Section 7 (I recommend
you stay in λ throughout, rather than try to change to ν). You will need to know the distance
to calculate the rest-frame luminosity of the model SED which can be found by looking at the
caption of the figure in the original Blanton & Roweis paper.
Again, I recommend that you interpolate your answer to the same common wavelength vector
you used above. This will make putting the output of this routine into the input of the above
routine much easier!
Building the model ’grid’
Now that we have the above routines in place, we’re ready to build a ‘grid’ (actually just a line,
since the only variable being used is redshift). This is in preparation for fitting the redshifts of real
data to the model in part B.
Question 4).
Put the above two routines together so that we now have a new routine which takes the LRG
template and an input redshift and calculates the griz magnitudes at this redshift. Note: we
will drop the u-band from further consideration as it’s not useful in constraining the photo-z
of LRGs.
Once you have this routine use it to calculate the griz magnitudes of the model SED in “small
steps” in redshift from z=0.0 to z=0.7.
Hint: Actually, you should probably make the first bin non-zero for practical reasons.
Decide what “small step” means in terms of how precisely you think a photo-z can be calculated
from these data.
You will need to store the set of four magnitudes at each ‘trial redshift’ for use in the photo-z
fitting in the next part. Think about how to efficiently build this array for querying later.
Make plots of a) (g − r) colour vs redshift; b) (r − z) colour vs redshift. Do these colours
seem sensible? How did you check?
3
PART B (Friday 10 April 2015)
In this second part, we will take the routines for calculating model magnitudes at different redshifts
and use this as the basis for fitting to real photometric data. The photometric data provided are all
for LRGs, so the template you are using should provide a good fit (once appropriately redshifted
and normalised in flux) to each object.
Reading in SDSS photometry
Read in the data file LRG lowz sample.dat containing magnitudes and magnitude uncertainties
from SDSS data. It would also be a good idea to keep track of the object ID numbers for ease of
referring to specific galaxies later.
Note: the magnitudes in the file need to be corrected for extinction due to the Earth’s atmosphere,
as discussed in class. Do this for each magnitude by subtracting1 the appropriate value in the
extinction column for that filter. e.g.,
modelMagCalibrated u = modelMag u − extinction u
Converting magnitudes and uncertainties to fluxes and uncertainties
Before fitting, we must convert the magnitudes and their uncertainties “back” to fluxes. We don’t
need to worry about zeropoints because we’ve already taken care of this, but it is vital that we
do the modelling in linear (flux) space rather than log (magnitude) space. Hint: Use the general
relation between magnitude and flux (ignore the zeropoint); use the relation given in the notes for
converting magnitude uncertainty to fractional flux uncertainty.
Fitting for redshift
Now we are ready to fit for the (unknown) redshift of each LRG. Using any technique you like (e.g.,
simple χ2 minimisation, MCMC, etc.) write a routine to take the photometry of each SDSS LRG
from the datafile provided and find its best fit redshift.
Remember, there are two unknowns to be fitted: the redshift, z, and the unknown normalisation
constant which determines how intrinsically bright the galaxy is.
The only restrictions on the fitting method you choose are that you must be able to explain clearly
1
This should intuitively makes sense as subtracting a positive number makes the object’s magnitude brighter, as
it should be if its observed magnitude was dimmed by the Earth’s atmosphere
4
the method you are using and how it finds the best fit redshift (and normalisation); and that you
must be able to plot your fitting statistic as a function of trial redshift for any given galaxy.
Question 5)
Write the fitting code described above.
Record the best fit redshift for each galaxy.
Plot your fitting statistic as a function of redshift for galaxy 1237648703517425814 and
1237648722316362093.
Bonus question: If you were able to correctly account for the reduction in flux with increasing
distance in question 3, then your normalisation constant here has physical meaning. Explain what
it is and give the physically interesting value for each galaxy (remember units!). What assumptions
(if any) did you have to make? Hint: you might need to go back and look at the figure caption in
the paper again if you didn’t note it in your answer to question 3.
Question 6)
Make a plot of spectroscopic redshift vs your photometric redshift. Hint: the spectroscopic
redshift is already stored in the file you read in.
Comment on the agreement. Is this what you’d expect?
Getting more SDSS data
Note: for the following queries, copy the appropriate MySQL code either as comments in your
python code (preferred) or attach them as text in some sensible way.
Now that you’ve constructed your own photometric redshift code and run it on the data provided,
it’s time to let you loose on SDSS to get your own data. Remember: we’re only fitting one
template currently, so this will only work well on galaxies pre-selected to have this type of spectrum.
Fortunately, the LRG query is one of the examples given on the SDSS webserver.
Go to http://skyserver.sdss.org/dr12/en/tools/search/sql.aspx to access the SQL query
form. (Note: this is a newer data release, DR12, than the URL given in the notes, DR7, but the
format should be exactly the same).
Look at the sample queries (see notes if unsure where to find) and find the LRG query. Use this as
the basis of a query to download your own sample of LRGs. Warning: don’t make the query too
large or it won’t finish in a reasonable amount of time. Just requesting ∼10-100 objects is plenty.
5
Question 7)
Download your own sample of SDSS LRGs and calculate their best fit photo-zs with your
code.
Bonus question Write a MySQL query to return spectroscopic redshifts for the objects you just
downloaded. Hint: the default query when you first opened the webpage is an example of the query
you need to match the spectroscopic catalogue to the photometric catalogue.
Extra Bonus question Repeat the above bonus question, but find one of the available photometric
redshifts from the SDSS database. Hint: you may need to look in one of the other tables of
properties using the schema browser. Plot your photo-z vs this photo-z for these objects. How do
they compare? How might you decide which (if either) is better?
6