Detailed run

An example of a complete run of lephare with all stages required to estimate redshift. In contrast to the two first notebooks we are not using the high level prepare and process methods. Instead we are using the more fundamental filter, sedtolib, mag_gal, and zphota which more resembles a command line based run.

We show how to include new filters from the Spanish Virtual Observatory (SVO).

Again this notebook uses the COSMOS2020 (Weaver et al. 2022) data as an example.

The notebook can be downloaded here.

[1]:
import os

os.environ["OMP_NUM_THREADS"] = "5"
import lephare as lp
import numpy as np
from matplotlib import pylab as plt

%matplotlib inline
User defined LEPHAREDIR is set. Code runs depend on all required
auxiliary data being present at /home/docs/.cache/lephare/data.
User defined LEPHAREWORK is set. All intermediate files will be written to:
 /home/docs/.cache/lephare/work
OMP_NUM_THREADS set to 1 (max available CPUs: 2)

Set up the parameters

As for the previous notebooks we are starting with the default COSMOS config that ships with the lephare Python code.

Modification of three keywords of the parameter file.

[2]:
# Default config from COSMOS
config = lp.default_cosmos_config.copy()

# You could also load this from a local text file:
# config=lp.keymap_to_string_dict(lp.read_config("your_own.para"))
# An example can be downloaded with curl
# !curl -s -o ./COSMOS.para https://raw.githubusercontent.com/lephare-photoz/lephare-data/refs/heads/main/examples/COSMOS.para
# config = lp.read_config("./COSMOS.para")

# update keywords
config.update(
    {
        # Verbose must be NO in the notebook.
        "VERBOSE": "NO",
        # this line reduced the zgrid density from the default to make the notebook run faster.
        # Comment this out for better science results
        "Z_STEP": "0.04,0.,6.",
    }
)

Then we get the auxiliary files required to run the notebook for the documentation. If you have cloned the full auxiliary data repository you do not need to run this.

