Class PhotoZ

Class Documentation

class PhotoZ

Class managing photo-z computation.

The PhotoZ class is the central executor of photo-z estimation : it manages most configuration parameters, reads synthetic magnitudes inputs and object catalogs, performs the fit, and is in charge of producing results and saving them to files.

Public Functions

PhotoZ(keymap &key_analysed)

Build a PhotoZ instance: parse every keyword needed to run the fit (input catalogue format, priors, Milky Way extinction options, output format…), then read and merge the GAL/QSO/STAR (and, if configured, FIR) binary magnitude libraries built beforehand by mag_gal, checking their cosmology/redshift-grid consistency

Parameters:

key_analysed – map of keyword/value pairs

inline virtual ~PhotoZ()
vector<double> compute_offsets(vector<onesource*> adaptSources)

Determine the per-band magnitude zero-point offsets (a0) to apply before fitting, either from the APPLY_SYSSHIFT keyword if it matches the number of filters, or by running the auto-adaptation procedure (AUTO_ADAPT=YES) on adaptSources, or 0 for every band otherwise

Parameters:

adaptSources – sources (typically with a reliable spec-z) used for the auto-adaptation procedure

Returns:

the per-band offset, one value per filter

vector<double> run_autoadapt(vector<onesource*> adaptSources)

Iteratively fit adaptSources at their spec-z and derive, for each band, the median magnitude offset between the observed and predicted magnitudes, until convergence or 10 iterations

Parameters:

adaptSources – sources (typically with a reliable spec-z) used for the auto-adaptation procedure

Returns:

the per-band offset, one value per filter

void run_photoz(vector<onesource*> sources, const vector<double> &a0)

Fit every source in the given list against the GAL/QSO/STAR (and, if configured, FIR) libraries, compute their uncertainties and physical parameters, and write the per-source outputs (ascii catalogue, spectra, PDFs) as configured

Parameters:
  • sources – sources to fit

  • a0 – per-band magnitude zero-point offset to apply before fitting

void fit(onesource &source, const vector<double> &mag_shifts)

Fit a source based on the PhotoZ configuration

Parameters:
  • source – the onesource object under consideration

  • mag_shifts – magnitude shifts to apply prior to fit (zero points)

void fit_uncertainties(onesource &source)

Compute the fit uncertainties of a source

Parameters:

source – the onesource object under consideration

void physical_parameters(onesource &src)

Compute the physical parameters derived from the fit to a source

Parameters:

src – the onesource object under consideration

pair<vector<double>, vector<double>> best_template(onesource &source, int const templateType, double const minl, double const maxl)

Get the spectrum of one of the template of one solution to the fit of a source

Parameters:
  • source – the onesource object under consideration

  • templateType – which object type (GAL:0, GAL 2nd solution:1, GAL FIR:2, QSO:3, STAR:4)

  • minl – lower bound in wavelength for the returned spectrum

  • maxl – upper bound in wavelength for the returned spectrum

Returns:

a pair of vectors for the wavelengths and spectral energy density.

inline void write_spectrum(const onesource &src, const string outputDir = ".")

Write out the spectrum solutions to ascii

Parameters:
  • src – the onesource object under consideration

  • outputDir – output directory The ascii file will be outputDir/Id<source.spec>.spec

string prep_header(vector<string> outkeywords)

Build the header line(s) of the output ascii catalogue from the list of requested output keywords

Parameters:

outkeywords – output column keywords (OUTPUT_PARA / CAT_OUT_PARA)

Returns:

the formatted header, ready to be written to the output file

void write_outputs(vector<onesource*> sources)

Write the per-source outputs (ascii catalogue line, spectra, PDFs, .chi files) for every source in the list, as configured by the relevant keywords (CAT_OUT, SPEC_OUT, PDZ_OUT, FULL_CHI_OUT…)

Parameters:

sources – sources to write out

void read_lib(vector<SED*> &libFull, int &ind, int nummodpre[3], const string libName, string &filtname, vector<int> emMod, int &babs)

Read a binary SED/magnitude library (and its .doc file) into memory, checking cosmology/redshift-grid consistency with any library already read via check_consistency()

Parameters:
  • libFull – SED library to append the read templates to

  • ind – running count of templates read so far, updated in place

  • nummodpre – per-type (GAL/QSO/STAR) running count of models read so far, used to renumber templates across successive libraries

  • libName – base name of the library to read (in $LEPHAREWORK/lib_mag/)

  • filtname – filled with the FILTER_FILE used to build this library

  • emMod – [min,max] model index range with emission lines, filled from the library’s EM_LINES keyword

  • babs – filled with the reference-band index for absolute magnitudes (MAG_REF keyword)

void check_consistency(keymap &keys)

