# HOW-TO Photometric redshifts (OLD)¶

The photred code (Bender et al. 2001 (2001defi.conf…96B) and Gabasch et al. 2004 (2004A&A…421…41G)) provides a way to derive redshifts from photometric observations.

WARNING: The code currently uses the MAG_ISO fluxes and magnitudes from the SExtractor catalogs. For SourceLists generated from images with different seeing, the colors will be inaccurate, and the derived photometric redshifts as well.

The user interface consists of two major Python classes, PhotRedConfig and PhotRedCatalog. The PhotRedConfig contains the information about the filters and SEDs used. In PhotRedCatalog the used SourceLists, the two resulting SourceLists with the best-fitting stellar and galactic SEDs and redshifts are stored, as well as an AssociateList of all these lists to allow easy access to the complete information about a given object.

awe> from astro.main.PhotRedCatalog import *


## PhotRedConfig¶

The PhotRedConfig class needs some input calibration files that are stored on the dataserver. In most cases these should be already available in the system. If not, at the end of this HOW-TO, instructions are given on how to import Filters and SEDs.

### PhotRedFilter¶

The PhotRedFilter stores the transmission curve of the filter and is associated with an Astro-WISE Filter object.

awe> filt = (Filter.name == '#842' )[0]
awe> pf = (PhotRedFilter.filter == filt )[0]


### PhotRedSED¶

A PhotRedSED object stores the unprocessed SED of a model galaxy, a table of wavelengths and fluxes, and is referenced by a name given on import, e.g. ‘mod_e’ for an elliptical galaxy.

awe> pse = (PhotRedSED.sed_name == 'mod_e.sed' )[0]
awe> ps1 = (PhotRedSED.sed_name == 'mod_s210.sed' )[0]


### PhotRedStarlib¶

The PhotRedStarlib stores a collection of PhotRedSEDs of different stars. It is referenced by the filename of the list of SED names.

awe> starlib=(PhotRedStarlib.filename=='starlib_pickles.lis')[0]


### PhotRedConfig¶

The PhotRedConfig takes a combination of SEDs and filter names, creates the processed SEDs and Starlib and stores these and other information relevant for PhotRed itself. A PhotRedConfig object is referenced by a unique name, given at creation. This allows the reuse of an existing PhotRedConfig object.

