POSEIDON.corner

Functions to generate corner plots

Contributions from:

Johannes Buchner [PyMultiNest] (C) 2013-2019 Josh Speagle [Dynesty] (MIT licensed) Ryan MacDonald [POSEIDON modifications] (2021-2022)

Module Contents

Functions

_quantile(x, q[, weights])

Compute (weighted) quantiles from an input set of samples.

resample_equal(samples, weights[, rstate])

Resample a new set of points from the weighted set of inputs, such that

_hist2d(x, y[, smooth, span, weights, levels, ax, ...])

Internal function called by the 'cornerplot' function to generate a 2D

cornerplot(results[, span, quantiles, colour_plt, ...])

Generate a corner plot of the 1D and 2D marginalised posteriors.

generate_cornerplot(planet, model[, retrieval_name, ...])

Generate giant triangle plot of doom to visualise the results of a

Attributes

str_type

SQRTEPS

comm

rank

POSEIDON.corner.str_type
POSEIDON.corner.SQRTEPS
POSEIDON.corner.comm
POSEIDON.corner.rank
POSEIDON.corner._quantile(x, q, weights=None)

Compute (weighted) quantiles from an input set of samples.

Parameters:
  • x (np.array of float) – Input samples.

  • q (np.array of float) – The list of quantiles to compute (ranging from 0 to 1).

  • weights (np.array of float) – The associated weight from each sample.

Returns:

The weighted sample quantiles computed at ‘q’.

Return type:

quantiles (np.array of float)

POSEIDON.corner.resample_equal(samples, weights, rstate=None)

Resample a new set of points from the weighted set of inputs, such that they all have equal weight.

Each input sample appears in the output array either ‘floor(weights[i] * nsamples)’ or ‘ceil(weights[i] * nsamples)’ times, with ‘floor’ or ‘ceil’ randomly selected (weighted by proximity).

Note: implements the systematic resampling method described in Hol, Schon,

and Gustafsson (2006): doi:10.1109/NSSPW.2006.4378824.

Parameters:
  • samples (np.array of float) – Set of unequally weighted samples.

  • weights (np.array of float) – Corresponding weight of each sample.

  • rstate (np.random.RandomState) – Numpy ‘RandomState’ instance.

Returns:

New set of samples with equal weights.

Return type:

equal_weight_samples (np.array of float)

POSEIDON.corner._hist2d(x, y, smooth=0.02, span=None, weights=None, levels=None, ax=None, colour='gray', plot_datapoints=False, plot_density=True, plot_contours=True, no_fill_contours=False, fill_contours=True, contour_kwargs=None, contourf_kwargs=None, data_kwargs=None, **kwargs)

Internal function called by the ‘cornerplot’ function to generate a 2D histogram / contour of samples.

Parameters:
  • x (np.array of float) – Sample positions in the first dimension.

  • y (np.array of float) – Sample positions in the second dimension.

  • smooth (float) – Gaussian smoothing factor for 2D contours.

  • span (list of tuples or float) – A list where each element is either a length-2 tuple containing lower and upper bounds or a float from (0., 1.] giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. If not specified, defaults to +/- 5σ range. Example: span = [(0., 10.), 0.95, (5., 6.)].

  • weights (np.array of float) – Weights associated with the samples.

  • levels (np.array of float) – The contour levels to draw. Default are [1σ, 2σ, 3σ].

  • ax (matplotlib axis object) – A matplotlib axis instance on which to add the 2-D histogram. If not provided, a figure will be generated.

  • colour (str) – The matplotlib-style colour used to draw lines, colour cells, and contours. Default is ‘gray’.

  • plot_datapoints (bool) – Whether to plot the individual data points. Default is False.

  • plot_density (bool) – Whether to draw the density colourmap. Default is True.

  • plot_contours (bool) – Whether to draw the contours. Default is True.

  • no_fill_contours (bool) – Whether to add absolutely no filling to the contours. This differs from ‘fill_contours = False’, which still adds a white fill at the densest points. Default is False.

  • fill_contours (bool) – Whether to fill the contours. Default is True.

  • contour_kwargs (dict) – Any additional keyword arguments to pass to the ‘contour’ method.

  • contourf_kwargs (dict) – Any additional keyword arguments to pass to the ‘contourf’ method.

  • data_kwargs (dict) – Any additional keyword arguments to pass to the ‘plot’ method when adding the individual data points.

Returns:

None.

