blendz API documentation

The blendz.Photoz class is designed to be the only user-facing class and has methods for each step of the photo-z analysis.

class blendz.Photoz(model=None, photometry=None, config=None, load_state_path=None, **kwargs)[source]
applyToMarginals(func, num_components, galaxy=None, **kwargs)[source]

Apply a function to the 1D marginal distribution samples of each parameter.

Args:
func (function):
The function to apply to the marginal distribution samples. It should accept an array of the samples as its first argument, with optional keyword arguments.
num_components (int):
Number of components.
galaxy (int or None):
Index of the galaxy to apply the function to. If None, return array with a row for each galaxy. Defaults to None.
**kwargs:
Any optional keyword arguments to pass to the function.
chain(num_components, galaxy=None)[source]

Return the (unweighted) posterior samples.

Args:
num_components (int):
Number of components.
galaxy (int or None):
Index of the galaxy to calculate log-evidence for. If None, return array of log-evidence for every galaxy. Defaults to None.
logbayes(m, n, base=None, galaxy=None)[source]

Return the log of the Bayes factor between m and n components, log[B_mn].

A positive value suggests that that evidence prefers the m-component model over the n-component model.

Args:
m (int):
First number of components.
n (int):
Second number of components.
base (float or None):
Base of the log to return. If None, uses natural log. Defaults to None.
galaxy (int or None):
Index of the galaxy to calculate B_mn for. If None, return array of B_mn for every galaxy. Defaults to None.
logevd(num_components, galaxy=None, return_error=False)[source]

Return the natural log of the evidence.

Args:
num_components (int):
Number of components.
galaxy (int or None):
Index of the galaxy to calculate log-evidence for. If None, return array of log-evidence for every galaxy. Defaults to None.
return_error (bool):
If True, also return the error on the log-evidence. If galaxy is None, this is also an array. Defaults to False.
max(num_components, galaxy=None, bins=20)[source]

Return the maximum-a-posteriori point for the 1D marginal distribution of each parameter.

This is calculated by forming a 1D histogram of each marginal distribution and assigning the MAP of that parameter as the centre of the tallest bin.

Args:
num_components (int):
Number of components.
galaxy (int or None):
Index of the galaxy to calculate the MAP for. If None, return array with rows of MAPs for each galaxy. Defaults to None.
bins (int):
Number of bins to use for each 1D histogram.
mean(num_components, galaxy=None)[source]

Return the mean point for the 1D marginal distribution of each parameter.

Args:
num_components (int):
Number of components.
galaxy (int or None):
Index of the galaxy to calculate the MAP for. If None, return array with rows of means for each galaxy. Defaults to None.
sample(num_components, galaxy=None, nresample=1000, seed=False, measurement_component_mapping=None, npoints=150, print_interval=10, use_pymultinest=None, save_path=None, save_interval=None)[source]

Sample the posterior for a particular number of components.

Args:
num_components (int):
Sample the posterior defined for this number of components in the source.
galaxy (int or None):
Index of the galaxy to sample. If None, sample every galaxy in the photometry. Defaults to None.
nresample (int):
Number of non-weighted samples to draw from the weighted samples distribution from Nested Sampling. Defaults to 1000.
seed (bool or int):
Random seed for sampling to ensure deterministic results when ampling again. If False, do not seed. If True, seed with value derived from galaxy index. If int, seed with specific value.
measurement_component_mapping (None or list of tuples):
If None, sample from the fully blended posterior. For a partially blended posterior, this should be a list of tuples (length = number of measurements), where each tuples contains the (zero-based) indices of the components that measurement contains. Defaults to None.
npoints (int):
Number of live points for the Nested Sampling algorithm. Defaults to 150.
print_interval (int):
Update the progress bar with number of posterior evaluations every print_interval calls. Defaults to 10.
save_path (None or str):
Filepath for saving the Photoz object for reloading with Photoz.loadState. If None, do not automatically save. If given, the Photoz object will be saved to this path after all galaxies are sampled. If save_interval is also not None, the Photoz object will be saved to this path every save_interval galaxies. Defaults to None.
save_interval (None or int)
If given and save_path is not None, the Photoz object will be saved to save_path every save_interval galaxies. Defaults to None.
use_pymultinest (bool or None)
If True, sample using the pyMultinest sampler. This requires PyMultiNest to be installed separately. If False, sample using the Nestle sampler, which is always installed when blendz is. If None, check whether pyMultinest is installed and use it if it is, otherwise use Nestle. Defaults to None.
saveState(filepath)[source]

Save this entire Photoz instance to file.

This saves the exact state of the current object, including all data and any reults from sampling.

Args:
filepath (str): Path to file to save to.
std(num_components, galaxy=None)[source]

Return the standard deviation for the 1D marginal distribution of each parameter.

Args:
num_components (int):
Number of components.
galaxy (int or None):
Index of the galaxy to calculate the MAP for. If None, return array with rows of means for each galaxy. Defaults to None.