WARNING: Except for use with the /lrg flag for Luminous Red Galaxies, the photo-z code is NOT sufficiently tested for the v4 templates
Once one has constructed the SED templates, it is trivial to use them to calculate photometric redshifts.
Fitting photometric redshifts just requires fitting the coefficients for a number of redshifts and minimizing the chi^2 residuals for the fits. I provide routines here to do so.
A piece of advice on the type of magnitudes to use for SDSS photometric redshifts. For modern versions of PHOTO (v5_4 and later) it is best to simply use the model magnitudes for all galaxies. (And indeed this is what we use in sdss_kphotoz.
The IDL routine kphotoz works in a way which is extremely similar to the kcorrect routine.
IDL> kphotoz
Syntax - kphotoz, maggies, maggies_ivar, photoz [ , $
/magnitude, /stddev, lfile=, zmin=, zmax=, nz=, $
vfile=, vpath=, filterlist=, filterpath=, rmatrix=, $
zvals=, lambda=, vmatrix=, coeffs=, /verbose, $
lprior=, zprior=, /noprior, /sdssfix ]
For example, one might do the following:
kphotoz, [1., 4.78, 10.96, 14.45, 19.05], $
[1100., 28., 7.7, 4.4, 2.5], $
photoz
Again, there is large overhead, so one-at-a-time is not the way to
call kphotoz. As for kcorrect, you can avoid spending
this overhead more than once either by feeding it lists of objects or
as follows:
kphotoz, [1., 4.78, 10.96, 14.45, 19.05], $
[1100., 28., 7.7, 4.4, 2.5], $
photoz, rmatrix=rmatrix, zvals=zvals
kphotoz, [1., 4.78, 10.96, 14.45, 19.05], $
[1100., 28., 7.7, 4.4, 2.5], $
photoz, rmatrix=rmatrix, zvals=zvals
Finally, the /sdssfix option fixes SDSS magnitudes in the same way as
for kcorrect.
By default, kphotoz uses a very simple prior (equal to the redshift z) to push the fits away from z=0. You can turn this off with the flag /noprior, or specify your own prior using the inputs zprior (which indicates the redshift grid) and lprior (which indicates the natural log of the prior).
The stand-alone program fit_photoz works in the same way as fit_coeffs:
apeiron.[v3_1].27 % fit_photoz --help Usage: catAs in:| fit_photoz [--vfile --lfile --ffile ]
cat maggies.dat | fit_photozwhere in this case each line of "maggies.dat" has the form:
umaggies gmaggies rmaggies imaggies zmaggies uinvvar ginvvar rinvvar iinvvar zinvvarThe output is again to standard out and is of the form:
photoz coeff0 coeff1 coeff2The same rules apply here as to the IDL code: call the code for many objects at a time, or else the overhead (about 3 seconds) will kill you.
The photo-z code can also be accessed through the C library libkcorrect.so. Follow the directions in the main page for using this library. Instead of k_fit_coeffs, you will be calling k_fit_photoz, as in:
k_fit_photoz(photoz, coeffs, rmatrix, nk, nv, zprior, lprior, nprior,
zvals, nz, maggies, maggies_ivar, ngalaxy, tolerance,
maxiter, niter, chi2, verbose)
zprior, lprior, and nprior should contain the prior grid to use.
Please note that the photometric redshifts resulting from this code are not in any sense "official" SDSS photometric redshifts. They have not been subject to the care and scrutiny given to the official photometric redshifts. In addition, they should be used with due regard to the correlations between errors in type and errors in redshift, as well as the systematic errors associated with photometric redshifts.
Finally, this code can be (almost) trivially adapted to any optical photometry results for galaxies in the redshift range 0 to 0.5. All you need to do is to specify a different set of filters, make sure your magnitudes are AB, and plug away!