POSEIDON.corner.cornerplot(results, span=None, quantiles=[0.1587, 0.5, 0.8413], colour_plt='purple', colour_quantile='blue', smooth_hist=30, smooth_corr=0.02, hist_kwargs=None, hist2d_kwargs=None, labels=None, param_names=None, label_kwargs=None, show_titles=True, title_kwargs=None, truths=None, truth_colour='red', truth_kwargs=None, max_n_ticks=5, top_ticks=False, use_math_text=False, verbose=False, fig=None)

Generate a corner plot of the 1D and 2D marginalised posteriors.

Parameters:
  • results (dict) – Results dictionary containing the samples and weights from a nested sampling retrieval.

  • span (list of tuples or float) – A list where each element is either a length-2 tuple containing lower and upper bounds or a float from (0., 1.] giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. If not specified, defaults to +/- 5σ range. Example: span = [(0., 10.), 0.95, (5., 6.)].

  • quantiles (np.array of float) – A list of fractional quantiles to overplot on the 1D marginalised posteriors as vertical dashed lines. Default is ‘[0.1587, 0.5, 0.8413]’ (spanning the 68% / 1σ confidence interval).

  • colour_plt (str) – Matplotlib-style colour for the histograms and probability contours.

  • colour_quantile (str) – Matplotlib-style for the vertical dashed quantile lines.

  • smooth_hist (float or int) – The standard deviation for the Gaussian kernel used to smooth the 1D histograms, expressed as a fraction of the span, if a float provided. If an integer is provided instead, this will instead default to a simple (weighted) histogram with ‘bins=smooth’. Default is 30 bins.

  • smooth_corr (float) – The standard deviation for the Gaussian kernel used to smooth the 2D contours, expressed as a fraction of the span, if a float provided. Default is 2% smoothing.

  • hist_kwargs (dict) – Extra keyword arguments to send to the 1D histograms.

  • hist2d_kwargs (dict) – Extra keyword arguments to send to the 2D contours.

  • labels (np.array of str) – A list of names for each parameter. If not provided, the default name used when plotting will follow the math module ‘x_i’ style.

  • param_names (np.array of str) – List of parameter names used by POSEIDON for this retrieval.

  • label_kwargs (dict) – Extra keyword arguments that will be sent to the matplotlib axes ‘set_xlabel’ and ‘set_ylabel’ methods.

  • show_titles (bool) – Whether to display a title above each 1D marginalised posterior showing the median along with the upper/lower bounds associated with the 1σ confidence interval. Default is True.

  • title_kwargs (dict) – Extra keyword arguments that will be sent to the matplotlib axes ‘set_title’ command.

  • truths (list of float) – A list of reference values that will be overplotted on the traces and marginalised 1D histograms as solid horizontal/vertical lines. Individual values can be exempt using ‘None’. Default is ‘None’.

  • truth_colour (str or list of str) – Matplotlib-style colour (either a single colour or a different value for each subplot) used when plotting ‘truths’. Default is ‘red’.

  • truth_kwargs (dict) – Extra keyword arguments that will be used for plotting the vertical and horizontal lines with ‘truths’.

  • max_n_ticks (int) – Maximum number of ticks allowed. Default is ‘5’.

  • top_ticks (bool) – Whether to label the top (rather than bottom) ticks. Default is False.

  • use_math_text (bool) – Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using ‘e’. Default is False.

  • verbose (bool) – Whether to print the values of the computed quantiles associated with each parameter. Default is False.

  • fig (matplotlib figure object) – If provided, overplot the traces and marginalised 1D histograms onto the provided figure. Otherwise, by default an internal figure is generated.

Returns:

Output corner plot.

Return type:

cornerplot (matplotlib figure, matplotlib axes objects)

POSEIDON.corner.generate_cornerplot(planet, model, retrieval_name=None, true_vals=None, colour_scheme='#984ea3', span=None)

Generate giant triangle plot of doom to visualise the results of a POSEIDON retrieval.

Parameters:
  • planet (dict) – Collection of planetary properties used by POSEIDON.

  • model (dict) – Dictionary containing the description of the POSEIDON model.

  • retrieval_name (str) – Optional retrieval name suffix after the model name.

  • true_vals (list of float) – True values of parameters to overplot.

  • colour_scheme (str with hex code) – Desired colour for the histograms and probability contours.

  • span (list of tuples of float) – Range to plot for each parameter (overrules default +/- 5σ range).

Returns:

Your new triangle plot of doom. Use responsibly!

Return type:

fig (matplotlib figure object)