MultiLightning#
The main interface to multilightning is the MultiLightning class.
- class multi_lightning.MultiLightning#
A class interface to fit “multi-region” spectral energy distributions: SEDs where multiple regions are resolved in some, but not all of the available bandpasses.
- Parameters:
- lghLightning object or list of Nregions Lightning objects
If a single Lightning object, the same model will be applied to each region (albeit with different parameters) and the
Nregionskeyword must be set. More generally, this can by a list of Lightning objects, one per region. Things like the redshift, luminosity distance, and filter set are expected to agree between different objects.- flux_obsnp.ndarray, (Nregions+1, Nfilters), float
An array giving the observed fluxes in mJy: the first row should contain the unresolved “global” fluxes, and subsequent rows should contain the resolved fluxes for each region. Missing or NA entries should be set to NaN. As an example, suppose we have 2 regions with 4 resolved optical measurements and 2 unresolved IR measurements. Our flux array would be structured like:
Opt1 Opt2 Opt3 Opt4 IR1 IR2 unresolved [[ NaN, NaN, NaN, NaN, 0.2, 1], region1 [0.003, 0.002, 0.004, 0.002, NaN, NaN], region2 [ NaN, 0.001, 0.002, 0.001, NaN, NaN]]
where we’ve supposed that region2 is undetected in band Opt1.
- flux_uncnp.ndarray, (Nregions+1, Nfilters), float
An array giving the uncertainties on the fluxes in mJy. Here, missing and NA entries should be set to 0.0.
- model_uncfloat
Fractional model uncertainty to apply to all bands.
- Nregionsint
Number of resolved regions. Only necessary if
lghis a single Lightning object.- reg_nameslist of str
Names for individual regions, e.g. ‘core’, ‘disk’, ‘clumpA’, ‘clumpB’, etc. Defaults to ‘reg1’, ‘reg2’, etc. if not set.
Methods
fit(p0, priors[, Nwalkers, Nsteps, ...])Fit the multi-region model with emcee.
get_model_log_like(params)Calculate model log-likelihood.
get_model_log_prior(params, priors)Calculate prior probability of parameters.
get_model_log_prob(params, priors[, p_bound])Calculate model log probability.
init_from_priors(priors, Nwalkers)Sample an initial state vector for emcee from the priors.
print_params([verbose])List parameters (or pretty-print, when verbose=True)
- __init__(lgh, flux_obs, flux_unc, model_unc=None, Nregions=None, reg_names=None)#
- fit(p0, priors, Nwalkers=64, Nsteps=30000, init_sigma=0.001, progress=True, savefile=None)#
Fit the multi-region model with emcee.
- Parameters:
- priorsdict
A dictionary keyed on
reg_names, where each entry is a list of theNparamsx-many prior functions for each region. Prior functions should be specified by lightning.priors objects. Any prior == None is assumed to indicate a constant parameter.- Nwalkersint
Number of MCMC samplers for the emcee affine-invariant algorithm (Default: 64)
- Nstepsint
Number of steps to run the MCMC (default: 30000)
- init_sigmafloat
Sigma for gaussian ball initialization (default: 1e-3) UNUSED
- progressbool
If
True, print atqdmprogress bar. (Default: True)- savefilestr
Filename to use with the
emceeHDF5 backend (if any). (Default: None)
- Returns:
- sampleremcee.EnsembleSampler
- get_model_log_like(params)#
Calculate model log-likelihood.
- Parameters:
- paramsdict
A dictionary keyed on
reg_names, where each entry is a numpy array with dimensions (Nmodels, Nparamsx), giving the parameters for each region. Note that in the most general caseNparamsxcan be different for each region, while the firstNmodelsaxis is the vectorization axis, and should be the same for each region.
- Returns:
- lnlikenp.ndarray, (Nmodels,)
-0.5 * chi2
- get_model_log_prior(params, priors)#
Calculate prior probability of parameters.
- Parameters:
- paramsdict
A dictionary keyed on
reg_names, where each entry is a numpy array with dimensions (Nmodels, Nparamsx), giving the parameters for each region. Note that in the most general caseNparamsxcan be different for each region, while the firstNmodelsaxis is the vectorization axis, and should be the same for each region.- priorsdict
A dictionary keyed on
reg_names, where each entry is a list of theNparamsx-many prior functions for each region. Prior functions should be specified by lightning.priors objects.
- Returns:
- lnprior_probnp.ndarray, (Nmodels,)
Prior log-probabilities
- get_model_log_prob(params, priors, p_bound=inf)#
Calculate model log probability.
- Parameters:
- paramsdict
A dictionary keyed on
reg_names, where each entry is a numpy array with dimensions (Nmodels, Nparamsx), giving the parameters for each region. Note that in the most general caseNparamsxcan be different for each region, while the firstNmodelsaxis is the vectorization axis, and should be the same for each region.- priorsdict
A dictionary keyed on
reg_names, where each entry is a list of theNparamsx-many prior functions for each region. Prior functions should be specified by lightning.priors objects.- p_boundfloat
The magnitude of the log-probability of zero (default: np.inf)
- Returns:
- log_probnp.ndarray, (Nmodels,)
Log probabilities
- init_from_priors(priors, Nwalkers)#
Sample an initial state vector for emcee from the priors.
- Parameters:
- priorsdict
A dictionary keyed on
reg_names, where each entry is a list of theNparamsx-many prior functions for each region. Prior functions should be specified by lightning.priors objects. Any prior == None is assumed to indicate a constant parameter.- Nwalkersint
Number of MCMC samplers for the emcee affine-invariant algorithm
- Returns:
- x0np.ndarray, (Nwalkers, Ndim)
Sampled initial state for emcee
- print_params(verbose=False)#
List parameters (or pretty-print, when verbose=True)