Example of MagSvc class

This demonstrates direct access to the bound c++ functions. It is an advanced use case.

The notebook can be downloaded here.

[1]:
import lephare as lp
import numpy as np
from matplotlib import pylab as plt
from scipy import integrate as sciint
import glob, time

%matplotlib inline
LEPHAREDIR is being set to the default cache directory:
/home/docs/.cache/lephare/data
More than 1Gb may be written there.
LEPHAREWORK is being set to the default cache directory:
/home/docs/.cache/lephare/work
Default work cache is already linked.
This is linked to the run directory:
/home/docs/.cache/lephare/runs/20260304T112842
[2]:
keymap = lp.all_types_to_keymap(lp.default_cosmos_config)
# Get the auxiliary files required.
lp.data_retrieval.get_auxiliary_data(
    keymap=keymap, additional_files=["sed/STAR/BD_NEW/lte012.0-4.0-0.0a+0.0.BT-Settl.spec.txt"]
)
Registry file downloaded and saved as data_registry.txt.
Downloading file 'sed/STAR/BD_NEW/lte012.0-4.0-0.0a+0.0.BT-Settl.spec.txt' from 'https://raw.githubusercontent.com/lephare-photoz/lephare-data/main/sed/STAR/BD_NEW/lte012.0-4.0-0.0a+0.0.BT-Settl.spec.txt' to '/home/docs/.cache/lephare/data'.
Checking/downloading 445 files...
445 completed.
All files downloaded successfully and are non-empty.
Created directory: /home/docs/.cache/lephare/data/sed/STAR/BD_NEW
Checking/downloading 1 files...
1 completed.
All files downloaded successfully and are non-empty.
[3]:
# we can write the config to a file to keep a record
config_file = "./config_file.para"
lp.write_para_config(keymap, config_file)
allFlt = lp.FilterSvc.from_config(config_file)
[4]:
sed = lp.StarSED("test", 0)
sed.read(f"{lp.LEPHAREDIR}/sed/STAR/BD_NEW/lte012.0-4.0-0.0a+0.0.BT-Settl.spec.txt")
[5]:
opavec = lp.GalMag.read_opa()
[6]:
# We need the full previous stages to get the mags
filterLib = lp.Filter(config_file=config_file)
filterLib.run()
sedlib = lp.Sedtolib(config_keymap=keymap)
sedlib.run(typ="STAR", star_sed="$LEPHAREDIR/sed/STAR/STAR_MOD_ALL.list")
sedlib.run(typ="QSO", qso_sed="$LEPHAREDIR/sed/QSO/SALVATO09/AGN_MOD.list", gal_lib="LIB_QSO")
sedlib.run(typ="GAL", gal_sed="$LEPHAREDIR/sed/GAL/COSMOS_SED/COSMOS_MOD.list", gal_lib="LIB_GAL")
maglib = lp.MagGal(config_keymap=keymap)
maglib.run(typ="STAR", lib_ascii="YES", star_lib_out="ALLSTAR_COSMOS")
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",
)
maglib.run(
    typ="GAL",
    lib_ascii="YES",
    gal_lib_in="LIB_GAL",
    gal_lib_out="VISTA_COSMOS_FREE",
    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.",
)
# NAME                        IDENT      Lbda_mean Lbeff(Vega)       FWHM     AB-cor    TG-cor      VEGA M_sun(AB)   CALIB      Lb_eff    Fac_corr
u_cfht.lowres                 1             0.3844      0.3908      0.0538    0.3150   -0.3891  -20.6345    6.0327       0      0.3815      1.0000
u_new.pb                      2             0.3690      0.3750      0.0456    0.6195   -0.2745  -20.8527    6.3135       0      0.3668      1.0000
gHSC.pb                       3             0.4851      0.4760      0.1194   -0.0860   -0.2458  -20.7272    5.0764       0      0.4780      1.0000
rHSC.pb                       4             0.6241      0.6142      0.1539    0.1466    0.2580  -21.5143    4.6523       0      0.6178      1.0000
iHSC.pb                       5             0.7716      0.7637      0.1476    0.3942    0.6138  -22.2286    4.5323       0      0.7666      1.0000
zHSC.pb                       6             0.8915      0.8907      0.0768    0.5169    0.7625  -22.6733    4.5147       0      0.8903      1.0000
yHSC.pb                       7             0.9801      0.9771      0.0797    0.5534    0.7763  -22.9145    4.5081       0      0.9782      1.0000
Y.lowres                      8             1.0222      1.0196      0.0919    0.6043    0.8180  -23.0574    4.5130       0      1.0206      1.0000
J.lowres                      9             1.2555      1.2481      0.1712    0.9228  -99.0000  -23.8194    4.5638       0      1.2514      1.0000
H.lowres                      10            1.6497      1.6352      0.2893    1.3701  -99.0000  -24.8565    4.7045       0      1.6409      1.0000
K.lowres                      11            2.1577      2.1435      0.2926    1.8335  -99.0000  -25.9057    5.1316       0      2.1502      1.0000
IB427.lowres                  12            0.4264      0.4256      0.0207   -0.1446   -0.4942  -20.4117    5.5152       0      0.4262      1.0000
IB464.lowres                  13            0.4636      0.4633      0.0218   -0.1520   -0.3463  -20.5860    5.0658       0      0.4634      1.0000
IB484.lowres                  14            0.4851      0.4846      0.0228   -0.0241   -0.1770  -20.8122    4.9880       0      0.4849      1.0000
IB505.lowres                  15            0.5064      0.5061      0.0231   -0.0656   -0.1366  -20.8639    4.9423       0      0.5061      1.0000
IB527.lowres                  16            0.5262      0.5259      0.0242   -0.0260   -0.0464  -20.9871    4.8937       0      0.5260      1.0000
IB574.lowres                  17            0.5766      0.5762      0.0272    0.0657    0.1377  -21.2773    4.7042       0      0.5763      1.0000
IB624.lowres                  18            0.6234      0.6230      0.0301    0.1527    0.2768  -21.5339    4.6386       0      0.6232      1.0000
IB679.lowres                  19            0.6783      0.6779      0.0336    0.2542    0.4288  -21.8183    4.5709       0      0.6779      1.0000
IB709.lowres                  20            0.7075      0.7071      0.0316    0.2982    0.4968  -21.9541    4.5558       0      0.7072      1.0000
IB738.lowres                  21            0.7363      0.7358      0.0323    0.3460    0.5577  -22.0886    4.5449       0      0.7360      1.0000
IB767.lowres                  22            0.7687      0.7681      0.0364    0.3992    0.6164  -22.2351    4.5243       0      0.7683      1.0000
IB827.lowres                  23            0.8246      0.8241      0.0344    0.4891    0.7300  -22.4777    4.5161       0      0.8243      1.0000
NB711.lowres                  24            0.7120      0.7119      0.0073    0.3072    0.5084  -21.9774    4.5542       0      0.7120      1.0000
NB816.lowres                  25            0.8150      0.8149      0.0120    0.4713    0.7098  -22.4349    4.5154       0      0.8149      1.0000
NB118.lowres                  26            1.1909      1.1909      0.0112    0.8376  -99.0000  -23.6250    4.5554       0      1.1909      1.0000
irac_ch1.lowres               27            3.5763      3.5264      0.7411    2.7951  -99.0000  -27.9585    6.0679       1      3.5634      1.0036
irac_ch2.lowres               28            4.5290      4.4609      1.0105    3.2634  -99.0000  -28.9384    6.5680       1      4.5111      1.0040
irac_ch3.lowres               29            5.7873      5.6765      1.3509    3.7537  -99.0000  -29.9581    7.0472       1      5.7592      1.0050
irac_ch4.lowres               30            8.0442      7.7033      2.8394    4.3959  -99.0000  -31.2962    7.6701       1      7.9590      1.0110
#######################################
# 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 SED in the list 254
#######################################
# 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 SED in the list 30
#######################################
# 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 SED in the list 31
WRONG NUMBER OF ARGUMENTS FOR OPTION MOD_EXTINC
We have 2 instead of 8
Use default value 0,0 for all filters
#######################################
# 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/ALLSTAR_COSMOS(.doc & .bin)
# LIB_ASCII   YES
# CREATION_DATE Wed Mar  4 11:31:29 2026
#############################################
#######################################
# 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.0100 0.0000 7.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 # LIB_ASCII   YES
# CREATION_DATE Wed Mar  4 11:31:29 2026
#############################################
#######################################
# 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/VISTA_COSMOS_FREE(.doc & .bin)
# Z_STEP   :0.0100 0.0000 7.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,
# LIB_ASCII   YES
# CREATION_DATE Wed Mar  4 11:32:10 2026
#############################################
[7]:
mag = lp.MagSvc.from_config("Star", config_file)
Number of keywords read in the config file: 86
WRONG NUMBER OF ARGUMENTS FOR OPTION MOD_EXTINC
We have 2 instead of 8
Use default value 0,0 for all filters
[8]:
newsed = mag.make_maglib(sed)
[9]:
newsed[0].mag
[9]:
[-17.832635547445825,
 -16.965434915160827,
 -21.74369850105703,
 -23.924441687077692,
 -27.27064606256254,
 -30.41100563847929,
 -31.391194440280003,
 -31.789356087837827,
 -32.60607648903679,
 -33.17999398114149,
 -33.11090548326123,
 -19.508519013723287,
 -22.731890656223662,
 -22.751761120054706,
 -20.034611030001372,
 -17.67834196521941,
 -13.657105603466924,
 -20.374734241068733,
 -25.480954814468745,
 -25.72124998601171,
 -25.229256732623675,
 -23.765485912116315,
 -28.554487232454346,
 -25.84162861778997,
 -27.939724821108424,
 -32.30750089217318,
 -33.35774425614392,
 -32.86914154249609,
 -32.769299032400184,
 -32.55862340088774]