lephare
Submodules
- lephare._flt
- lephare._pdf
- lephare._photoz
- lephare._plot_utils
- lephare._spec
- lephare._utils
- lephare.data_manager
- lephare.data_retrieval
- lephare.default_cosmos_config
- lephare.filter
- lephare.filterSvc
- lephare.filter_extinc
- lephare.magSvc
- lephare.mag_gal
- lephare.prepare
- lephare.process
- lephare.runner
- lephare.sedtolib
- lephare.zphota
Attributes
Classes
Utility class for generating diagnostic plots and statistical summaries |
|
The specific arguments to the Filter class are |
|
The specific arguments to the Filter class are |
|
Filter service for retrieving filters from various sources. |
|
The specific arguments to the MagGal class are |
|
Magnitude service to return magnitudes of a single SED. |
|
Runner is the base class of the classes Filter, Sedtolib, MagGal, and Zphota, |
|
The specific arguments to the Sedtolib class are |
|
The specific arguments to the Zphota class are |
Functions
|
|
|
Calculate the extinction values for a set of filters |
|
Run the prepare stages of LePHARE |
|
Check that two config can be safely broadcast for a joint run |
|
Open a standard yaml file and render it as a dictionary of keywords |
|
Write a dictionary of keywords to a yaml file |
|
Write a dictionary of keywords to a para file |
|
Convert a dictionary of keywords to a dictionary of strings |
|
Convert a dictionary of strings to a dictionary of keywords |
|
Convert all types of configs to keymap |
|
Run all required steps to produce photometric redshift estimates |
|
Take an astropy table and return the arrays required for a run. |
|
Calculate the zero point offsets for objects with spectroscopic redshifts |
|
Take a sed list and move it with the sed files to the work directory. |
Package Contents
- class DataManager[source]
- lephare_dir
- lephare_work_dir
- property LEPHAREDIR
- property LEPHAREWORK
- create_new_run(descriptive_directory_name=None)[source]
Create a timestamped directory to contain the output from the current run. The newly created timestamped directory is symlinked to the path defined by the LEPHAREWORK environment variable.
- Parameters:
descriptive_directory_name (str) – A descriptive name for the new run directory. If None, the directory will be named with the current timestamp.
- Returns:
run_directory – The path to the newly created run directory.
- Return type:
str
- class PlotUtils(t, sel_filt=0, pos_filt=None, range_z=None, range_mag=None, pdf_col=None)[source]
Utility class for generating diagnostic plots and statistical summaries from LePHARE output tables.
This class provides a suite of methods for analyzing photometric redshift and physical parameters catalogs generated by LePHARE, including comparisons between photometric and spectroscopic redshifts, redshift error distributions, chi-squared diagnostics, magnitude and color relations, and other common validation plots.
Examples
Typical usage example:
from astropy.table import Table import lp t = Table.read("outputphotoz.fits") utils = lp.PlotUtils( t, sel_filt=3, pos_filt=[0, 1, 2, 4, 5, 5], range_z=[0, 0.5, 1, 1.5, 3], range_mag=[19, 20.5, 21.5, 22.5, 25] ) utils.zml_zs() utils.zp_zs() utils.zml_zp() utils.dist_z() utils.dist_chi2() utils.dist_filt() utils.dist_model() utils.dist_ebv() utils.secondpeak() utils.bzk() utils.cumulative68() utils.check_error() utils.errormag() utils.errorz() utils.pit_qq() utils.absmag_z() utils.rf_color() utils.william() utils.dist_mass() utils.dist_sfr() utils.dist_ssfr() utils.mass_med_best() utils.sfr_med_best() utils.mass_sfr() utils.mass_z() utils.sfr_z() utils.lnuv_sfr() utils.absmagu_sfr() utils.absmagk_mass() utils.masstolight_z() utils.save_all_plots_pdf()
- Parameters:
t (astropy.table.Table) – Table containing the output from a LePHARE run. Must include columns such as
Z_BEST,Z_MED,MAG_OBS(),MAG_ABS(),CHI_BEST, etc.sel_filt (int, optional) – Index (starting at 0) of the filter used to select objects by observed magnitude. Default is 0.
pos_filt (list of int, optional) – Indices (starting at 0) of the filters corresponding to u, g, r, z, J, and Ks bands. Used to generate color-based plots. Default is
[0, 0, 0, 0, 0, 0].range_z (list of float, optional) – Redshift bin edges to use in diagnostics. If not provided, quartiles of the spectroscopic redshift distribution (0, 0.25, 0.5, 0.75, 1 quantiles) are used.
range_mag (list of float, optional) – Observed magnitude bin edges to use in diagnostics. If not provided, quartiles of the selected-band magnitude distribution (0, 0.25, 0.5, 0.75, 1 quantiles) are used.
- Id
Object identifiers.
- Type:
ndarray
- zp, zml, zs
Best-fit, median, and spectroscopic redshifts, respectively.
- Type:
ndarray
- chi, chi2
Chi-squared values for best-fit and secondary models.
- Type:
ndarray
- mag, magu, magb, magr, magz, magj, magk
Observed magnitudes in various filters.
- Type:
ndarray
- mabsu, mabsb, mabsr, mabsz, mabsj, mabsk
Absolute magnitudes in various filters.
- Type:
ndarray
- range_z, range_mag
Bin edges used for redshift and magnitude-based diagnostics.
- Type:
ndarray
- cond, condgal, condstar, condspec
Boolean selection masks for general, galaxy, star, and spectroscopic subsets.
- Type:
ndarray of bool
- z_min, z_max, mag_min, mag_max
Minimum and maximum values for redshift and magnitude selection.
- Type:
float
- nbRowM, nbColM, nbRowZ, nbColZ
Number of subplot rows and columns used in magnitude and redshift binnings.
- Type:
int
Notes
The filter numbering starts at 0.
The table must contain all expected columns from a LePHARE output table.
The class methods produce a variety of plots to assess photometric redshift performance and SED fitting reliability.
- sel_filt = 0
- uFilt
- bFilt
- rFilt
- zFilt
- jFilt
- kFilt
- Id
- zp
- zl68
- zu68
- zml
- zmll68
- zmlu68
- chi
- mod
- law
- ebv
- zp2
- chi2
- mod2
- ebv2
- zq
- chiq
- modq
- mods
- chis
- mag
- magu
- magb
- magr
- magz
- magj
- magk
- mabsu
- mabsb
- mabsr
- mabsz
- mabsj
- mabsk
- scale
- nbFilt
- context
- zs
- ageb
- agel
- agem
- ages
- ldustb
- ldustl
- ldustm
- ldusts
- ltirb
- ltirl
- ltirm
- ltirs
- massb
- massl
- massm
- masss
- sfrb
- sfrl
- sfrm
- sfrs
- ssfrb
- ssfrl
- ssfrm
- ssfrs
- lnuv
- lr
- lk
- pdfs
- cond
- condstar
- condgal
- condspec
- save_photoz_plots_pdf(filename='all_plots.pdf', **kwargs)[source]
Generate all photoz plotting methods in the class and save them in a single PDF.
- Parameters:
filename (str, optional) – The output PDF filename (default “all_photoz_plots.pdf”).
**kwargs (dict, optional) –
Keyword arguments to pass to the plotting methods. Common keys include: - bins : int
Number of bins for histograms.
- show_pitbool
Whether to include PIT histogram in applicable plots.
- show_qqbool
Whether to include QQ plots in applicable methods.
- savefigbool
Whether to save individual plots.
Any method that does not accept a particular key will ignore it.
- save_phys_plots_pdf(filename='all_phys_plots.pdf', **kwargs)[source]
Generate all physical parameter plots in the class and save them in a single PDF.
- Parameters:
filename (str, optional) – The output PDF filename (default “all_phys_plots.pdf”).
**kwargs (dict, optional) –
Keyword arguments to pass to the plotting methods. Common keys include: - bins : int
Number of bins for histograms.
- show_pitbool
Whether to include PIT histogram in applicable plots.
- show_qqbool
Whether to include QQ plots in applicable methods.
- savefigbool
Whether to save individual plots.
Any method that does not accept a particular key will ignore it.
- title_page()[source]
Create a title page for diagnostic plots.
This method generates a simple title page summarizing the LePHARE diagnostic plots. It includes the LePHARE version and the current date. The information is displayed centered on the page.
The axes are retained (not hidden) so that further annotations or plot elements can be added later if needed.
- zml_zs()[source]
Plot photometric redshifts (median of the PDF) versus spectroscopic redshifts.
This diagnostic compares the median of PDF(z) (Z_MED) derived by LePHARE with the spectroscopic redshifts (ZSPEC) for all objects meeting the selection criteria. It is commonly used to assess the accuracy, scatter, and presence of catastrophic outliers in photometric redshift estimates.
The plot is divided into subpanels based on magnitude bins defined in range_mag. Each panel displays Z_MED versus ZSPEC, with reference lines indicating the 1:1 relation and typical deviation thresholds.
Notes
Only objects with valid spectroscopic redshifts (0 < ZSPEC < 9) and within the defined redshift and magnitude ranges are included.
The number and layout of subpanels depend on the magnitude binning.
This plot is typically one of the first diagnostics used to check the performance of photometric redshift estimation.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.zml_zs() # Produces a Z_MED vs ZSPEC scatter plot by magnitude bin.
- zp_zs()[source]
Plot photometric redshifts (minimum chi-squared value) versus spectroscopic redshifts.
This diagnostic compares the best-fit photometric redshifts (Z_BEST) obtained from the minimum χ² solution in LePHARE with the spectroscopic redshifts (ZSPEC). It is useful for assessing the quality and bias of the primary redshift solution and identifying catastrophic outliers.
The figure is divided into subpanels according to the magnitude bins defined in range_mag. Each panel shows Z_BEST versus ZSPEC along with reference lines for the one-to-one relation and typical redshift deviation thresholds (e.g., Δz / (1 + z) = ±0.05).
Notes
Only sources with valid spectroscopic redshifts (0 < ZSPEC < 9) and within the defined redshift and magnitude ranges are included.
The panel layout is determined by the number of magnitude bins.
This plot complements
zml_zs()by using the minimum χ² redshift rather than the PDF median.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.zp_zs() # Produces a Z_BEST vs ZSPEC scatter plot by magnitude bin.
- zml_zp()[source]
Plot photometric redshifts (median of the PDF) versus photometric redshifts (minimum χ²).
This diagnostic compares the two photometric redshift estimates produced by LePHARE: the median of the posterior probability distribution (Z_MED) and the best-fit value from the minimum χ² solution (Z_BEST). The comparison helps identify systematic biases between the two estimators and assess the stability of redshift determinations.
The figure is divided into subpanels based on magnitude bins defined in range_mag. Each subpanel shows Z_MED versus Z_BEST with a 1:1 reference line and scatter indicating consistency between the two measures.
Notes
Only sources within the defined redshift and magnitude ranges are included.
The plot can reveal populations where the PDF and best-fit solutions diverge, such as multi-peaked PDFs or poor fits.
Strong deviations from the 1:1 line indicate inconsistency between the χ²-based and PDF-based estimates.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.zml_zp() # Produces a Z_MED vs Z_BEST comparison plot by magnitude bin.
- dist_z(nstep=20)[source]
Plot the redshift distribution of the spectroscopic and photometric samples.
This diagnostic shows histograms of the spectroscopic redshifts (ZSPEC), the photometric redshifts from the minimum χ² solution (Z_BEST), and the median of the PDF (Z_MED). It provides an overview of the redshift coverage and potential biases between the photometric and spectroscopic distributions.
- Parameters:
nstep (int, optional) – Number of bins to use in the redshift histograms. Default is 20.
Notes
Only objects satisfying the redshift and magnitude selection criteria are used.
Overlaid histograms allow direct comparison of the redshift distributions.
Discrepancies between spectroscopic and photometric distributions may indicate systematic shifts or incomplete coverage in certain redshift ranges.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_z(nstep=30) # Produces histograms of ZSPEC, Z_BEST, and Z_MED distributions.
- dist_chi2(nstep=20)[source]
Plot the reduced χ² distribution as a function of observed magnitude.
This diagnostic shows the distribution of the minimum χ² values (CHI_BEST) for different magnitude bins, helping to assess the quality of SED fits across brightness ranges. Poorer fits at faint magnitudes may indicate increased photometric noise or template limitations.
We estimate the reduced χ² by dividing the minimum χ² by the number of filters used minus 1
- Parameters:
nstep (int, optional) – Number of bins to use in the χ² histograms. Default is 20.
Notes
The figure is typically divided into subpanels according to range_mag.
Only objects meeting the redshift and magnitude selection criteria are included.
A broad or asymmetric χ² distribution at a given magnitude may suggest underestimated photometric errors or mismatched templates.
See also
dist_zShow redshift distributions.
dist_modelShow distribution of best-fit SED model identifiers.
dist_ebvShow distribution of dust extinction values.
check_errorVerify internal photometric error estimates.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_chi2(nstep=30) # Produces χ² histograms by magnitude bin.
- dist_filt(nstep=10)[source]
Plot the distribution of the number of filters used in each fit.
This diagnostic shows how many photometric bands were included by LePHARE when fitting each object. It helps assess data completeness and detect cases where limited filter coverage may affect the reliability of photometric redshifts or SED parameters.
- Parameters:
nstep (int, optional) – Number of bins to use in the histogram of NBAND_USED. Default is 10.
Notes
Uses the NBAND_USED column from the LePHARE output table.
Only sources satisfying the redshift and magnitude selection criteria are included.
A concentration of objects with a low number of filters may indicate missing photometry or incomplete coverage in certain bands.
See also
dist_chi2Show χ² distribution by magnitude bin.
dist_modelShow distribution of best-fit model identifiers.
dist_ebvShow distribution of dust extinction values.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_filt(nstep=15) # Produces a histogram of the NBAND_USED distribution.
- dist_model(nstep=20)[source]
Plot the distribution of best-fit SED model identifiers.
This diagnostic displays the frequency of SED templates (MOD_BEST) selected by LePHARE as the best-fitting models across the sample. It helps visualize which galaxy, AGN, or stellar templates dominate the fits and can reveal biases toward certain template types.
- Parameters:
nstep (int, optional) – Number of bins to use in the histogram of model identifiers. Default is 20.
Notes
Uses the MOD_BEST column from the LePHARE output table.
Only sources satisfying the redshift and magnitude selection criteria are included.
The model identifiers correspond to entries in the LePHARE template library.
A dominance of certain templates may indicate population trends or a lack of diversity in the input SED library.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_model(nstep=25) # Produces a histogram of MOD_BEST template identifiers.
- dist_ebv(nstep=10)[source]
Plot the distribution of best-fit dust extinction values (E(B-V)).
This diagnostic shows the range and frequency of dust extinction (EBV_BEST) values derived by LePHARE for the sample. It helps assess typical dust content and the effects of extinction on photometric redshift or SED fitting results.
- Parameters:
nstep (int, optional) – Number of bins to use in the histogram of E(B-V) values. Default is 10.
Notes
Uses the EBV_BEST column from the LePHARE output table.
Only sources meeting the redshift and magnitude selection criteria are included.
Peaks or concentrations in E(B-V) may indicate preferred extinction values in the template set or the typical dust content of the population.
See also
dist_modelShow distribution of best-fit SED model identifiers.
dist_chi2Show χ² distribution by magnitude bin.
dist_filtShow number of filters used in each fit.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_ebv(nstep=15) # Produces a histogram of EBV_BEST values.
- secondpeak(nstep=20)[source]
Plot the redshift distribution of the secondary photometric redshift peak.
This diagnostic examines objects where LePHARE identifies a secondary photometric redshift solution (Z_SEC) and compares it with the primary solutions (Z_BEST and Z_MED). It helps identify multi-modal PDFs and potential catastrophic redshift outliers.
- Parameters:
nstep (int, optional) – Number of bins to use in the histogram of secondary peak redshifts. Default is 20.
Notes
Only sources with a valid secondary peak (Z_SEC) are included.
The figure may be divided into subpanels based on magnitude bins.
Comparison of primary and secondary peaks can reveal degeneracies in SED fitting and ambiguous photometric redshift solutions.
Useful for assessing the reliability of photometric redshift catalogs and flagging objects with uncertain redshifts.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.secondpeak(nstep=25) # Produces a histogram of secondary peak redshifts compared with primary solutions.
- bzk()[source]
Plot BzK diagram for galaxy/star classification per redshift bin.
This diagnostic produces BzK color-color diagrams to separate star-forming galaxies, passive galaxies, and stars based on the observed B, z, and K magnitudes. The plots are generated for different redshift bins defined in range_z, allowing assessment of population segregation at different epochs.
Notes
Uses the observed magnitudes in B (magb), z (magz), and K (magk) filters.
Only sources meeting the redshift and magnitude selection criteria are included.
Overlaid regions indicate typical BzK selection areas for star-forming galaxies, passive galaxies, and stars.
Helps identify misclassified objects or potential contamination by stars in galaxy samples.
See also
dist_filtShow number of filters used in each fit.
dist_modelShow distribution of best-fit SED model identifiers.
secondpeakExamine secondary photometric redshift peaks.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.bzk() # Produces BzK color-color diagrams per redshift bin.
- absmag_z()[source]
Plot B-band absolute magnitude versus redshift for the sample.
This diagnostic shows the relation between absolute magnitudes and redshift, providing insight into luminosity evolution, selection effects, and completeness limits of the survey.
Notes
Uses the B-band absolute magnitudes
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Helps identify trends such as brightening or dimming with redshift and the distribution of galaxies in the luminosity-redshift plane.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.absmag_z() # Produces plots of absolute magnitude versus redshift.
- rf_color()[source]
Plot rest-frame colors U-R versus absolute magnitude R.
This diagnostic shows the relation between rest-frame colors and absolute magnitudes in different bands, allowing analysis of galaxy populations, color bimodality, and stellar population trends.
Notes
Uses absolute magnitudes (MAG_ABS()) and rest-frame colors derived from the best-fit templates.
Only objects within the redshift and magnitude selection ranges are included.
Can reveal red sequence and blue cloud populations in the color–magnitude diagram.
Subpanels can be used to separate objects by magnitude or redshift bins.
See also
absmag_zAbsolute magnitude versus redshift.
bzkBzK color-color diagram for star/galaxy classification.
dist_modelDistribution of best-fit SED models.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.rf_color() # Produces rest-frame color versus absolute magnitude plots.
- william()[source]
Create a rest-frame U-R, R-J color-color plot.
This diagnostic reproduces the rest-frame color-color diagrams of ‘’William’’, which are commonly used to separate galaxy populations (e.g., quiescent vs star-forming) and study stellar population properties.
Notes
Uses rest-frame magnitudes or colors derived from the best-fit templates.
Only objects within the redshift and magnitude selection ranges are included.
Subpanels can be applied based on redshift or magnitude bins to study evolution with cosmic time.
Helps visualize the bimodality of galaxy populations in rest-frame color space.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.william() # Produces a William style rest-frame color-color plot.
- cumulative68(nstep=20)[source]
Check that 68% of spectroscopic redshifts fall within the 68% photometric error interval.
This diagnostic evaluates the accuracy of photometric redshift uncertainties by computing the fraction of objects for which the spectroscopic redshift (ZSPEC) lies within the 68% confidence interval of the photometric redshift PDF (Z_MED68_LOW to Z_MED68_HIGH or Z_BEST68_LOW to Z_BEST68_HIGH). It helps validate the reliability of the estimated errors.
- Parameters:
nstep (int, optional) – Number of bins to use when plotting cumulative distributions. Default is 20.
Notes
Only objects with valid spectroscopic redshifts are considered.
A well-calibrated photometric redshift error distribution should contain ~68% of spectroscopic redshifts within the 68% interval.
Deviations from 68% indicate under- or overestimated photometric uncertainties.
See also
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.cumulative68(nstep=30) # Evaluates the fraction of spectroscopic redshifts within the 68% photometric error interval.
- check_error()[source]
Check photometric redshift errors as a function of magnitude.
This diagnostic evaluates how the estimated photometric redshift uncertainties change as a function of observed magnitude.
Notes
Uses the columns Z_BEST68_LOW, Z_BEST68_HIGH, Z_MED68_LOW, Z_MED68_HIGH, and ZSPEC.
The plot shows error distributions as a function of the selected magnitude band.
Can reveal trends where photometric errors are underestimated at faint magnitudes or overestimated at bright magnitudes.
See also
cumulative68Check fraction of spectroscopic redshifts within the 68% photometric error.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.check_error() # Produces a plot of photometric redshift errors versus observed magnitude.
- errormag()[source]
Plot photometric redshift errors as a function of observed magnitude.
This diagnostic shows how the estimated photometric redshift errors (e.g., derived from the PDF width or χ² fitting) vary with object brightness. It is useful for assessing the reliability of redshift estimates across the magnitude range.
Notes
Uses the selected magnitude (mag) and corresponding photometric redshift errors from the LePHARE output.
Only objects within the redshift and magnitude selection criteria are included.
Typically, errors increase for fainter objects due to lower signal-to-noise.
See also
check_errorEvaluate 68% error coverage as a function of magnitude.
errorzCompare photometric redshift errors as a function of redshift.
cumulative68Check fraction of spectroscopic redshifts within the 68% photometric error.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.errormag() # Produces a plot of photometric redshift errors versus magnitude.
- errorz()[source]
Plot photometric redshift errors as a function of redshift.
This diagnostic shows how the estimated photometric redshift uncertainties (e.g., derived from the PDF width or χ² fitting) vary with redshift. It is useful for identifying redshift ranges where photometric redshifts may be less reliable or exhibit larger scatter.
Notes
Uses the photometric redshifts (Z_BEST or Z_MED) and their associated uncertainties from the LePHARE output.
Only objects within the redshift and magnitude selection criteria are included.
Errors often increase at high redshift due to fainter magnitudes and fewer spectral features in the observed bands.
See also
errormagPhotometric redshift errors versus observed magnitude.
check_errorEvaluate 68% error coverage as a function of magnitude.
cumulative68Check fraction of spectroscopic redshifts within the 68% photometric error.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.errorz() # Produces a plot of photometric redshift errors versus redshift.
- pit_qq(pdfs=None, zgrid=None, ztrue=None, bins=None, title=None, show_pit=True, show_qq=True, savefig=False) str[source]
Generate a PIT and QQ quantile-quantile plot for photometric redshift PDFs.
This function creates a visualization to assess the calibration of predicted PDFs against true redshifts. It can display a Probability Integral Transform (PIT) histogram and/or a QQ plot, optionally saving the figure.
- Parameters:
pdfs (np.ndarray, shape (m, n), optional) – Array of PDFs for m objects over n z-grid points. If None, use the PDFs from the class Metrics object.
zgrid (np.ndarray, shape (n,), optional) – The z-axis corresponding to the PDF bins. Required if pdfs is provided.
ztrue (np.ndarray, shape (m,), optional) – True redshift values for the m objects. Required if pdfs is provided.
bins (int, optional) – Number of bins for the PIT histogram. If None, use the default number of quantiles defined in the sample (sample.n_quant).
title (str, optional) – Title for the plot. If None, a formatted sample name will be used.
show_pit (bool, default=True) – Whether to include the PIT histogram in the figure.
show_qq (bool, default=True) – Whether to include the QQ plot in the figure.
savefig (bool, default=False) – Whether to save the plot to a PNG file. If True, the filename will be automatically generated.
- Returns:
Path to the saved figure if savefig=True; otherwise an empty string.
- Return type:
str
Notes
PIT (Probability Integral Transform) values should be uniformly
distributed if the PDFs are well-calibrated. - QQ plot compares the quantiles of the PIT distribution against a uniform distribution to visually assess calibration.
- dist_mass(nstep=10)[source]
Plot the distribution of stellar mass
This diagnostic shows the range and frequency of stellar mass values derived by LePHARE for the sample.
- Parameters:
nstep (int, optional) – Number of bins to use in the histogram of mass values. Default is 10.
Notes
Uses the MASS_BEST and ‘MASS_MED’ column from the LePHARE output table.
Only sources meeting the redshift and magnitude selection criteria are included.
See also
dist_modelShow distribution of best-fit SED model identifiers.
dist_filtShow number of filters used in each fit.
dist_SFRSFR distribution
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_mass(nstep=15) # Produces a histogram of MASS_BEST and MASS_MED values.
- dist_sfr(nstep=10)[source]
Plot the distribution of SFR
This diagnostic shows the range and frequency of SFR values derived by LePHARE for the sample.
- Parameters:
nstep (int, optional) – Number of bins to use in the histogram of mass values. Default is 10.
Notes
Uses the SFR_BEST and ‘SFR_MED’ column from the LePHARE output table.
Only sources meeting the redshift and magnitude selection criteria are included.
See also
dist_modelShow distribution of best-fit SED model identifiers.
dist_filtShow number of filters used in each fit.
dist_massMass distribution
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_sfr(nstep=15) # Produces a histogram of SFR_BEST and SFR_MED values.
- dist_ssfr(nstep=10)[source]
Plot the distribution of specific SFR
This diagnostic shows the range and frequency of sSFR values derived by LePHARE for the sample.
- Parameters:
nstep (int, optional) – Number of bins to use in the histogram of mass values. Default is 10.
Notes
Uses the SSFR_BEST and ‘SSFR_MED’ column from the LePHARE output table.
Only sources meeting the redshift and magnitude selection criteria are included.
See also
dist_modelShow distribution of best-fit SED model identifiers.
dist_filtShow number of filters used in each fit.
dist_massMass distribution
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.dist_ssfr(nstep=15) # Produces a histogram of SSFR_BEST and SSFR_MED values.
- mass_med_best()[source]
Plot stellar mass median of the PDF versus minimum χ²
This diagnostic compares the two mass estimates produced by LePHARE: the median of the posterior probability distribution (MASS_MED) and the best-fit value from the minimum χ² solution (MASS_BEST). The comparison helps identify systematic biases between the two estimators and assess the stability of mass determinations.
The figure is divided into subpanels based on magnitude bins defined in range_mag. Each subpanel shows MASS_MED versus MASS_BEST with a 1:1 reference line and scatter indicating consistency between the two measures.
Notes
Only sources within the defined redshift and magnitude ranges are included.
The plot can reveal populations where the PDF and best-fit solutions diverge, such as multi-peaked PDFs or poor fits.
Strong deviations from the 1:1 line indicate inconsistency between the χ²-based and PDF-based estimates.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.mass_med_best() # Produces a MASS_MED vs MASS_BEST comparison plot by magnitude bin.
- sfr_med_best()[source]
Plot SFR median of the PDF versus minimum χ²
This diagnostic compares the two mass estimates produced by LePHARE: the median of the posterior probability distribution (SFR_MED) and the best-fit value from the minimum χ² solution (SFR_BEST). The comparison helps identify systematic biases between the two estimators and assess the stability of mass determinations.
The figure is divided into subpanels based on magnitude bins defined in range_mag. Each subpanel shows SFR_MED versus SFR_BEST with a 1:1 reference line and scatter indicating consistency between the two measures.
Notes
Only sources within the defined redshift and magnitude ranges are included.
The plot can reveal populations where the PDF and best-fit solutions diverge, such as multi-peaked PDFs or poor fits.
Strong deviations from the 1:1 line indicate inconsistency between the χ²-based and PDF-based estimates.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.sfr_med_best() # Produces a SFR_MED vs SFR_BEST comparison plot by magnitude bin.
- mass_z()[source]
Plot stellar mass versus redshift for the sample.
This diagnostic shows the relation between stellar masses and redshift, providing insight into mass evolution, selection effects, and completeness limits of the survey.
Notes
Uses the stellar mass
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Helps identify trends such as brightening or dimming with redshift and the distribution of galaxies in the mass-redshift plane.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.mass_z() # Produces plots of mass versus redshift
- sfr_z()[source]
Plot SFR versus redshift for the sample.
This diagnostic shows the relation between SFR and redshift, providing insight into mass evolution, selection effects, and completeness limits of the survey.
Notes
Uses the SFR
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Helps identify trends such as brightening or dimming with redshift and the distribution of galaxies in the mass-redshift plane.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.sfr_z() # Produces plots of mass versus redshift
- mass_sfr()[source]
Plot stellar mass versus SFR for the sample.
This diagnostic shows the main sequence
Notes
Uses the stellar mass and SFR
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.mass_sfr() # Produces plots of mass versus SFR
- lnuv_sfr()[source]
Plot dust-corrected L(NUV) versus SFR for the sample.
Notes
Uses the Lnuv and SFR
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.lnuv_sfr() # Produces plots of L(NUV) versus SFR
- masstolight_z()[source]
Plot mass-to-light ratio versus redshift for the sample.
This diagnostic shows the relation between mass-to-light ratio and redshift, providing insight into SED fitting
Notes
Uses the L(K) and massb
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.masstolight_z() # Produces plots of mass-to-light versus redshift
- absmagk_mass()[source]
Plot M(Ks) versus mass for the sample.
Notes
Uses the M(Ks) and mass
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.absmagk_mass() # Produces plots of M(K) versus mass
- absmagu_sfr()[source]
Plot M(U) versus SFR for the sample.
Notes
Uses the M(U) and SFR
Only objects within the redshift and magnitude selection ranges are included.
The figure can be divided into subpanels based on magnitude or redshift bins.
Examples
>>> utils = lp.PlotUtils(t, sel_filt=3) >>> utils.absmagu_sfr() # Produces plots of M(U) versus SFR
- class Filter(config_file=None, config_keymap=None, **kwargs)[source]
Bases:
lephare.runner.RunnerThe specific arguments to the Filter class are
- verbose
increase onscreen verbosity
- FILTER_REP
path to repository where filter files are searched
- FILTER_LIST
list of filter files, to be searched in FILTER_REP if relative
- TRANS_TYPE
Transmission curve type: 0[def] for energy, 1 for photon nb
- FILTER_CALIB
- calibration system for the filter:
0[def]: fnu=cst 1: nu.fnu=cst 2: fnu=nu 3: fnu=Black Body @ T=10000K 4: for MIPS (leff with nu fnu=ctt and flux with BB @ 10000K
- FILTER_FILE
output filter filename, will be saved in $LEPHAREWORK/filt/
- class FiltExt(config_file=None, config_keymap=None, **kwargs)[source]
Bases:
lephare.runner.RunnerThe specific arguments to the Filter class are
- verbose
increase onscreen verbosity
- FILTER_FILE
Path to filter file on which to compute extinction, output of the filter execution, to be found in $LEPHAREWORK/filt
- EXT_CURVE
Extinction law to use, to be searched in $LEPHAREDIR/ext if relative
- GAL_CURVE
Extinction curve in the galaxy, to be searched in $LEPHAREDIR/ext if relative
- OUTPUT
Output file name
- calculate_extinction_values(filters, atmec, galec, verbose=False)[source]
Calculate the extinction values for a set of filters
- Parameters:
filters (str) – The file containing the lephare compiled filter list
atmec (str) – Extinction law to use, to be searched in $LEPHAREDIR/ext if relative
galec (str) – Extinction curve in the galaxy, to be searched in $LEPHAREDIR/ext if relative
verbose (bool) – Increase onscreen verbosity
- Returns:
all_filters (list of lephare.GalMag) – The list of filter objects
aint (np.array) – Atmospheric extinction in each filter (mag/airmass)
albdav (np.array) – Galactic extinction in each filter A(lbd)/Av
albd (np.array) – Galactic extinction in each filter A(lbd)/E(B-V)
- class FilterSvc[source]
Filter service for retrieving filters from various sources.
This class defines a number of methods for loading and manipulating filters.
- classmethod from_yaml(yaml_file)[source]
Load filter from a yaml file
- Parameters:
yaml_file (str) – Path to yaml file
- Returns:
flt_array – Array of wavelengths in Angstrom and filter transmissivity.
- Return type:
list of lephare.flt
- classmethod from_config(config_file)[source]
Load filter from a .para config file
- Parameters:
config_file (str) – Path to config file
- Returns:
flt_array – List of filters.
- Return type:
list of lephare.flt
- classmethod from_svo(counter, filter_id, system='AB', calib=0)[source]
Return filter from SVO
- Parameters:
counter (int) – Filter number
filter_id (str) – Id of filter in SVO format.
system (str, optional) – Photometric system
calib (float, optional) – Calibration value. Not currently used.
- Returns:
res – Filter in native lephare format.
- Return type:
lephare.flt
- classmethod from_file(filename, counter=-1, trans=0, calib=0)[source]
Return filter from SVO
- Parameters:
filename (str) – Path to filter file.
counter (int) – Filter number
trans (int, optional) – Photometric system.
calib (int, optional) – Calibration value.
- Returns:
f – Filter in native lephare format.
- Return type:
lephare.flt
- class MagGal(config_file=None, config_keymap=None, **kwargs)[source]
Bases:
lephare.runner.RunnerThe specific arguments to the MagGal class are
- typ:
define what kind of objects these SED belong to : GAL, QSO, or STAR
- verbose:
increase onscreen verbosity
- COSMOLOGY:
fiducial h0, Omega_m0, and LambdaO used to define a flat LCDM cosmology used for absolute magnitudes evaluations
- FILTER_FILE:
filter file provided by filter script or the Filter class
- MAGTYPE:
AB or VEGA system
- EXTINC_LAW:
list of extinction files used for extinction correction (if relative, in $LEPHAREDIR/ext/)
- MOD_EXTINC:
list of SED template ranges for which each extinction law is going to be applied
- EB_V:
E(B-V) grid of values to be applied to the SEDs (comma separated)
- Z_STEP:
dz, zmin, zmax defining the redshift grid
- GAL_LIB_IN:
input SED library file, as output by sedtolib script or SEDtolib class (in $LEPHAREWORK/lib_bin/)
- GAL_LIB_OUT:
output file of the synthetic magnitudes (in $LEPHAREWORK/lib_mag/)
- QSO_LIB_IN, QSO_LIB_OUT, STAR_LIB_IN, STAR_LIB_OUT
same for STAR templates
- LIB_ASCII:
if set to YES, also provide the output in ascii
- EM_LINES:
[NO/EMP_UV/EMP_SFR/PHYS] choice of prescription for emission line computation
- EM_DISPERSION:
possible rescaling values for the emission lines
- ADD_DUSTEM:
add the dust emission in templates when missing
- VERBOSE:
add verbosity
- prepare(config, star_config=_DEFAULT, gal_config=_DEFAULT, qso_config=_DEFAULT)[source]
Run the prepare stages of LePHARE
In order to run “zphota” we must create the filter files, run sedtolib to create the SED libraries, and finally run mag_gal, to create the magnitude libararies. We abstract these tasks into a single prepare stage.
We overide the config for each type if distinct config set. If no overide configs are set we use the same for each type.
- Parameters:
config (dict of lephare.keyword) – The config base to run all tasks
star_config (dict of lephare.keyword or None) – Config values to override for stars. If None do not run.
gal_config (dict of lephare.keyword or None) – Config values to override for galaxies. If None do not run.
qso_config (dict of lephare.keyword or None) – Config values to override for QSO. If None do not run.
- overwrite_config(config1, config2)[source]
Check that two config can be safely broadcast for a joint run
- read_yaml_config(yaml_file_path)[source]
Open a standard yaml file and render it as a dictionary of keywords
- Parameters:
yaml_file_path (str) – Path to input yaml file.
- write_yaml_config(keymap, yaml_file_path)[source]
Write a dictionary of keywords to a yaml file
- Parameters:
keymap (dict of lephare.keyword) – The dictionary of keywords to be written to yaml.
yaml_file_path (str) – Path to output yaml file.
- write_para_config(keymap, para_file_path)[source]
Write a dictionary of keywords to a para file
- Parameters:
keymap (dict of lephare.keyword) – The dictionary of keywords to be written to yaml.
para_file_path (str) – Path to output para file.
- string_dict_to_keymap(string_dict)[source]
Convert a dictionary of strings to a dictionary of keywords
- process(config, input, col_names=None, standard_names=False, filename=None, write_outputs=False)[source]
Run all required steps to produce photometric redshift estimates
- Parameters:
config (dict of lephare.keyword) – The configuration for the run
input (astropy.table.Table) – The input table which must satisfy column name requirements depending on other optional inputs.
col_names (list) – Input catalogue column names. We will use ordering to determine meaning
standard_names (bool) – If true we assume standard names.
filename (str) – Output file name for the output catalogue.
write_outputs (bool) – Whether to write the output spectra, PDF, and ascii file if specified in the config. By default these are not written to save space.
- Returns:
output (astropy.table.Table) – The output table.
photozlist (list of lephare.onesource) – List of lephare onesource objects.
- table_to_data(config, input, col_names=None, standard_names=False)[source]
Take an astropy table and return the arrays required for a run.
We assume that either the columns are in the standard LePHARE order or that the user provides the colnames in the standard order or they use a standard naming convention and set the standard_names=True
The column names are id, f_filtername, ferr_filtername (for all filters) and context, zspec, string_input.
- Parameters:
config (dict of lephare.keyword) – The config keymap. We need this to know if we have magnitudes or fluxes and to get the filter names.
input (astropy.table.Table) – The input catalogue.
col_names (list of str) – The column names in the default order.
standard_names (bool) – If this is set we assume a standard column naming convention.
- Returns:
id (np.array) – The object ids
flux (np.array) – The object fluxes or magnitudes
flux_err (np.array) – The flux or magnitude errors
context (np.array) – The context determining flux usage
zspec (np.array) – The spectroscopic redshifts.
string_input (np.array) – Additional notes as a string.
- calculate_offsets_from_input(config, input, col_names=None, standard_names=False)[source]
Calculate the zero point offsets for objects with spectroscopic redshifts
We want to have this available as an independent method so that it can be called as a training stage prior to running at scale.
- Parameters:
config (dict of lephare.keyword) – The configuration for the run
input (astropy.table.Table) – The input table which must satisfy column name requirements depending on other optional inputs.
col_names (list) – Input catalogue column names. We will use ordering to determine meaning
standard_names (bool) – If true we assume standard names.
- Returns:
a0 – Offsets a0
- Return type:
np.array
- load_sed_list(path_to_list, object_type, absolute_paths=False)[source]
Take a sed list and move it with the sed files to the work directory.
We want to be able to load SED lists from other sources. These may use absolute paths or relative to the list file. They must adopt the lepahre standard which is relative to the sed/$TYPE/ directory
- Parameters:
path_to_list (str) – The path to the SED list file. This can be absolute or relative.
object_type ({'STAR', 'GAL', 'QSO'}) – The type of object. Must be one of “STAR”, “GAL”, or “QSO”.
absolute_paths (bool) – Set to True if list of absolute paths and not relative to list file
- Returns:
new_config_val – The location of the new list file with respect to current LEPHAREWORK directory. This is the value to set in the config.
- Return type:
str
- class Runner(config_keys=None, config_file=None, config_keymap=None, **kwargs)[source]
Runner is the base class of the classes Filter, Sedtolib, MagGal, and Zphota, responsible to drive the execution of the filter, sedtolib, mag_gal, and zphota scripts, respectively.
Configuration of the classes uses either a configuration file, a dictionary of key names and corresponding keyword objects, or set of key/values passed as arguments to the constructor
The order of precedence is : key/values pairs overwrite config_keymap entries, which themselves overwrite config_file entries.
- Parameters:
config_keys (list or None, optional) – List of all admissible configuration keys, provided by the inheriting classes
config_file (string or None, optional) – Path to a configuration file in LePHARE .para format
config_keymap (dict or None, optional) – Dictionary of configuration values provided as ‘key/keyword object’ pairs.
- keymap
- config = ''
- verbose = False
- typ = None
- timer = False
- config_keys = None
- parse_config_file(filename)[source]
Load config file and set config values.
- Parameters:
filename (string) – Path to config file
- class Sedtolib(config_file=None, config_keymap=None, **kwargs)[source]
Bases:
lephare.runner.RunnerThe specific arguments to the Sedtolib class are
- typ:
define what kind of objects these SED belong to : GAL, QSO, or STAR
- verbose:
increase onscreen verbosity
- GAL_SED:
file listing the galaxy SEDs to be used
- GAL_FSCALE”:
arbitrary Flux scale for galaxy templates
- GAL_LIB:
name of the output binary SED file for the galaxies (relative to $ZPHOTWORK/lib_bin/)
- SEL_AGE:
file listing the different galaxy ages to consider
- AGE_RANGE:
minimal and maximal age in year to consider
- QSO_SED, QSO_FSCALE, QSO_LIB, STAR_SED, STAR_LIB, STAR_FSCALE :
same for QSO/AGN and STAR SED types
- class Zphota(config_file=None, config_keymap=None, **kwargs)[source]
Bases:
lephare.runner.RunnerThe specific arguments to the Zphota class are verbose:
add verbosity
- CAT_IN:
input catalog
- INP_TYPE:
F if Fluxes, M if magnitudes
- CAT_MAG:
AB or VEGA magnitude system of the input catalog (default AB)
- CAT_FMT:
MEME or MMEE, to precise the order of value and error columns
- CAT_LINES:
min,max range to subselect entries in the input catalog
- ZPHOTLIB:
comma-separated list of template magnitude libraries without the suffix (to be found in $LEPHAREWORK/lib_mag)
- ADD_EMLINES:
range of galaxy models for which considering emission lines contribution
- EBV_RANGE:
E(B-V) min and max allowed in the library. Applied to all attenuation laws
- Z_RANGE:
Z min and max allowed in the GALAXY library
- PARA_OUT:
file listing the output keywords to be written on file (one keyword per line)
- CAT_OUT:
output file name
- CAT_TYPE:
LONG or SHORT, depending on whether zspec, context, and other columns are present after the magnitudes/fluxes and error columns
- ERR_SCALE:
values to be added in quadrature to the errors in magnitude in each band, values separated by a comma
- ERR_FACTOR:
values to scale the errors in flux (a single value for all bands)
- GLB_CONTEXT:
global context to define the bands to be used in the fit
- FORB_CONTEXT:
forbidden context to define the bands to be discarded from the fit
- MAG_ABS:
min,max absolute magnitudes allowed for GAL type
- MAG_ABS_QSO:
min,max absolute magnitudes allowed for QSO/AGN type
- MAG_REF:
reference band to compute absolute magnitudes
- NZ_PRIOR:
band to be used in the n(z) prior; a second band can be given in case the first one is absent in some objects
- ZFIX:
fix z to a known redshift, in case one is interested in inferring the best template
- Z_INTERP:
perform quadratic interpolation to refine best redshift solution
- Z_METHOD:
which redshift solution, between best and pdf median, to use for physical parameter computation
- DZ_WIN:
Window search for second peak
- MIN_THRES:
lower threshold for second peak
- SPEC_OUT:
output the best spectrum of each object
- FIR_LIB:
dedicated far infrared synthetic magnitudes files
- FIR_LMIN:
minimum value for lambda_mean/(1+z) (in microns) in FIR analysis
- FIR_CONT:
context for the FIR bands to be used in the FIR fit
- FIR_SCALE:
context for the FIR scale determination in the FIR fit
- FIR_FREESCALE:
consider FIR scaling free
- FIR_SUBSTELLAR:
substract the stellar component to the observed IR fluxes
- MABS_METHOD:
method to compute absolute magnitudes (e.g. 1 use the most appropriated filter for observed flux, 3 the model)
- MABS_CONTEXT:
context to decide which band can be used to derive the absolute magnitude in method 1
- MABS_REF:
fixed filter used to derived all abs mag (if MABS_METHOD=2)
- MABS_FILT:
list of fixed filters chosen to derive abs mag in all bands depending on the redshift bins defined in MABS_ZBIN (if MABS_METHOD=4)
- MABS_ZBIN:
list of Redshift bins associated with MABS_FILT
- RF_COLORS:
list of 4 band indexes out of which to compute the probability distribution of the 2 corresponding rest frame colors (default=-1 which means to not compute these color distributions)
- M_REF:
band index for which to compute the rest frame absolute magnitude probability distribution
- APPLY_SYSSHIFT:
list of values (equal to the number of bands) to add to the predicted magnitudes as zero-points (substracted to the observed magnitudes)
- AUTO_ADAPT:
perform zero point auto adaptation based on the provided true redshifts
- ADAPT_BAND:
band number for which to check magnitude range for auto adaptation
- ADAPT_LIM:
min,max magnitude range for auto adaptation
- ADAPT_ZBIN:
min,max value of the true redshifts used for auto adaptation of the zero points
- PDZ_OUT:
output the PDF of each object
- PDZ_TYPE:
list of the PDFs to output if PDZ_OUT is set
- ADDITIONAL_MAG:
file basename (in $LEPHAREWORK/filt/) for the set of additional filters for which to compute magnitudes. Thus a pass to the LePHARE filter stage needs to have occurred on these filters.
- LIMITS_ZBIN:
used to compute z_max. Redshifts used to split in N bins, separated by a coma. Need N+1 values (start with the minimum redshift).
- LIMITS_MAPP_REF:
used to compute z_max. Band in which the absolute magnitude is computed
- LIMITS_MAPP_SEL:
used to compute z_max. Give the selection band in each redshift bin. Need 1 or N values.
- LIMITS_MAPP_CUT:
used to compute z_max. Apparent mag selection used in each redshift bin. Need 1 or N values
- CHI2_OUT
Flag to output the chi2 value of each template (one file per source)