Verify that the cosmology and redshift grid of the library being read are consistent with any library already read (all GAL/QSO libraries used together must share the same cosmology and redshift grid), and that the Milky Way Galametz option matches between the library and the current run

Parameters:

keys – keywords read from the library’s .doc file

void readsource(onesource *oneObj, const string line)

Parse one catalogue line into a source’s identifier, fluxes/magnitudes and errors, and (for the LONG format) its context and spectroscopic redshift

Parameters:
  • oneObj – the source to fill in place

  • line – one line of the input catalogue (CAT_IN)

inline onesource *yield(const int nobj, const string line)

Build, read and prepare a single source from one catalogue line

Parameters:
  • nobj – position (row index) to give the new source

  • line – one line of the input catalogue (CAT_IN)

Returns:

the newly allocated, ready-to-fit source (ownership passed to the caller)

vector<onesource*> read_autoadapt_sources()

Read the input catalogue (CAT_IN) and keep only the sources eligible for the auto-adaptation of zero-points: those with a spec-z within [adzmin, adzmax] and a magnitude in the #fl_auto band within [auto_thresmin, auto_thresmax]. Also applies read_mw_ebv() and read_externalz() to the selected sources.

Returns:

the selected sources (heap-allocated; ownership passed to the caller)

vector<onesource*> read_photoz_sources()

Read every source of the input catalogue (CAT_IN), regardless of spec-z or magnitude, applying read_mw_ebv() and read_externalz()

Returns:

all sources (heap-allocated; ownership passed to the caller)

void read_mw_ebv(vector<onesource*> sources)

Set each source’s Milky Way E(B-V) (onesource::mw_ebv), either from a single global value (MW_GLOBAL_EBV, one_mw_ebv true) or by matching each source’s Id against a per-source file (MW_EBV_FILE)

Parameters:

sources – sources to set the E(B-V) of, in place

void read_externalz(vector<onesource*> sources)

Override each source’s spectroscopic redshift (onesource::zs) by matching its Id against an external file (EXTERNALZ_FILE); sources not found in the file keep their catalogue redshift. No-op if EXTERNALZ_FILE is “NONE”.

Parameters:

sources – sources to override the redshift of, in place

void prep_data(vector<onesource*> sources)

Prepare every source in the list for fitting (see the single-source overload)

Parameters:

sources – sources to prepare, in place

void prep_data(onesource *oneObj)

Prepare a source for fitting: convert magnitudes to fluxes if needed, rescale the flux errors, derive magnitudes, keep a copy of the original values, and flag which bands are used based on the context

Parameters:

oneObj – the source to prepare, in place

vector<size_t> validLib(const double &redshift, const bool &ir = false)

Return the indexes over zlib vector on which to run the fit.

Parameters:
  • redshift – the selected redshift

  • ir – whether the selection is done on the main template library or on the IR one.

Returns:

Vector of indexes for templates set with redshift as redshift.

bool belong_autoadapt(onesource *src)

Check that the source belon to the auto-adapt sample i.e. selected magnitude and redshift range

Returns:

a boolean

Public Members

vector<vector<double>> flux

predicted flux of each GAL/QSO library template, in each band, after any MW dust correction

vector<vector<double>> flux_no_mw

same as flux, before MW dust correction

vector<vector<double>> fluxIR

predicted flux of each FIR library template, in each band

vector<vector<double>> reddening

per-template, per-band Galametz MW reddening correction (see onesource::redden_flux)

string mw_ref_mod

path (relative to $LEPHAREDIR) of the reference stellar SED used to normalise the Milky Way extinction correction (MW_REFERENCE_MODEL keyword)

vector<double> zLib

redshift of each GAL/QSO library template

vector<double> zLibIR

redshift of each FIR library template

vector<SED*> fullLib

GAL/QSO/STAR library templates (owned)

vector<SED*> fullLibIR

FIR library templates (owned)

SEDlight lightLib

lightweight (memory-reduced) copy of fullLib used during the fit

vector<flt> allFilters

filter set the libraries were built with

vector<double> gridz

redshift grid of the GAL/QSO libraries

vector<string> outkeywords

requested output column keywords (OUTPUT_PARA / CAT_OUT_PARA)

vector<string> pdftype

requested output PDF types (PDZ_OUT)

int imagm

number of filters/bands

string outputHeader

configuration, written atop the output catalogue

accumulated header text describing the run

string outpara

accumulated documentation of the output columns

bool one_mw_ebv = false

Whether or not a single MW E(B-V) value is applied to all sources, as opposed to a different value for each source read from a file

vector<double> mw_classic_extinction_values

If mw_classic_extinction is true, this vector contains the extinction values to apply to each filter for all SEDs. It is computed once at the beginning of the code, based on the selected Milky Way extinction curve and the filter transmission curves.