The number of filters selected at creation time can be larger than the number of filters used for PhotRed (as long as the filters of all the SourceLists given to PhotRedCatalog are present in the configuration. Thus it is advisable to create the PhotRedConfig with all PhotRedFilters available, making the combination of SEDs reusable with different combinations of SourceLists.

awe> pc = PhotRedConfig()
awe> pc.SEDs=[pse,ps1,ps2,ps3]
awe> pc.filters=[pfu,pfb,pfv,pfr,pfi]
awe> pc.starlib=(PhotRedStarlib.filename=='starlib_pickles.lis')[0]
awe> pc.name='MyPhotRedConfig'
awe> pc.make()


## PhotRedCatalog¶

The PhotRedCatalog is the main component, doing the actual work determining the best fitting stellar / galactic SED. It reads in the SEDs processed by PhotRedConfig, redshifts them and calculates the least-squares fit of the magnitudes obtained from the combination of the redshifted SEDs and the filter curves against the observed data. The least-squares fit is determined by minimizing:

$\chi^2(z,SED) = \frac{1}{N_{filt}}\sum^{N_{filt}}_{i=1} \frac{\left[f_i - \alpha f_i \left(z,SED\right)\right]^2}{\sigma_i^2 + \left[ 0.005\alpha f_i\left(z,SED\right)\right]^2}$

The probability $$P_T$$ of a source being at a given redshift is calculated as:

$P_T = P_\chi \cdot P_L \cdot P_z = e^{-\frac{1}{2}\chi^2} \cdot e^{-k_\beta \left( \frac{M-M_\star}{\sigma} \right)^\beta } \cdot e^{-k_\gamma \left( \frac{z}{z_{lim}} \right)^\gamma }$

As input it takes the SourceLists and PhotRedConfig. The pr.master stores the master SourceList against which the association of the other SourceLists is done. It has to be in the SourceLists array as well, to allow correlation between the SourceLists, the extinction and model_error arrays.

awe> pr = PhotRedCatalog()
awe> pr.config=pc
awe> pr.master=sV
awe> pr.sourcelists=[sU,sV,sB,sR,sI]


Additionally, individual values for extinction (used for relative corrections of the photometric calibration of the individual SourceLists) and model_errors (to allow some spread between the distinct SEDs) can be specified. The length and the order of the arrays must in both cases be the same as the length iof the list of sourcelists.

awe> pr.extinc=[0.,0.,0.,0.,0.]
awe> pr.model_error=[0.,0.,0.,0.,0.]


The PhotRedCatalog object can be assigned a name for future reference. The resulting SourceLists are created and stored in the database by calling the make function:

awe> pr.name='FDF_UBRI'
awe> pr.make()


## The output SourceLists¶

The resulting SourceLists are stored under in the PhotRedCatalog object as:

awe> pr.datpz1  # Data of best-fitting galactic SED


and

awe> pr.datstar # Data of best-fitting stellar SED


and associate with the master AssociateList.

## The visualization routines¶

For visual inspection a plot of the best-fitting SED, the best-fitting stellar SED, the datapoints and the redshift probability distribution can be done by calling:

awe> pr.plot( 23 ) # For the object with AID 23 in associate_list


## An example from users view¶

Import the needed Python classes:

awe> from astro.main.PhotRedCatalog import *


### PhotRedConfig¶

Create a configuration. This is only needed if no suitable configuration is present in the system, because existing configurations could and should be reused. First select the respective PhotRedFilter objects from the database,

awe> pf1 = (PhotRedFilter.filename == '#843.filter' )[0]
awe> pf2 = (PhotRedFilter.filename == '#844.filter' )[0]
awe> pf3 = (PhotRedFilter.filename == '#846.filter' )[0]
awe> pf4 = (PhotRedFilter.filename == '#878.filter' )[0]
awe> pf5 = (PhotRedFilter.filename == '#879.filter' )[0]


then select the SEDs you want to use from the database,

awe> ps01 = (PhotRedSED.filename == 'manucci_soc.sed' )[0]
awe> ps02 = (PhotRedSED.filename == 'manucci_sac.sed' )[0]
awe> ps03 = (PhotRedSED.filename == 'manucci_sbc.sed' )[0]
awe> ps04 = (PhotRedSED.filename == 'mod_e.sed' )[0]
awe> ps05 = (PhotRedSED.filename == 'mod_s010.sed' )[0]
awe> ps06 = (PhotRedSED.filename == 'mod_s020.sed' )[0]
awe> ps07 = (PhotRedSED.filename == 'mod_s030.sed' )[0]
...


and create the PhotRedConfig object using the standard starlib.

awe> pc = PhotRedConfig()
awe> pc.SEDs=[pse,ps1,ps2,ps3]
awe> pc.filters=[pfu,pfb,pfv,pfr,pfi]
awe> pc.starlib=(PhotRedStarlib.filename=='starlib_pickles.lis')[0]
awe> pc.name='WFI_BgRIz'
awe> pc.make()


### PhotRedCatalog¶

To create the photometric redshifts, a PhotRedConfig object and a list of SourceLists is needed. First select the PhotRedConfig and the SourceLists from the database:

awe> pc=(PhotRedConfig.name=='PhotRedConfig-1114174946.26')[0]
awe> sU=(SourceList.SLID==5)[0]
awe> sB=(SourceList.SLID==6)[0]
awe> sV=(SourceList.SLID==7)[0]
awe> sR=(SourceList.SLID==8)[0]
awe> sI=(SourceList.SLID==9)[0]


With these, the PhotRedCatalog object can be created. Using the V-Band data (in this example) as the master SourceList and the MAG_APER magnitudes, only objects detected in all 5 filters are associated.

awe> pr = PhotRedCatalog()
awe> pr.config=pc
awe> pr.master=sV
awe> pr.sourcelists=[sU,sV,sB,sR,sI]
awe> pr.extinc=[0.,0.,0.,0.,0.]
awe> pr.model_error=[0.1,0.1,0.1,0.1,0.1]
awe> pr.min_num_sources=5
awe> pr.mag='MAG_APER'
awe> pr.flux='FLUX_APER'
awe> pr.fluxerr='FLUXERR_APER
awe> pr.name='photoz_1'
awe> pr.make()


Once the object is made, all data is stored in the pr.associate_list AssociateList.

## Ingestion of Filters and SEDs¶

The ingestion of new / additional SEDs or filter lightcurves is a straightforward process.

### PhotRedFilter¶

The input file for PhotRedFilter is a simple ASCII file with two columns, wavelength in Ångstroms and the transmission of the filter at this wavelength. The values should be sorted with ascending wavelength, and to avoid possible problems contain 2 lines with 0 transmission at the beginning and at the end. The canonical extension for these objects is “.filter”.

To create the Python object, a new PhotRedFilter object pointing to the file on disk is created, and the corresponding Filter object is selected. After this the make routine stores the relevant metadata in the database and the filter curve object on the dataserver.

awe> photredfilter = PhotRedFilter( pathname='wfi_r.filter')
awe> photredfilter.filter=(Filter.mag_id=='Cousins R')
awe> photredfilter.make()


### PhotRedSED¶

The input file for PhotRedSED is a simple text file as well, again with two columns, wavelength in Ångstroms and the normalized flux of the SED. A new PhotRedSED object pointing to the file on disk is created, and the object’s make method is invoked. The metadata is again stored in the database, and the file stored on the dataserver.

awe> photredsed = PhotRedSED( pathname='mod_e.sed')
awe> photredsed.make()