[3]:
lp.data_retrieval.get_auxiliary_data(
    keymap=config,
    additional_files=["examples/COSMOS.in", "examples/config_svo_filters.yml", "examples/output.para"],
)
Local registry file is up to date: data_registry.txt
/home/docs/checkouts/readthedocs.org/user_builds/lephare/envs/latest/lib/python3.10/site-packages/lephare/data_retrieval.py:431: UserWarning: /home/docs/.cache/lephare/data/sed/STAR/STAR_MOD_ALL.list is present locally and will not be overwritten.
  warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/lephare/envs/latest/lib/python3.10/site-packages/lephare/data_retrieval.py:431: UserWarning: /home/docs/.cache/lephare/data/sed/GAL/COSMOS_SED/COSMOS_MOD.list is present locally and will not be overwritten.
  warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/lephare/envs/latest/lib/python3.10/site-packages/lephare/data_retrieval.py:431: UserWarning: /home/docs/.cache/lephare/data/sed/QSO/SALVATO09/AGN_MOD.list is present locally and will not be overwritten.
  warnings.warn(
Checking/downloading 442 files...
442 completed.
All files downloaded successfully and are non-empty.
Downloading file 'examples/config_svo_filters.yml' from 'https://raw.githubusercontent.com/lephare-photoz/lephare-data/main/examples/config_svo_filters.yml' to '/home/docs/.cache/lephare/data'.
Checking/downloading 3 files...
3 completed.
All files downloaded successfully and are non-empty.

Create filter library

Read the filter names to be used in COSMOS.para and generate the filter file

First, you can use the standard method with the list of filters in the parameter file. The filters are store in the LEPHAREDIR/filt directory. You can pass either the config file or the keymap as argument

Getting new filters

Each filter requires a filter response curve. This is a table of wavelength values in Angstrom and filter transmission in arbitrary units. In this example we get the filters we need from the SVO. We could have also used the filters that are available in $LEPHAREDIR/filt. Or one could also use local files.

[4]:
# This would get the filters from the config file and local LEPHAREDIR/filt location.
# Later we see how to do the same from the SVO.
filterRunner = lp.Filter(config_keymap=lp.all_types_to_keymap(config))
filterLib = filterRunner.run()
# NAME                        IDENT      Lbda_mean Lbeff(Vega)       FWHM     AB-cor    TG-cor      VEGA M_sun(AB)   CALIB      Lb_eff    Fac_corr
u_cfht.lowres                 1             3844.1      3908.3       537.9    0.3150   -0.3891  -20.6345    6.0327       0      0.3815      1.0000
u_new.pb                      2             3689.8      3749.5       456.0    0.6195   -0.2745  -20.8527    6.3135       0      0.3668      1.0000
gHSC.pb                       3             4850.6      4760.2      1194.2   -0.0860   -0.2458  -20.7272    5.0764       0      0.4780      1.0000
rHSC.pb                       4             6241.4      6142.0      1538.5    0.1466    0.2580  -21.5143    4.6523       0      0.6178      1.0000
iHSC.pb                       5             7716.5      7636.7      1476.1    0.3942    0.6138  -22.2286    4.5323       0      0.7666      1.0000
zHSC.pb                       6             8915.2      8906.7       768.0    0.5169    0.7625  -22.6733    4.5147       0      0.8903      1.0000
yHSC.pb                       7             9801.2      9770.6       796.8    0.5534    0.7763  -22.9145    4.5081       0      0.9782      1.0000
Y.lowres                      8            10222.2     10195.8       919.2    0.6043    0.8180  -23.0574    4.5130       0      1.0206      1.0000
J.lowres                      9            12554.9     12480.6      1712.3    0.9228  -99.0000  -23.8194    4.5638       0      1.2514      1.0000
H.lowres                      10           16497.4     16351.6      2892.7    1.3701  -99.0000  -24.8565    4.7045       0      1.6409      1.0000
K.lowres                      11           21576.6     21434.8      2926.3    1.8335  -99.0000  -25.9057    5.1316       0      2.1502      1.0000
IB427.lowres                  12            4263.9      4255.9       206.5   -0.1446   -0.4942  -20.4117    5.5152       0      0.4262      1.0000
IB464.lowres                  13            4636.1      4633.3       218.1   -0.1520   -0.3463  -20.5860    5.0658       0      0.4634      1.0000
IB484.lowres                  14            4850.7      4846.4       228.2   -0.0241   -0.1770  -20.8122    4.9880       0      0.4849      1.0000
IB505.lowres                  15            5063.6      5060.6       230.9   -0.0656   -0.1366  -20.8639    4.9423       0      0.5061      1.0000
IB527.lowres                  16            5262.3      5258.9       242.1   -0.0260   -0.0464  -20.9871    4.8937       0      0.5260      1.0000
IB574.lowres                  17            5766.0      5762.0       272.1    0.0657    0.1377  -21.2773    4.7042       0      0.5763      1.0000
IB624.lowres                  18            6234.5      6230.0       300.6    0.1527    0.2768  -21.5339    4.6386       0      0.6232      1.0000
IB679.lowres                  19            6782.6      6778.6       336.5    0.2542    0.4288  -21.8183    4.5709       0      0.6779      1.0000
IB709.lowres                  20            7075.0      7070.6       315.6    0.2982    0.4968  -21.9541    4.5558       0      0.7072      1.0000
IB738.lowres                  21            7362.7      7358.5       323.5    0.3460    0.5577  -22.0886    4.5449       0      0.7360      1.0000
IB767.lowres                  22            7686.6      7681.2       363.8    0.3992    0.6164  -22.2351    4.5243       0      0.7683      1.0000
IB827.lowres                  23            8245.9      8241.0       343.7    0.4891    0.7300  -22.4777    4.5161       0      0.8243      1.0000
NB711.lowres                  24            7119.9      7119.4        72.6    0.3072    0.5084  -21.9774    4.5542       0      0.7120      1.0000
NB816.lowres                  25            8149.9      8149.2       119.8    0.4713    0.7098  -22.4349    4.5154       0      0.8149      1.0000
NB118.lowres                  26           11909.2     11908.6       112.3    0.8376  -99.0000  -23.6250    4.5554       0      1.1909      1.0000
irac_ch1.lowres               27           35763.0     35263.7      7410.9    2.7951  -99.0000  -27.9585    6.0679       1      3.5634      1.0036
irac_ch2.lowres               28           45289.5     44608.6     10104.6    3.2634  -99.0000  -28.9384    6.5680       1      4.5111      1.0040
irac_ch3.lowres               29           57873.0     56764.7     13508.5    3.7537  -99.0000  -29.9581    7.0472       1      5.7592      1.0050
irac_ch4.lowres               30           80442.3     77033.1     28394.0    4.3959  -99.0000  -31.2962    7.6701       1      7.9590      1.0110

It is also possible to pass all the necessary keywords as arguments to the constructor:

[5]:
# the config keymap from a config file can also be added to the constructor's arguments, in which case the keywords
# will be overridden by the explicit keywords passed as arguments below.
filterRunner2 = lp.Filter(
    FILTER_REP=os.path.join(os.environ["LEPHAREDIR"], "filt"),
    FILTER_LIST="cosmos/u_cfht.lowres,cosmos/u_new.pb,hsc/gHSC.pb,hsc/rHSC.pb,\
                       hsc/iHSC.pb,hsc/zHSC.pb,hsc/yHSC.pb,vista/Y.lowres,vista/J.lowres,vista/H.lowres,\
                       vista/K.lowres,cosmos/IB427.lowres,cosmos/IB464.lowres,cosmos/IB484.lowres,\
                       cosmos/IB505.lowres,cosmos/IB527.lowres,cosmos/IB574.lowres,cosmos/IB624.lowres,\
                       cosmos/IB679.lowres,cosmos/IB709.lowres,cosmos/IB738.lowres,cosmos/IB767.lowres,\
                       cosmos/IB827.lowres,cosmos/NB711.lowres,cosmos/NB816.lowres,vista/NB118.lowres,\
                       cosmos/irac_ch1.lowres,cosmos/irac_ch2.lowres,cosmos/irac_ch3.lowres,cosmos/irac_ch4.lowres",
    TRANS_TYPE=1,
    FILTER_CALIB="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1",
    FILTER_FILE="filter_cosmos",
)
filterLib2 = filterRunner2.run()
# NAME                        IDENT      Lbda_mean Lbeff(Vega)       FWHM     AB-cor    TG-cor      VEGA M_sun(AB)   CALIB      Lb_eff    Fac_corr
u_cfht.lowres                 1             3844.1      3908.3       537.9    0.3150   -0.3891  -20.6345    6.0327       0      0.3815      1.0000
u_new.pb                      2             3689.8      3749.5       456.0    0.6195   -0.2745  -20.8527    6.3135       0      0.3668      1.0000
gHSC.pb                       3             4850.6      4760.2      1194.2   -0.0860   -0.2458  -20.7272    5.0764       0      0.4780      1.0000
rHSC.pb                       4             6241.4      6142.0      1538.5    0.1466    0.2580  -21.5143    4.6523       0      0.6178      1.0000
iHSC.pb                       5             7716.5      7636.7      1476.1    0.3942    0.6138  -22.2286    4.5323       0      0.7666      1.0000
zHSC.pb                       6             8915.2      8906.7       768.0    0.5169    0.7625  -22.6733    4.5147       0      0.8903      1.0000
yHSC.pb                       7             9801.2      9770.6       796.8    0.5534    0.7763  -22.9145    4.5081       0      0.9782      1.0000
Y.lowres                      8            10222.2     10195.8       919.2    0.6043    0.8180  -23.0574    4.5130       0      1.0206      1.0000
J.lowres                      9            12554.9     12480.6      1712.3    0.9228  -99.0000  -23.8194    4.5638       0      1.2514      1.0000
H.lowres                      10           16497.4     16351.6      2892.7    1.3701  -99.0000  -24.8565    4.7045       0      1.6409      1.0000
K.lowres                      11           21576.6     21434.8      2926.3    1.8335  -99.0000  -25.9057    5.1316       0      2.1502      1.0000
IB427.lowres                  12            4263.9      4255.9       206.5   -0.1446   -0.4942  -20.4117    5.5152       0      0.4262      1.0000
IB464.lowres                  13            4636.1      4633.3       218.1   -0.1520   -0.3463  -20.5860    5.0658       0      0.4634      1.0000
IB484.lowres                  14            4850.7      4846.4       228.2   -0.0241   -0.1770  -20.8122    4.9880       0      0.4849      1.0000
IB505.lowres                  15            5063.6      5060.6       230.9   -0.0656   -0.1366  -20.8639    4.9423       0      0.5061      1.0000
IB527.lowres                  16            5262.3      5258.9       242.1   -0.0260   -0.0464  -20.9871    4.8937       0      0.5260      1.0000
IB574.lowres                  17            5766.0      5762.0       272.1    0.0657    0.1377  -21.2773    4.7042       0      0.5763      1.0000
IB624.lowres                  18            6234.5      6230.0       300.6    0.1527    0.2768  -21.5339    4.6386       0      0.6232      1.0000
IB679.lowres                  19            6782.6      6778.6       336.5    0.2542    0.4288  -21.8183    4.5709       0      0.6779      1.0000
IB709.lowres                  20            7075.0      7070.6       315.6    0.2982    0.4968  -21.9541    4.5558       0      0.7072      1.0000
IB738.lowres                  21            7362.7      7358.5       323.5    0.3460    0.5577  -22.0886    4.5449       0      0.7360      1.0000
IB767.lowres                  22            7686.6      7681.2       363.8    0.3992    0.6164  -22.2351    4.5243       0      0.7683      1.0000
IB827.lowres                  23            8245.9      8241.0       343.7    0.4891    0.7300  -22.4777    4.5161       0      0.8243      1.0000
NB711.lowres                  24            7119.9      7119.4        72.6    0.3072    0.5084  -21.9774    4.5542       0      0.7120      1.0000
NB816.lowres                  25            8149.9      8149.2       119.8    0.4713    0.7098  -22.4349    4.5154       0      0.8149      1.0000
NB118.lowres                  26           11909.2     11908.6       112.3    0.8376  -99.0000  -23.6250    4.5554       0      1.1909      1.0000
irac_ch1.lowres               27           35763.0     35263.7      7410.9    2.7951  -99.0000  -27.9585    6.0679       1      3.5634      1.0036
irac_ch2.lowres               28           45289.5     44608.6     10104.6    3.2634  -99.0000  -28.9384    6.5680       1      4.5111      1.0040
irac_ch3.lowres               29           57873.0     56764.7     13508.5    3.7537  -99.0000  -29.9581    7.0472       1      5.7592      1.0050
irac_ch4.lowres               30           80442.3     77033.1     28394.0    4.3959  -99.0000  -31.2962    7.6701       1      7.9590      1.0110

Second, you can use the filterSvc helper class to gain more freedom. This class allows to retrieve the list of filt objetcs, independently of writing them on file.

[6]:
filterLib = lp.FilterSvc.from_keymap(lp.all_types_to_keymap(config))
filter_output = os.path.join(os.environ["LEPHAREWORK"], "filt", config["FILTER_FILE"])
lp.write_output_filter(filter_output + ".dat", filter_output + ".doc", filterLib)
# NAME                        IDENT      Lbda_mean Lbeff(Vega)       FWHM     AB-cor    TG-cor      VEGA M_sun(AB)   CALIB      Lb_eff    Fac_corr
u_cfht.lowres                 1             3844.1      3908.3       537.9    0.3150   -0.3891  -20.6345    6.0327       0      0.3815      1.0000
u_new.pb                      2             3689.8      3749.5       456.0    0.6195   -0.2745  -20.8527    6.3135       0      0.3668      1.0000
gHSC.pb                       3             4850.6      4760.2      1194.2   -0.0860   -0.2458  -20.7272    5.0764       0      0.4780      1.0000
rHSC.pb                       4             6241.4      6142.0      1538.5    0.1466    0.2580  -21.5143    4.6523       0      0.6178      1.0000
iHSC.pb                       5             7716.5      7636.7      1476.1    0.3942    0.6138  -22.2286    4.5323       0      0.7666      1.0000
zHSC.pb                       6             8915.2      8906.7       768.0    0.5169    0.7625  -22.6733    4.5147       0      0.8903      1.0000
yHSC.pb                       7             9801.2      9770.6       796.8    0.5534    0.7763  -22.9145    4.5081       0      0.9782      1.0000
Y.lowres                      8            10222.2     10195.8       919.2    0.6043    0.8180  -23.0574    4.5130       0      1.0206      1.0000
J.lowres                      9            12554.9     12480.6      1712.3    0.9228  -99.0000  -23.8194    4.5638       0      1.2514      1.0000
H.lowres                      10           16497.4     16351.6      2892.7    1.3701  -99.0000  -24.8565    4.7045       0      1.6409      1.0000
K.lowres                      11           21576.6     21434.8      2926.3    1.8335  -99.0000  -25.9057    5.1316       0      2.1502      1.0000
IB427.lowres                  12            4263.9      4255.9       206.5   -0.1446   -0.4942  -20.4117    5.5152       0      0.4262      1.0000
IB464.lowres                  13            4636.1      4633.3       218.1   -0.1520   -0.3463  -20.5860    5.0658       0      0.4634      1.0000
IB484.lowres                  14            4850.7      4846.4       228.2   -0.0241   -0.1770  -20.8122    4.9880       0      0.4849      1.0000
IB505.lowres                  15            5063.6      5060.6       230.9   -0.0656   -0.1366  -20.8639    4.9423       0      0.5061      1.0000
IB527.lowres                  16            5262.3      5258.9       242.1   -0.0260   -0.0464  -20.9871    4.8937       0      0.5260      1.0000
IB574.lowres                  17            5766.0      5762.0       272.1    0.0657    0.1377  -21.2773    4.7042       0      0.5763      1.0000
IB624.lowres                  18            6234.5      6230.0       300.6    0.1527    0.2768  -21.5339    4.6386       0      0.6232      1.0000
IB679.lowres                  19            6782.6      6778.6       336.5    0.2542    0.4288  -21.8183    4.5709       0      0.6779      1.0000
IB709.lowres                  20            7075.0      7070.6       315.6    0.2982    0.4968  -21.9541    4.5558       0      0.7072      1.0000
IB738.lowres                  21            7362.7      7358.5       323.5    0.3460    0.5577  -22.0886    4.5449       0      0.7360      1.0000
IB767.lowres                  22            7686.6      7681.2       363.8    0.3992    0.6164  -22.2351    4.5243       0      0.7683      1.0000
IB827.lowres                  23            8245.9      8241.0       343.7    0.4891    0.7300  -22.4777    4.5161       0      0.8243      1.0000
NB711.lowres                  24            7119.9      7119.4        72.6    0.3072    0.5084  -21.9774    4.5542       0      0.7120      1.0000
NB816.lowres                  25            8149.9      8149.2       119.8    0.4713    0.7098  -22.4349    4.5154       0      0.8149      1.0000
NB118.lowres                  26           11909.2     11908.6       112.3    0.8376  -99.0000  -23.6250    4.5554       0      1.1909      1.0000
irac_ch1.lowres               27           35763.0     35263.7      7410.9    2.7951  -99.0000  -27.9585    6.0679       1      3.5634      1.0036
irac_ch2.lowres               28           45289.5     44608.6     10104.6    3.2634  -99.0000  -28.9384    6.5680       1      4.5111      1.0040
irac_ch3.lowres               29           57873.0     56764.7     13508.5    3.7537  -99.0000  -29.9581    7.0472       1      5.7592      1.0050
irac_ch4.lowres               30           80442.3     77033.1     28394.0    4.3959  -99.0000  -31.2962    7.6701       1      7.9590      1.0110

It also allows to load the filters from a yaml file, with the possibility to query the SVO service for filters

[7]:
!ls $LEPHAREDIR/examples/
COSMOS.in  COSMOS.para  config_svo_filters.yml  output.para
[8]:
# We use an example yaml file to retrieve the filter names used by the SVO
try:
    filterLibSVO = lp.FilterSvc.from_yaml(f"{lp.LEPHAREDIR}/examples/config_svo_filters.yml")
except lp.SVOUnavailableError as err:
    # The SVO server is sometimes unreachable (also when the documentation is built):
    # use the local filters instead, so that the notebook can still be run.
    print(f"WARNING: {err}\nThe local filters are used instead of those of the SVO.")
    filterLibSVO = filterLib
filter_output = os.path.join(os.environ["LEPHAREWORK"], "filt", config["FILTER_FILE"])
lp.write_output_filter(filter_output + "_svo.dat", filter_output + "_svo.doc", filterLibSVO)
# NAME                        IDENT      Lbda_mean Lbeff(Vega)       FWHM     AB-cor    TG-cor      VEGA M_sun(AB)   CALIB      Lb_eff    Fac_corr
MegaCam.u_1                   2             3817.6      3884.2       600.9    0.3478   -0.3793  -20.6542    6.0708       0      0.3793      1.0000
MegaCam.u                     3             3692.8      3752.5       456.4    0.6143   -0.2762  -20.8493    6.3092       0      0.3671      1.0000
HSC.g                         4             4850.9      4760.3      1186.5   -0.0860   -0.2457  -20.7273    5.0764       0      0.4780      1.0000
HSC.r                         5             6264.9      6168.6      1496.4    0.1518    0.2660  -21.5284    4.6480       0      0.6203      1.0000
HSC.i                         6             7769.3      7683.1      1559.7    0.4032    0.6245  -22.2518    4.5314       0      0.7715      1.0000
HSC.z                         7             8917.6      8908.8       773.8    0.5168    0.7624  -22.6737    4.5146       0      0.8905      1.0000
HSC.Y                         8             9789.2      9758.7       793.0    0.5526    0.7764  -22.9110    4.5082       0      0.9770      1.0000
VISTA.Y                       9            10222.8     10196.4       917.6    0.6044    0.8180  -23.0575    4.5130       0      1.0206      1.0000
VISTA.J                       10           12555.8     12481.3      1713.4    0.9229  -99.0000  -23.8197    4.5638       0      1.2515      1.0000
VISTA.H                       11           16499.3     16353.3      2894.1    1.3703  -99.0000  -24.8569    4.7046       0      1.6411      1.0000
VISTA.Ks                      12           21577.3     21435.6      3057.4    1.8335  -99.0000  -25.9058    5.1317       0      2.1502      1.0000
Suprime.IB427                 13            4264.4      4256.3       206.4   -0.1436   -0.4933  -20.4130    5.5150       0      0.4262      1.0000
Suprime.IB464                 14            4636.1      4633.3       218.1   -0.1520   -0.3463  -20.5860    5.0659       0      0.4634      1.0000
Suprime.IB484                 15            4850.2      4845.9       228.3   -0.0241   -0.1773  -20.8119    4.9882       0      0.4848      1.0000
Suprime.IB505                 16            5063.5      5060.6       230.8   -0.0656   -0.1366  -20.8640    4.9423       0      0.5061      1.0000
Suprime.IB527                 17            5262.3      5258.9       241.9   -0.0260   -0.0464  -20.9871    4.8938       0      0.5260      1.0000
Suprime.IB574                 18            5766.0      5762.1       271.8    0.0657    0.1377  -21.2773    4.7042       0      0.5763      1.0000
Suprime.IB624                 19            6234.5      6230.0       300.1    0.1527    0.2768  -21.5339    4.6386       0      0.6232      1.0000
Suprime.IB679                 20            6782.6      6778.6       336.2    0.2542    0.4288  -21.8183    4.5709       0      0.6779      1.0000
Suprime.IB709                 21            7074.9      7070.6       315.6    0.2982    0.4968  -21.9541    4.5558       0      0.7072      1.0000
Suprime.IB738                 22            7362.8      7358.5       323.7    0.3460    0.5577  -22.0886    4.5449       0      0.7360      1.0000
Suprime.IB767                 23            7686.6      7681.2       363.6    0.3992    0.6164  -22.2351    4.5243       0      0.7683      1.0000
Suprime.IB827                 24            8246.0      8241.0       343.5    0.4891    0.7300  -22.4777    4.5161       0      0.8243      1.0000
Suprime.NB711                 25            7120.0      7119.5        72.3    0.3072    0.5084  -21.9775    4.5541       0      0.7120      1.0000
Suprime.NB816                 26            8149.8      8149.1       119.7    0.4713    0.7098  -22.4349    4.5154       0      0.8149      1.0000
VISTA.NB118                   27           11909.2     11908.6       112.3    0.8376  -99.0000  -23.6249    4.5554       0      1.1909      1.0000
IRAC.I1                       28           35572.6     35074.3      7431.7    2.7842  -99.0000  -27.9359    6.0572       0      3.5314      1.0000
IRAC.I2                       29           45050.9     44373.2     10096.8    3.2530  -99.0000  -28.9165    6.5561       0      4.4694      1.0000
IRAC.I3                       30           57386.4     56286.7     13911.9    3.7363  -99.0000  -29.9222    7.0310       0      5.6821      1.0000
IRAC.I4                       31           79267.8     75890.0     28311.8    4.3645  -99.0000  -31.2322    7.6389       0      7.7543      1.0000

Plot the filters. We can see slight differences between those on the SVO and in the lepahre database.

[9]:
fig = plt.figure(figsize=(15, 8))
for f, fsvo in zip(filterLib, filterLibSVO):
    d = f.data()
    plt.semilogx(d[0], d[1] / d[1].max())
    dsvo = fsvo.data()
    plt.semilogx(dsvo[0], dsvo[1] / dsvo[1].max(), ".")
../_images/notebooks_Detailed_run_18_0.png
[10]:
# filter_output = os.path.join(os.environ["LEPHAREWORK"],"filt", filterLib.keymap['FILTER_FILE'] + ".dat")
# This figure shows that the filters have differing normalisation which has no impact on the fitting process.
filters = np.loadtxt(
    filter_output + ".dat", dtype={"names": ("lamb", "val", "bid"), "formats": (float, float, int)}
)
plt.loglog(filters["lamb"], filters["val"])
plt.xlabel("wavelength");
../_images/notebooks_Detailed_run_19_0.png

Create SED library

SED objects represent SED templates belonging to one of the three possible classes “STAR”, “QSO” (for AGN type of objects), and “GAL” for galaxies. SED templates available with LePhare can be found under the sed directory.

[11]:
sedlib = lp.Sedtolib(config_keymap=lp.all_types_to_keymap(config))
[12]:
sedlib.run(typ="STAR", star_sed="$LEPHAREDIR/sed/STAR/STAR_MOD_ALL.list")
#######################################
# It s translating SEDs to binary library #
# with the following options :
# Config file     :
# Library type     : STAR
# STAR_SED    :/home/docs/.cache/lephare/data/sed/STAR/STAR_MOD_ALL.list
# STAR_LIB    :LIB_STAR
# STAR_LIB doc:/home/docs/.cache/lephare/work/lib_bin/LIB_STAR.doc
# STAR_FSCALE :0.0000
#######################################
Number of templates in the list 254
Number of SED in the list (including different ages) 254
[13]:
sedlib.run(typ="QSO", qso_sed="$LEPHAREDIR/sed/QSO/SALVATO09/AGN_MOD.list", gal_lib="LIB_QSO")
#######################################
# It s translating SEDs to binary library #
# with the following options :
# Config file     :
# Library type     : QSO
# QSO_SED    :/home/docs/.cache/lephare/data/sed/QSO/SALVATO09/AGN_MOD.list
# QSO_LIB    :LIB_QSO
# QSO_LIB doc:/home/docs/.cache/lephare/work/lib_bin/LIB_QSO.doc
# QSO_FSCALE :1.0000
#######################################
Number of templates in the list 30
Number of SED in the list (including different ages) 30
[14]:
sedlib.run(typ="GAL", gal_sed="$LEPHAREDIR/sed/GAL/COSMOS_SED/COSMOS_MOD.list", gal_lib="LIB_GAL")
#######################################
# It s translating SEDs to binary library #
# with the following options :
# Config file     :
# Library type     : GAL
# GAL_SED    :/home/docs/.cache/lephare/data/sed/GAL/COSMOS_SED/COSMOS_MOD.list
# GAL_LIB    :LIB_GAL
# GAL_LIB doc:/home/docs/.cache/lephare/work/lib_bin/LIB_GAL.doc
# GAL_LIB phys:/home/docs/.cache/lephare/work/lib_bin/LIB_GAL.phys
# SEL_AGE    :none
# GAL_FSCALE :1.0000
# AGE_RANGE   0.0000 15000000000.0000
#######################################
Number of templates in the list 31
Number of SED in the list (including different ages) 31

Create a magnitude library

Use the SED library to create a magnitude library

[15]:
maglib = lp.MagGal(config_keymap=lp.all_types_to_keymap(config))
[16]:
maglib.run(
    typ="STAR",
    lib_ascii="YES",
    star_lib_out="STAR_COSMOS",
    extinc_law="SB_calzetti.dat",
    mod_extinc="0,0",
)
#######################################
# It s computing the SYNTHETIC MAGNITUDES #
# For Gal/QSO libraries with these OPTIONS #
# with the following options :
# Config file     :
# Filter file     : filter_cosmos
# Magnitude type     : AB
# COSMOLOGY   :70.0000,0.3000,0.7000
# STAR_LIB_IN    :/home/docs/.cache/lephare/work/lib_bin/LIB_STAR(.doc & .bin)
# STAR_LIB_OUT   :/home/docs/.cache/lephare/work/lib_mag/STAR_COSMOS(.doc & .bin)
# LIB_ASCII   YES
# MW_GALAMETZ   NO
# EXT_MW_CURVE   CARDELLI
# CREATION_DATE Wed Oct 28 09:37:45 2026
#############################################
[17]:
maglib.run(
    typ="QSO",
    lib_ascii="YES",
    mod_extinc="0,1000",
    eb_v="0.,0.1,0.2,0.3",
    extinc_law="SB_calzetti.dat",
    qso_lib_in="LIB_QSO",
    qso_lib_out="QSO_COSMOS",
)
#######################################
# It s computing the SYNTHETIC MAGNITUDES #
# For Gal/QSO libraries with these OPTIONS #
# with the following options :
# Config file     :
# Filter file     : filter_cosmos
# Magnitude type     : AB
# QSO_LIB_IN    :/home/docs/.cache/lephare/work/lib_bin/LIB_QSO(.doc & .bin)
# QSO_LIB_OUT   :/home/docs/.cache/lephare/work/lib_mag/QSO_COSMOS(.doc & .bin)
# Z_STEP   :0.0400 0.0000 6.0000
# COSMOLOGY   :70.0000,0.3000,0.7000
# EXTINC_LAW   :SB_calzetti.dat
# MOD_EXTINC   :0 1000
# EB_V   :0.0000 0.1000 0.2000 0.3000
# MW_GALAMETZ   NO
# EXT_MW_CURVE   CARDELLI
# LIB_ASCII   YES
# CREATION_DATE Wed Oct 28 09:37:45 2026
#############################################
[18]:
maglib.run(
    typ="GAL",
    lib_ascii="YES",
    gal_lib_in="LIB_GAL",
    gal_lib_out="GAL_COSMOS",
    mod_extinc="18,26,26,33,26,33,26,33",
    extinc_law="SMC_prevot.dat,SB_calzetti.dat,SB_calzetti_bump1.dat,SB_calzetti_bump2.dat",
    em_lines="EMP_UV",
    em_dispersion="0.5,0.75,1.,1.5,2.",
)
#######################################
# It s computing the SYNTHETIC MAGNITUDES #
# For Gal/QSO libraries with these OPTIONS #
# with the following options :
# Config file     :
# Filter file     : filter_cosmos
# Magnitude type     : AB
# GAL_LIB_IN    :/home/docs/.cache/lephare/work/lib_bin/LIB_GAL(.doc & .bin)
# GAL_LIB_OUT   :/home/docs/.cache/lephare/work/lib_mag/GAL_COSMOS(.doc & .bin)
# Z_STEP   :0.0400 0.0000 6.0000
# COSMOLOGY   :70.0000,0.3000,0.7000
# EXTINC_LAW   :SMC_prevot.dat SB_calzetti.dat SB_calzetti_bump1.dat SB_calzetti_bump2.dat
# MOD_EXTINC   :18 26 26 33 26 33 26 33
# EB_V   :0.0000 0.1000 0.2000 0.3000
# EM_LINES   EMP_UV
# EM_DISPERSION   0.5000,0.7500,1.0000,1.5000,2.0000,
# MW_GALAMETZ   NO
# EXT_MW_CURVE   CARDELLI
# LIB_ASCII   YES
# CREATION_DATE Wed Oct 28 09:37:47 2026
#############################################

Run the photoz

Read the parameter file and store the keywords. Example with the modification of three keywords of the parameter file. Verbose must be NO in the notebook.

[19]:
# These are the names created above with the argument gal_lib_out
config.update(
    {
        "ZPHOTLIB": "GAL_COSMOS,STAR_COSMOS,QSO_COSMOS",
        "SPEC_OUT": "save_spec",
        "AUTO_ADAPT": "YES",
        # "APPLY_SYSSHIFT": "0.049,-0.013,-0.055,-0.065,-0.042,-0.044,-0.065,-0.0156,-0.002,0.052,-0.006,0.071,0.055,0.036,0.036,0.054,0.088,0.019,-0.154,0.040,0.044,0.060,0.045,0.022,0.062,0.033,0.015,0.012,0.0,0.0]"
        "CHI2_OUT": "NO",
    }
)

Instantiate a lephare.PhotoZ object which will manage the computation of photometric redshifts for all sources. It is instantiated based on all the config parameters.

[20]:
photz = lp.PhotoZ(lp.all_types_to_keymap(config))
#######################################
# PHOTOMETRIC REDSHIFT with OPTIONS   #
# Config file            :
# CAT_IN                 : change_me_to_output_filename_required.ascii
# CAT_OUT                : zphot.out
# CAT_LINES              : 0 1000000000
# PARA_OUT               : /home/docs/.cache/lephare/data/examples/output.para
# INP_TYPE               : F
# CAT_FMT[0:MEME 1:MMEE] : 0
# CAT_MAG                : AB
# ZPHOTLIB               : GAL_COSMOS STAR_COSMOS QSO_COSMOS
# APPLY_MW_EXTINCTION    : NO
# FIR_LIB                :
# FIR_LMIN               : 7.000000
# FIR_CONT               : -1.000000
# FIR_SCALE              : -1.000000
# FIR_FREESCALE          : YES
# FIR_SUBSTELLAR         : NO
# ERR_SCALE              : 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.050000 0.050000 0.050000 0.050000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.020000 0.050000 0.050000 0.050000 0.050000 0.100000 0.200000 0.300000
# ERR_FACTOR             : 1.500000
# GLB_CONTEXT            : 0
# FORB_CONTEXT           : -1
# DZ_WIN                 : 1.000000
# MIN_THRES              : 0.020000
# MAG_ABS                : -24.000000 -5.000000
# MAG_ABS_AGN            : -30.000000 -10.000000
# MAG_REF                : 3
# NZ_PRIOR               : -1 -1
# Z_INTERP               : YES
# Z_METHOD               : BEST
# MABS_METHOD            : 1
# MABS_CONTEXT           : 33556478
# MABS_REF               : 11
# AUTO_ADAPT             : YES
# ADAPT_BAND             : 5
# ADAPT_LIM              : 1.500000 23.000000
# ADAPT_ZBIN             : 0.010000 6.000000
# ZFIX                   : NO
# SPEC_OUT               : save_spec
# CHI_OUT                : NO
# PDZ_OUT                : test
#######################################
Reading input librairies ...
Read lib
Number of keywords to be read in the doc: 15
Number of keywords read at the command line (excluding -c config): 0
Reading keywords from /home/docs/.cache/lephare/work/lib_mag/QSO_COSMOS.doc
Number of keywords read in the config file: 18
Keyword NUMBER_ROWS not provided
Keyword NUMBER_SED not provided
Keyword Z_FORM not provided
Reading library: /home/docs/.cache/lephare/work/lib_mag/QSO_COSMOS.bin
 Done with the library reading with 18120 SED read.
Number of keywords to be read in the doc: 15
Number of keywords read at the command line (excluding -c config): 0
Reading keywords from /home/docs/.cache/lephare/work/lib_mag/STAR_COSMOS.doc
Number of keywords read in the config file: 18
Keyword NUMBER_ROWS not provided
Keyword NUMBER_SED not provided
Keyword Z_FORM not provided
Reading library: /home/docs/.cache/lephare/work/lib_mag/STAR_COSMOS.bin
 Done with the library reading with 18374 SED read.
Number of keywords to be read in the doc: 15
Number of keywords read at the command line (excluding -c config): 0
Reading keywords from /home/docs/.cache/lephare/work/lib_mag/GAL_COSMOS.doc
Number of keywords read in the config file: 18
Keyword NUMBER_ROWS not provided
Keyword NUMBER_SED not provided
Keyword Z_FORM not provided
Reading library: /home/docs/.cache/lephare/work/lib_mag/GAL_COSMOS.bin
 Done with the library reading with 102934 SED read.
Read lib out
Done reading the FIR lib
# NAME                        IDENT      Lbda_mean Lbeff(Vega)       FWHM     AB-cor      VEGA   CALIB    Fac_corr
u_cfht.lowres                 1             3844.1      3908.3       537.9    0.3150  -20.6345       0      1.0000
u_new.pb                      2             3689.8      3749.5       456.0    0.6195  -20.8527       0      1.0000
gHSC.pb                       3             4850.6      4760.2      1194.2   -0.0860  -20.7272       0      1.0000
rHSC.pb                       4             6241.4      6142.0      1538.5    0.1466  -21.5143       0      1.0000
iHSC.pb                       5             7716.5      7636.7      1476.1    0.3942  -22.2286       0      1.0000
zHSC.pb                       6             8915.2      8906.7       768.0    0.5169  -22.6733       0      1.0000
yHSC.pb                       7             9801.2      9770.6       796.8    0.5534  -22.9145       0      1.0000
Y.lowres                      8            10222.2     10195.8       919.2    0.6043  -23.0574       0      1.0000
J.lowres                      9            12554.9     12480.6      1712.3    0.9228  -23.8194       0      1.0000
H.lowres                      10           16497.4     16351.6      2892.7    1.3701  -24.8565       0      1.0000
K.lowres                      11           21576.6     21434.8      2926.3    1.8335  -25.9057       0      1.0000
IB427.lowres                  12            4263.9      4255.9       206.5   -0.1446  -20.4117       0      1.0000
IB464.lowres                  13            4636.1      4633.3       218.1   -0.1520  -20.5860       0      1.0000
IB484.lowres                  14            4850.7      4846.4       228.2   -0.0241  -20.8122       0      1.0000
IB505.lowres                  15            5063.6      5060.6       230.9   -0.0656  -20.8639       0      1.0000
IB527.lowres                  16            5262.3      5258.9       242.1   -0.0260  -20.9871       0      1.0000
IB574.lowres                  17            5766.0      5762.0       272.1    0.0657  -21.2773       0      1.0000
IB624.lowres                  18            6234.5      6230.0       300.6    0.1527  -21.5339       0      1.0000
IB679.lowres                  19            6782.6      6778.6       336.5    0.2542  -21.8183       0      1.0000
IB709.lowres                  20            7075.0      7070.6       315.6    0.2982  -21.9541       0      1.0000
IB738.lowres                  21            7362.7      7358.5       323.5    0.3460  -22.0886       0      1.0000
IB767.lowres                  22            7686.6      7681.2       363.8    0.3992  -22.2351       0      1.0000
IB827.lowres                  23            8245.9      8241.0       343.7    0.4891  -22.4777       0      1.0000
NB711.lowres                  24            7119.9      7119.4        72.6    0.3072  -21.9774       0      1.0000
NB816.lowres                  25            8149.9      8149.2       119.8    0.4713  -22.4349       0      1.0000
NB118.lowres                  26           11909.2     11908.6       112.3    0.8376  -23.6250       0      1.0000
irac_ch1.lowres               27           35763.0     35263.7      7410.9    2.7951  -27.9585       1      1.0036
irac_ch2.lowres               28           45289.5     44608.6     10104.6    3.2634  -28.9384       1      1.0040
irac_ch3.lowres               29           57873.0     56764.7     13508.5    3.7537  -29.9581       1      1.0050
irac_ch4.lowres               30           80442.3     77033.1     28394.0    4.3959  -31.2962       1      1.0110

Read the input file with the following information: id, flux and associated uncertainties in all bands, a context indicating which bands to use in the fit (0 indicates all bands), and a spectrocopic redshift if it exists.

[21]:
cat = np.loadtxt(f"{lp.LEPHAREDIR}/examples/COSMOS.in")
id = cat[:, 0]
fluxes = cat[:, 1:60:2]
efluxes = cat[:, 2:61:2]
context = cat[:, 61]
zspec = cat[:, 62]
print("Check format with context and zspec :", context, zspec)
Check format with context and zspec : [0. 0. 0. ... 0. 0. 0.] [4.839  1.166  0.1649 ... 0.214  0.3053 0.3448]

Create a list of sources with a spec-z. Use for the zero-point training or any validation run.

[22]:
srclist = []
# Here, limited to the 1000 first sources.
n_obj = 100
zspec_mask = np.logical_and(zspec > 0.01, zspec < 6)
# We are running on the last n_obj objects to use a different set of objects to perform
# zero-point correction to the test objects
for i in np.where(zspec_mask)[0][-n_obj:]:
    # Each element of the list is an instance of the lephare.onesource class.
    # This encapsulates all the information for a given source.
    oneObj = lp.onesource(i, photz.gridz)
    oneObj.readsource(str(id[i]), fluxes[i, :], efluxes[i, :], int(context[i]), zspec[i], " ")
    # lephare.PhotoZ passes the configuration parameters to each source.
    photz.prep_data(oneObj)
    srclist.append(oneObj)
print("Sources with a spec-z: ", len(srclist))
Sources with a spec-z:  100

Derive the zero-points offsets. This corresponds to the median difference between apparent and observed magnitude in each filter. It is stored in the list, a0, which is later passed to the lephare.PhotoZ.run_photoz method. If AUTO_ADAPT is NO, values will be set at 0. If APPLY_SYSSHIFT is defined, that’s the values which will be used for a0.

[23]:
a0 = photz.compute_offsets(srclist)
offsets = ",".join(np.array(a0).astype(str))
offsets = "# Offsets to be added to the modeled magnitudes: " + offsets + "\n"
print(offsets)
 Done with iteration 1 and converge 0
# Offsets to be added to the modeled magnitudes: 0.1072876902088602,-0.0020114216555242592,-0.047505809583217484,-0.12104608309720888,-0.11072038333515977,-0.10043273277701559,-0.12861846335626836,-0.0734508827876823,-0.0629044766921254,-0.0072150666954620135,-0.09789962486497572,0.10296160865133785,0.05407068212852906,0.03974695758738633,0.05170690731160832,0.022446003753703536,0.05708936369202533,-0.042322732636666416,-0.18525065391812845,-0.027796046661638485,-0.004696112122370977,0.02293691026752498,0.001957818460166294,-0.06042188239907631,0.02172145970057926,-0.0078105847328764355,-0.09697256057273762,-0.1208252142205275,0.0,0.0

 Done with iteration 2 and converge 0
 Done with iteration 3 and converge 0
 Done with iteration 4 and converge 1

Create the list of sources for which we want a photo-z.

[24]:
photozlist = []
for i in range(n_obj):
    oneObj = lp.onesource(i, photz.gridz)
    oneObj.readsource(str(id[i]), fluxes[i, :], efluxes[i, :], int(context[i]), zspec[i], " ")
    photz.prep_data(oneObj)
    photozlist.append(oneObj)
print("Number of sources to be analysed: ", len(srclist))
Number of sources to be analysed:  100

Run the photoz. We pass the values of the zero point calibration calculated above

[25]:
photz.run_photoz(photozlist, a0)

Compute additional quality flag for each object

[26]:
flags = []
for i, src in enumerate(photozlist):
    flags.append(src.compute_quality_flag())
plt.hist(flags, bins=15)
[26]:
(array([93.,  3.,  0.,  0.,  0.,  2.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,
         0.,  1.]),
 array([ 0.        ,  0.86666667,  1.73333333,  2.6       ,  3.46666667,
         4.33333333,  5.2       ,  6.06666667,  6.93333333,  7.8       ,
         8.66666667,  9.53333333, 10.4       , 11.26666667, 12.13333333,
        13.        ]),
 <BarContainer object of 15 artists>)
../_images/notebooks_Detailed_run_46_1.png
[ ]:

Save the parameters that have been used

For capturing the parameters that were used in a given run it is useful to save the updated config to file. Be careful as this will not capture the overrides that were sent directly to the lephare.MagGal.run method which impact the outputs.

[27]:
# we can write the config to a file to keep a record
lp.write_para_config(lp.all_types_to_keymap(config), "./config_file.para")
# One can also save it as a yaml file if you prefer
lp.write_yaml_config(lp.all_types_to_keymap(config), "./config_file.yaml")

Create output in fits

[28]:
t = photz.build_output_tables(photozlist[:n_obj], para_out=None, filename="outputphotoz.fits")
[29]:
t[:5]
[29]:
Table length=5
IDENTZ_BESTZ_BEST68_LOWZ_BEST68_HIGHZ_MEDZ_MED68_LOWZ_MED68_HIGHCHI_BESTMOD_BESTEXTLAW_BESTEBV_BESTZ_SECCHI_SECMOD_SECEBV_SECZQ_BESTCHI_QSOMOD_QSOMOD_STARCHI_STARMAG_OBS()ERR_MAG_OBS()K_COR()MAG_ABS()EMAG_ABS()MABS_FILT()SCALE_BESTNBAND_USEDCONTEXTZSPECAGE_BESTAGE_INFAGE_MEDAGE_SUPLDUST_BESTLDUST_INFLDUST_MEDLDUST_SUPLUM_TIR_BESTLUM_TIR_INFLUM_TIR_MEDLUM_TIR_SUPMASS_BESTMASS_INFMASS_MEDMASS_SUPSFR_BESTSFR_INFSFR_MEDSFR_SUPSSFR_BESTSSFR_INFSSFR_MEDSSFR_SUPCOL1_INFCOL1_MEDCOL1_SUPCOL2_INFCOL2_MEDCOL2_SUPLUM_NUV_BESTLUM_R_BESTLUM_K_BESTMAG_PRED()STRING_INPUTPDF_BAY_ZG()
str5float64float64float64float64float64float64float64int64float64float64float64float64int64float64float64float64int64int64float64float64[30]float64[30]float64[30]float64[30]float64[30]float64[30]float64int64int64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64[0]str1float64[151]
1.04.8530179587255424.8389255479964484.8450810659105714.8407790229234724.8130542381293784.86797902354435640.59678266884222291.00.0-99.91000000000.0-99-99.04.775346745527541108.2761974907447229204147.336152732004251000.0 .. 1000.01000.0 .. 1000.015.410312717380435 .. -2.2292014935879054-20.5220421088426 .. -20.019524615495797-1.0 .. -1.0-1.0 .. -1.0220.934464067076022704.839-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-999.0-999.0-999.0-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.99.5412987584972599.1542480081095098.1200612885897560.0 .. 5.406353962211857e-49
2.01.19182966697267731.19607196851301941.20164951207016621.199217625985551.1717055567920661.22694772886657228.445979213707954181.00.1-99.91000000000.0-99-99.00.965309204214451326.09456492346544519136611.655627404395924.716241086822183 .. 1000.00.0964327877384378 .. 1000.00.9749080970168283 .. -0.05266603283400354-20.906021870469502 .. -23.40659820990040.4939262293956439 .. 3.02631447390444565.0 .. 10.0551.01345183623272701.166-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-999.0-999.0-999.0-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.99.4688786708773739.9268998521884489.404373415321473.4537447114339183e-149 .. 0.0
3.00.161156845090988650.159506462706109850.160554137145498180.160.13279999971389770.187200000286102355.9584110184607771.00.0-99.91000000000.0-99-99.00.1448610072235909124.42625857029049998856.565442295984320.34852846025906 .. 1000.00.030183067850864845 .. 1000.00.6949991897408847 .. -0.4077500970514632-19.789021249285735 .. -20.346446370203750.409020137439148 .. 2.71868413509501042.0 .. 10.0149.651583523095352800.1649-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-999.0-999.0-999.0-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.97.843401448360529.6244966867441139.1524464256206814.678435173157799e-201 .. 0.0
4.05.6522543166123175.633916098840685.6653343784412785.37321999471774355.2524825095056285.66436427427819421.837290282044105291.00.0-99.91000000000.0-99-99.05.43726236007292840.363426607151932919662.34037701421786428.19576013148921 .. 1000.01.9744363436325476 .. 1000.016.69949373806199 .. -2.398578214351063-20.98964514698716 .. -20.487127653640357-1.0 .. -1.0-1.0 .. -1.0339.86362319185462805.742-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-999.0-999.0-999.0-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.99.7283399737550849.3412892233673338.3071025038475810.0 .. 2.1636598611766122e-14
5.00.84292715314175490.78649741725902540.92115549279429451.00411415931244160.7948259102453671.170131338785969838.38575942027551312.00.3-99.91000000000.0-99-99.00.1419477531010175451.6166681965104464136109.2242056888707428.437181029993205 .. 1000.02.1272798742731407 .. 1000.00.004327239640851513 .. 0.6020350306905731-16.14873989159669 .. -17.654328687461180.36536003683371554 .. -1.04.0 .. -1.026.2103678892268522805.745-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-999.0-999.0-999.0-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-999.0-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.9-99.98.7138244895452818.145868700921077.0496225304358120.0 .. 1.9702934855304613e-30

Create all ascii files with the output of the run

[30]:
photz.write_outputs(photozlist[:5])
[31]:
# This created the output ascii file specified in the config CAT_OUT parameter
!ls -al zphot.out
-rw-r--r-- 1 docs docs 19737 Oct 28 09:38 zphot.out

Check the results broadly follow a 1-1 relation

[32]:
plt.plot([0, 6], [0, 6], c="r", alpha=0.5)
plt.scatter(t["ZSPEC"], t["Z_BEST"], s=3)
plt.xlabel("z spec")
plt.ylabel("z phot")
[32]:
Text(0, 0.5, 'z phot')
../_images/notebooks_Detailed_run_57_1.png

Make plots for individual sources with all the files listed in save_spec

[33]:
from os import listdir
from os.path import isfile, join

listname = [f for f in listdir("save_spec") if isfile(join("save_spec", f))]
# Lets just look at the top 10
for namefile in listname[:10]:
    lp.plot_spectrum("save_spec/" + str(namefile))
../_images/notebooks_Detailed_run_59_0.png
../_images/notebooks_Detailed_run_59_1.png
../_images/notebooks_Detailed_run_59_2.png
../_images/notebooks_Detailed_run_59_3.png
../_images/notebooks_Detailed_run_59_4.png

You can use some plotting utilities provided with the code. Some examples are provided below. sel_filt is the index of the filter used to select objects by observed magnitude (starting at 0). pos_filt provides the index (starting at 0) of the filters corresponding to u, g, r, z, J, and Ks bands. If you want to create all the plots and store them in a pdf file, you can use: utils.save_photoz_plots_pdf(filename=”all_photoz.pdf”)

[34]:
utils = lp.PlotUtils(
    t,
    sel_filt=4,
    pos_filt=[0, 2, 3, 5, 7, 9],
    range_z=[0, 0.5, 1, 1.5, 3],
    range_mag=[19, 20.5, 21.5, 22.5, 25],
)
[35]:
utils.dist_chi2()
<Figure size 640x480 with 0 Axes>
../_images/notebooks_Detailed_run_62_1.png
[36]:
utils.zml_zs()
<Figure size 640x480 with 0 Axes>
../_images/notebooks_Detailed_run_63_1.png
[37]:
utils.dist_z()
<Figure size 640x480 with 0 Axes>
../_images/notebooks_Detailed_run_64_1.png
[ ]: