Plotting Module (brutus.plotting)#

The plotting module provides visualization utilities for stellar photometry analysis including corner plots, SEDs, distance-reddening plots, and photometric offsets.

Corner Plots#

brutus.plotting.cornerplot(idxs, data, params, lndistprior=None, coord=None, avlim=(0.0, 6.0), rvlim=(1.0, 8.0), weights=None, parallax=None, parallax_err=None, Nr=500, applied_parallax=True, pcolor='blue', parallax_kwargs=None, span=None, quantiles=[0.025, 0.5, 0.975], color='black', smooth=10, hist_kwargs=None, hist2d_kwargs=None, labels=None, label_kwargs=None, show_titles=False, title_fmt='.2f', title_kwargs=None, title_quantiles=[0.025, 0.5, 0.975], truths=None, truth_color='red', truth_kwargs=None, max_n_ticks=5, top_ticks=False, use_math_text=False, verbose=False, fig=None, rstate=None, R_solar=8.2, Z_solar=0.025)[source]#

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

Parameters:
  • idxs (~numpy.ndarray of shape (Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • data (3-tuple or 4-tuple containing ~numpy.ndarray`s of shape `(Nsamps)) – The data that will be plotted. Either a collection of (dists, reds, dreds) that were saved, or a collection of (scales, avs, rvs, covs_sar) that will be used to regenerate (dists, reds, dreds) in conjunction with any applied distance and/or parallax priors.

  • params (structured ~numpy.ndarray with shape (Nmodels,)) – Set of parameters corresponding to the input set of models. Note that ‘agewt’ will always be ignored.

  • lndistprior (func, optional) – The log-distsance prior function used. If not provided, the galactic model from Green et al. (2014) will be assumed.

  • coord (2-tuple, optional) – The galactic (l, b) coordinates for the object, which is passed to lndistprior.

  • avlim (2-tuple, optional) – The Av limits used to truncate results. Default is (0., 6.).

  • rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is (1., 8.).

  • weights (~numpy.ndarray of shape (Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • parallax (float, optional) – The parallax estimate for the source.

  • parallax_err (float, optional) – The parallax error.

  • Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 500.

  • applied_parallax (bool, optional) – Whether the parallax was applied when initially computing the fits. Default is True.

  • pcolor (str, optional) – Color used when plotting the parallax prior. Default is ‘blue’.

  • parallax_kwargs (kwargs, optional) – Keyword arguments used when plotting the parallax prior passed to fill_between.

  • span (iterable with shape (ndim,), optional) –

    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. An example would be:

    span = [(0., 10.), 0.95, (5., 6.)]
    

    Default is 0.99 (99% credible interval).

  • quantiles (iterable, optional) – A list of fractional quantiles to overplot on the 1-D marginalized posteriors as vertical dashed lines. Default is [0.025, 0.5, 0.975] (spanning the 95%/2-sigma credible interval).

  • color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting the histograms. Default is ‘black’.

  • smooth (float or iterable with shape (ndim,), optional) – The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 1-D and 2-D marginalized posteriors, expressed as a fraction of the span. If an integer is provided instead, this will instead default to a simple (weighted) histogram with bins=smooth. Default is 10 (10 bins).

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

  • hist2d_kwargs (dict, optional) – Extra keyword arguments to send to the 2-D (smoothed) histograms.

  • labels (iterable with shape (ndim,), optional) – A list of names for each parameter. If not provided, the names will be taken from params.dtype.names.

  • label_kwargs (dict, optional) – Extra keyword arguments that will be sent to the ~matplotlib.axes.Axes.set_xlabel and ~matplotlib.axes.Axes.set_ylabel methods.

  • show_titles (bool, optional) – Whether to display a title above each 1-D marginalized posterior showing the quantiles specified by title_quantiles. By default, This will show the median (0.5 quantile) along with the upper/lower bounds associated with the 0.025 and 0.975 (95%/2-sigma credible interval) quantiles. Default is False.

  • title_fmt (str, optional) – The format string for the quantiles provided in the title. Default is ‘.2f’.

  • title_kwargs (dict, optional) – Extra keyword arguments that will be sent to the ~matplotlib.axes.Axes.set_title command.

  • title_quantiles (iterable, optional) – A list of 3 fractional quantiles displayed in the title, ordered from lowest to highest. Default is [0.025, 0.5, 0.975] (spanning the 95%/2-sigma credible interval).

  • truths (iterable with shape (ndim,), optional) – A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using None. Default is None.

  • truth_color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting truths. Default is ‘red’.

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

  • max_n_ticks (int, optional) – Maximum number of ticks allowed. Default is 5.

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

  • use_math_text (bool, optional) – 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, optional) – Whether to print the values of the computed quantiles associated with each parameter. Default is False.

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

Returns:

cornerplot – Output corner plot.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)

SED Visualization#

brutus.plotting.posterior_predictive(models, idxs, reds, dreds, dists, weights=None, flux=False, data=None, data_err=None, data_mask=None, offset=None, vcolor='black', pcolor='black', labels=None, rstate=None, psig=2.0, fig=None)[source]#

Plot the posterior predictive SED.

Parameters:
  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.

  • idxs (~numpy.ndarray of shape (Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • reds (~numpy.ndarray of shape (Nsamps)) – Reddening samples (in Av) associated with the model indices.

  • dreds (~numpy.ndarray of shape (Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.

  • dists (~numpy.ndarray of shape (Nsamps)) – Distance samples (in kpc) associated with the model indices.

  • weights (~numpy.ndarray of shape (Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • flux (bool, optional) – Whether to plot the SEDs in flux space rather than magniude space. Default is False.

  • data (~numpy.ndarray of shape (Nfilt), optional) – Observed data values (fluxes). If provided, these will be overplotted.

  • data_err (~numpy.ndarray of shape (Nfilt)) – Associated 1-sigma errors on the data values. If provided, these will be overplotted as psig-sigma error bars (default: 2-sigma).

  • data_mask (~numpy.ndarray of shape (Nfilt)) – Binary mask (0/1) indicating whether the data value was observed. If provided, these will be used to mask missing/bad data values.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets that will be applied to the data (i.e. data_new = data * phot_offsets) and errors when provided.

  • vcolor (str, optional) – Color used when plotting the violin plots that comprise the SED posterior predictive distribution. Default is ‘black’.

  • pcolor (str, optional) – Color used when plotting the provided data values. Default is ‘black’.

  • labels (iterable with shape (ndim,), optional) – A list of names corresponding to each filter. If not provided, an ascending set of integers (0, 1, 2, …) will be used.

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

  • psig (float, optional) – The number of sigma to plot when showcasing the error bars from any provided data_err. Default is 2..

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

Returns:

postpredplot – The associated figure, axes, and violinplot dictionary for the posterior predictive distribution.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes, dict)

Summary Plots#

brutus.plotting.summary_plot(models, idxs, reds, dreds, dists, params, data=None, data_err=None, data_mask=None, offset=None, coord=None, parallax=None, parallax_err=None, labels=None, weights=None, show_titles=True, color='black', vcolor='black', pcolor='black', R_solar=8.2, Z_solar=0.025, figsize=None, **corner_kwargs)[source]#

Generate a combined corner plot with posterior predictive SED inset.

Creates a corner plot of the stellar parameter posteriors with the posterior predictive SED placed in the upper-right triangle, making efficient use of the figure space.

Parameters:
  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Model magnitude polynomial coefficients.

  • idxs (~numpy.ndarray of shape (Nsamps)) – Resampled model indices.

  • reds (~numpy.ndarray of shape (Nsamps)) – A(V) samples.

  • dreds (~numpy.ndarray of shape (Nsamps)) – R(V) samples.

  • dists (~numpy.ndarray of shape (Nsamps)) – Distance samples in kpc.

  • params (structured ~numpy.ndarray with shape (Nmodels,)) – Model parameters for the corner plot axes.

  • data (~numpy.ndarray of shape (Nfilt), optional) – Observed flux data for the posterior predictive.

  • data_err (~numpy.ndarray of shape (Nfilt), optional) – Observed flux errors.

  • data_mask (~numpy.ndarray of shape (Nfilt), optional) – Binary mask for valid bands.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets.

  • coord (tuple, optional) – Galactic (l, b) coordinates in degrees.

  • parallax (float, optional) – Parallax in mas.

  • parallax_err (float, optional) – Parallax error in mas.

  • labels (list, optional) – Filter names for the SED plot x-axis.

  • weights (~numpy.ndarray, optional) – Importance weights for the samples.

  • show_titles (bool, optional) – Whether to show parameter titles on the corner plot.

  • color (str, optional) – Color for the corner plot. Default is 'black'.

  • vcolor (str, optional) – Color for the SED violin plots. Default is 'black'.

  • pcolor (str, optional) – Color for the SED data points. Default is 'black'.

  • R_solar (float, optional) – Solar galactocentric radius in kpc. Default is 8.2.

  • Z_solar (float, optional) – Solar height above midplane in kpc. Default is 0.025.

  • figsize (tuple, optional) – Figure size. If None, determined automatically.

  • **corner_kwargs – Additional keyword arguments passed to cornerplot.

Returns:

  • fig (~matplotlib.figure.Figure) – The combined figure.

  • axes (~numpy.ndarray) – The corner plot axes array.

  • ax_sed (~matplotlib.axes.Axes) – The posterior predictive SED axes.

Distance and Reddening#

brutus.plotting.dist_vs_red(data, ebv=None, dist_type='distance_modulus', lndistprior=None, coord=None, avlim=(0.0, 6.0), rvlim=(1.0, 8.0), weights=None, parallax=None, parallax_err=None, Nr=300, cmap='Blues', bins=300, span=None, smooth=0.015, plot_kwargs=None, truths=None, truth_color='red', truth_kwargs=None, rstate=None)[source]#

Generate a 2-D plot of distance vs reddening.

Parameters:
  • data (3-tuple or 4-tuple containing ~numpy.ndarray`s of shape `(Nsamps)) – The data that will be plotted. Either a collection of (dists, reds, dreds) that were saved, or a collection of (scales, avs, rvs, covs_sar) that will be used to regenerate (dists, reds) in conjunction with any applied distance and/or parallax priors.

  • ebv (bool, optional) – If provided, will convert from Av to E(B-V) when plotting using the provided Rv values. Default is False.

  • dist_type (str, optional) – The distance format to be plotted. Options include ‘parallax’, ‘scale’, ‘distance’, and ‘distance_modulus’. Default is ‘distance_modulus.

  • lndistprior (func, optional) – The log-distsance prior function used. If not provided, the galactic model from Green et al. (2014) will be assumed.

  • coord (2-tuple, optional) – The galactic (l, b) coordinates for the object, which is passed to lndistprior.

  • avlim (2-tuple, optional) – The Av limits used to truncate results. Default is (0., 6.).

  • rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is (1., 8.).

  • weights (~numpy.ndarray of shape (Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • parallax (float, optional) – The parallax estimate for the source.

  • parallax_err (float, optional) – The parallax error.

  • Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 300.

  • cmap (str, optional) – The colormap used when plotting. Default is ‘Blues’.

  • bins (int or list of ints with length (ndim,), optional) – The number of bins to be used in each dimension. Default is 300.

  • span (iterable with shape (2, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds. If not provided, the x-axis will use the provided Av bounds while the y-axis will span (4., 19.) in distance modulus (both appropriately transformed).

  • smooth (int/float or list of ints/floats with shape (ndim,), optional) – The standard deviation (either a single value or a different value for each axis) for the Gaussian kernel used to smooth the 2-D marginalized posteriors. If an int is passed, the smoothing will be applied in units of the binning in that dimension. If a float is passed, it is expressed as a fraction of the span. Default is 0.015 (1.5% smoothing). Cannot smooth by more than the provided parallax will allow.

  • plot_kwargs (dict, optional) – Extra keyword arguments to be used when plotting the smoothed 2-D histograms.

  • truths (iterable with shape (ndim,), optional) – A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using None. Default is None.

  • truth_color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting truths. Default is ‘red’.

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

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

Returns:

hist2d – Output 2-D histogram.

Return type:

(counts, xedges, yedges, ~matplotlib.figure.Image)

brutus.plotting.bin_pdfs_distred(data, cdf=False, ebv=False, dist_type='distance_modulus', lndistprior=None, coord=None, avlim=(0.0, 6.0), rvlim=(1.0, 8.0), parallaxes=None, parallax_errors=None, Nr=100, bins=(750, 300), span=None, smooth=0.01, rstate=None, verbose=False, R_solar=8.2, Z_solar=0.025)[source]#

Generate binned versions of the 2-D posteriors for the distance and reddening.

Parameters:
  • data (3-tuple or 4-tuple containing ~numpy.ndarray`s of shape `(Nsamps)) – The data that will be plotted. Either a collection of (dists, reds, dreds) that were saved, or a collection of (scales, avs, rvs, covs_sar) that will be used to regenerate (dists, reds) in conjunction with any applied distance and/or parallax priors.

  • cdf (bool, optional) – Whether to compute the CDF along the reddening axis instead of the PDF. Useful when evaluating the MAP LOS fit. Default is False.

  • ebv (bool, optional) – If provided, will convert from Av to E(B-V) when plotting using the provided Rv values. Default is False.

  • dist_type (str, optional) – The distance format to be plotted. Options include ‘parallax’, ‘scale’, ‘distance’, and ‘distance_modulus’. Default is ‘distance_modulus.

  • lndistprior (func, optional) – The log-distsance prior function used. If not provided, the galactic model from Green et al. (2014) will be assumed.

  • coord (2-tuple, optional) – The galactic (l, b) coordinates for the object, which is passed to lndistprior when re-generating the fits.

  • avlim (2-tuple, optional) – The Av limits used to truncate results. Default is (0., 6.).

  • rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is (1., 8.).

  • parallaxes (~numpy.ndarray of shape (Nobj,), optional) – The parallax estimates for the sources.

  • parallax_errors (~numpy.ndarray of shape (Nobj,), optional) – The parallax errors for the sources.

  • Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 100.

  • bins (int or list of ints with length (ndim,), optional) – The number of bins to be used in each dimension. Default is (750, 300) (distance, reddening).

  • span (iterable with shape (ndim, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds. If not provided, the x-axis will use the provided Av bounds while the y-axis will span (4., 19.) in distance modulus (both appropriately transformed).

  • smooth (float or list of floats with shape (ndim,), optional) – The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 2-D marginalized posteriors, expressed as a fraction of the span. Default is 0.01 (1% smoothing).

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

  • verbose (bool, optional) – Whether to print progress to ~sys.stderr. Default is False.

Returns:

  • binned_vals (~numpy.ndarray of shape (Nobj, Nxbin, Nybin)) – Binned versions of the PDFs or CDFs.

  • xedges (~numpy.ndarray of shape (Nxbin+1,)) – The edges defining the bins in distance.

  • yedges (~numpy.ndarray of shape (Nybin+1,)) – The edges defining the bins in reddening.

Photometric Offsets#

brutus.plotting.photometric_offsets(phot, err, mask, models, idxs, reds, dreds, dists, x=None, flux=True, weights=None, bins=100, offset=None, dim_prior=True, plot_thresh=0.0, cmap='viridis', xspan=None, yspan=None, titles=None, xlabel=None, plot_kwargs=None, fig=None)[source]#

Plot photometric offsets (mag_pred - mag_obs).

Parameters:
  • phot (~numpy.ndarray of shape (Nobj, Nfilt), optional) – Observed data values (fluxes). If provided, these will be overplotted.

  • err (~numpy.ndarray of shape (Nobj, Nfilt)) – Associated errors on the data values. If provided, these will be overplotted as error bars.

  • mask (~numpy.ndarray of shape (Nobj, Nfilt)) – Binary mask (0/1) indicating whether the data value was observed. If provided, these will be used to mask missing/bad data values.

  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.

  • idxs (~numpy.ndarray of shape (Nobj, Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • reds (~numpy.ndarray of shape (Nobj, Nsamps)) – Reddening samples (in Av) associated with the model indices.

  • dreds (~numpy.ndarray of shape (Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.

  • dists (~numpy.ndarray of shape (Nobj, Nsamps)) – Distance samples (in kpc) associated with the model indices.

  • x (~numpy.ndarray with shape (Nobj) or (Nobj, Nsamps), optional) – Corresponding values to be plotted on the x axis. If not provided, the default behavior is to plot as a function of observed magnitude.

  • flux (bool, optional) – Whether the photometry provided is in fluxes (instead of magnitudes). Default is True.

  • weights (~numpy.ndarray of shape (Nobj) or (Nobj, Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • bins (single value or iterable of length Nfilt, optional) – The number of bins to use. Passed to ~matplotlib.pyplot.hist2d. Default is 100.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets that will be applied to the data (i.e. data_new = data * phot_offsets) and errors when provided.

  • dim_prior (bool, optional) – Whether to apply a dimensional-based correction (prior) to the log-likelihood when reweighting the data while cycling through each band. Transforms the likelihood to a chi2 distribution with Nfilt - 3 degrees of freedom. Default is True.

  • plot_thresh (float, optional) – The threshold used to threshold the colormap when plotting. Default is 0..

  • cmap (colormap, optional) – The colormap used when plotting results. Default is ‘viridis’.

  • xspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the x-axis for each plot.

  • yspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the y-axis for each plot.

  • titles (iterable of str of length Nfilt, optional) – Titles for each of the subplots corresponding to each band. If not provided Band # will be used.

  • xlabel (str, optional) – Labels for the x-axis of each subplot. If not provided, these will default to the titles.

  • plot_kwargs (kwargs, optional) – Keyword arguments to be passed to ~matplotlib.pyplot.imshow.

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

Returns:

postpredplot – The associated figure and axes for the photometric offsets.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)

brutus.plotting.photometric_offsets_2d(phot, err, mask, models, idxs, reds, dreds, dists, x, y, flux=True, weights=None, bins=100, offset=None, dim_prior=True, plot_thresh=10.0, cmap='coolwarm', clims=(-0.05, 0.05), xspan=None, yspan=None, titles=None, show_off=True, xlabel=None, ylabel=None, plot_kwargs=None, fig=None)[source]#

Plot photometric offsets (mag_pred - mag_obs).

Parameters:
  • phot (~numpy.ndarray of shape (Nobj, Nfilt), optional) – Observed data values (fluxes). If provided, these will be overplotted.

  • err (~numpy.ndarray of shape (Nobj, Nfilt)) – Associated errors on the data values. If provided, these will be overplotted as error bars.

  • mask (~numpy.ndarray of shape (Nobj, Nfilt)) – Binary mask (0/1) indicating whether the data value was observed. If provided, these will be used to mask missing/bad data values.

  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.

  • idxs (~numpy.ndarray of shape (Nobj, Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • reds (~numpy.ndarray of shape (Nobj, Nsamps)) – Reddening samples (in Av) associated with the model indices.

  • dreds (~numpy.ndarray of shape (Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.

  • dists (~numpy.ndarray of shape (Nobj, Nsamps)) – Distance samples (in kpc) associated with the model indices.

  • x (~numpy.ndarray with shape (Nobj) or (Nobj, Nsamps)) – Values to be plotted on the x axis. Required.

  • y (~numpy.ndarray with shape (Nobj) or (Nobj, Nsamps)) – Values to be plotted on the y axis. Required.

  • flux (bool, optional) – Whether the photometry provided is in fluxes (instead of magnitudes). Default is True.

  • weights (~numpy.ndarray of shape (Nobj) or (Nobj, Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • bins (single value or iterable of length Nfilt, optional) – The number of bins to use. Passed to ~matplotlib.pyplot.hist2d. Default is 100.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets that will be applied to the data (i.e. data_new = data * phot_offsets) and errors when provided.

  • dim_prior (bool, optional) – Whether to apply a dimensional-based correction (prior) to the log-likelihood when reweighting the data while cycling through each band. Transforms the likelihood to a chi2 distribution with Nfilt - 3 degrees of freedom. Default is True.

  • plot_thresh (float, optional) – The threshold used to threshold the colormap when plotting. Default is 10..

  • cmap (colormap, optional) – The colormap used when plotting results. Default is ‘coolwarm’.

  • clims (2-tuple, optional) – Plotting bounds for the colorbar. Default is (-0.05, 0.05).

  • xspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the x-axis for each plot.

  • yspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the y-axis for each plot.

  • titles (iterable of str of length Nfilt, optional) – Titles for each of the subplots corresponding to each band. If not provided Band # will be used.

  • show_off (bool, optional) – Whether to include the offsets in the titles. Default is True.

  • xlabel (str, optional) – Label for the x-axis of each subplot. If not provided, this will default to X.

  • ylabel (str, optional) – Label for the y-axis of each subplot. If not provided, this will default to Y.

  • plot_kwargs (kwargs, optional) – Keyword arguments to be passed to ~matplotlib.pyplot.imshow.

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

Returns:

postpredplot – The associated figure and axes for the photometric offsets.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)

Plotting Utilities#

brutus.plotting.hist2d(x, y, smooth=0.02, span=None, weights=None, levels=None, ax=None, color='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)[source]#

Internal function used to generate a 2-D histogram/contour of samples.

This is the refactored version of _hist2d from the original plotting.py.

Parameters:
  • x (interable with shape (nsamps,)) – Sample positions in the first dimension.

  • y (iterable with shape (nsamps,)) – Sample positions in the second dimension.

  • span (iterable with shape (ndim,), optional) –

    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. An example would be:

    span = [(0., 10.), 0.95, (5., 6.)]
    

    Default is 0.99 (99% credible interval).

  • weights (iterable with shape (nsamps,)) – Weights associated with the samples. Default is None (no weights).

  • levels (iterable, optional) – The contour levels to draw. Default are [0.5, 1, 1.5, 2]-sigma.

  • ax (~matplotlib.axes.Axes, optional) – An ~matplotlib.axes.axes instance on which to add the 2-D histogram. If not provided, a figure will be generated.

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

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

  • plot_density (bool, optional) – Whether to draw the density colormap. Default is True.

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

  • no_fill_contours (bool, optional) – 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, optional) – 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.

Submodules#

For advanced users who need access to internal implementations:

Corner plot visualization functions.

This module provides functions for creating corner plots of multi-dimensional posterior distributions.

brutus.plotting.corner.cornerplot(idxs, data, params, lndistprior=None, coord=None, avlim=(0.0, 6.0), rvlim=(1.0, 8.0), weights=None, parallax=None, parallax_err=None, Nr=500, applied_parallax=True, pcolor='blue', parallax_kwargs=None, span=None, quantiles=[0.025, 0.5, 0.975], color='black', smooth=10, hist_kwargs=None, hist2d_kwargs=None, labels=None, label_kwargs=None, show_titles=False, title_fmt='.2f', title_kwargs=None, title_quantiles=[0.025, 0.5, 0.975], truths=None, truth_color='red', truth_kwargs=None, max_n_ticks=5, top_ticks=False, use_math_text=False, verbose=False, fig=None, rstate=None, R_solar=8.2, Z_solar=0.025)[source]

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

Parameters:
  • idxs (~numpy.ndarray of shape (Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • data (3-tuple or 4-tuple containing ~numpy.ndarray`s of shape `(Nsamps)) – The data that will be plotted. Either a collection of (dists, reds, dreds) that were saved, or a collection of (scales, avs, rvs, covs_sar) that will be used to regenerate (dists, reds, dreds) in conjunction with any applied distance and/or parallax priors.

  • params (structured ~numpy.ndarray with shape (Nmodels,)) – Set of parameters corresponding to the input set of models. Note that ‘agewt’ will always be ignored.

  • lndistprior (func, optional) – The log-distsance prior function used. If not provided, the galactic model from Green et al. (2014) will be assumed.

  • coord (2-tuple, optional) – The galactic (l, b) coordinates for the object, which is passed to lndistprior.

  • avlim (2-tuple, optional) – The Av limits used to truncate results. Default is (0., 6.).

  • rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is (1., 8.).

  • weights (~numpy.ndarray of shape (Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • parallax (float, optional) – The parallax estimate for the source.

  • parallax_err (float, optional) – The parallax error.

  • Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 500.

  • applied_parallax (bool, optional) – Whether the parallax was applied when initially computing the fits. Default is True.

  • pcolor (str, optional) – Color used when plotting the parallax prior. Default is ‘blue’.

  • parallax_kwargs (kwargs, optional) – Keyword arguments used when plotting the parallax prior passed to fill_between.

  • span (iterable with shape (ndim,), optional) –

    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. An example would be:

    span = [(0., 10.), 0.95, (5., 6.)]
    

    Default is 0.99 (99% credible interval).

  • quantiles (iterable, optional) – A list of fractional quantiles to overplot on the 1-D marginalized posteriors as vertical dashed lines. Default is [0.025, 0.5, 0.975] (spanning the 95%/2-sigma credible interval).

  • color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting the histograms. Default is ‘black’.

  • smooth (float or iterable with shape (ndim,), optional) – The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 1-D and 2-D marginalized posteriors, expressed as a fraction of the span. If an integer is provided instead, this will instead default to a simple (weighted) histogram with bins=smooth. Default is 10 (10 bins).

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

  • hist2d_kwargs (dict, optional) – Extra keyword arguments to send to the 2-D (smoothed) histograms.

  • labels (iterable with shape (ndim,), optional) – A list of names for each parameter. If not provided, the names will be taken from params.dtype.names.

  • label_kwargs (dict, optional) – Extra keyword arguments that will be sent to the ~matplotlib.axes.Axes.set_xlabel and ~matplotlib.axes.Axes.set_ylabel methods.

  • show_titles (bool, optional) – Whether to display a title above each 1-D marginalized posterior showing the quantiles specified by title_quantiles. By default, This will show the median (0.5 quantile) along with the upper/lower bounds associated with the 0.025 and 0.975 (95%/2-sigma credible interval) quantiles. Default is False.

  • title_fmt (str, optional) – The format string for the quantiles provided in the title. Default is ‘.2f’.

  • title_kwargs (dict, optional) – Extra keyword arguments that will be sent to the ~matplotlib.axes.Axes.set_title command.

  • title_quantiles (iterable, optional) – A list of 3 fractional quantiles displayed in the title, ordered from lowest to highest. Default is [0.025, 0.5, 0.975] (spanning the 95%/2-sigma credible interval).

  • truths (iterable with shape (ndim,), optional) – A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using None. Default is None.

  • truth_color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting truths. Default is ‘red’.

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

  • max_n_ticks (int, optional) – Maximum number of ticks allowed. Default is 5.

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

  • use_math_text (bool, optional) – 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, optional) – Whether to print the values of the computed quantiles associated with each parameter. Default is False.

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

Returns:

cornerplot – Output corner plot.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)

Distance and reddening visualization functions.

This module provides functions for plotting distance vs reddening posterior distributions.

brutus.plotting.distance.dist_vs_red(data, ebv=None, dist_type='distance_modulus', lndistprior=None, coord=None, avlim=(0.0, 6.0), rvlim=(1.0, 8.0), weights=None, parallax=None, parallax_err=None, Nr=300, cmap='Blues', bins=300, span=None, smooth=0.015, plot_kwargs=None, truths=None, truth_color='red', truth_kwargs=None, rstate=None)[source]

Generate a 2-D plot of distance vs reddening.

Parameters:
  • data (3-tuple or 4-tuple containing ~numpy.ndarray`s of shape `(Nsamps)) – The data that will be plotted. Either a collection of (dists, reds, dreds) that were saved, or a collection of (scales, avs, rvs, covs_sar) that will be used to regenerate (dists, reds) in conjunction with any applied distance and/or parallax priors.

  • ebv (bool, optional) – If provided, will convert from Av to E(B-V) when plotting using the provided Rv values. Default is False.

  • dist_type (str, optional) – The distance format to be plotted. Options include ‘parallax’, ‘scale’, ‘distance’, and ‘distance_modulus’. Default is ‘distance_modulus.

  • lndistprior (func, optional) – The log-distsance prior function used. If not provided, the galactic model from Green et al. (2014) will be assumed.

  • coord (2-tuple, optional) – The galactic (l, b) coordinates for the object, which is passed to lndistprior.

  • avlim (2-tuple, optional) – The Av limits used to truncate results. Default is (0., 6.).

  • rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is (1., 8.).

  • weights (~numpy.ndarray of shape (Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • parallax (float, optional) – The parallax estimate for the source.

  • parallax_err (float, optional) – The parallax error.

  • Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 300.

  • cmap (str, optional) – The colormap used when plotting. Default is ‘Blues’.

  • bins (int or list of ints with length (ndim,), optional) – The number of bins to be used in each dimension. Default is 300.

  • span (iterable with shape (2, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds. If not provided, the x-axis will use the provided Av bounds while the y-axis will span (4., 19.) in distance modulus (both appropriately transformed).

  • smooth (int/float or list of ints/floats with shape (ndim,), optional) – The standard deviation (either a single value or a different value for each axis) for the Gaussian kernel used to smooth the 2-D marginalized posteriors. If an int is passed, the smoothing will be applied in units of the binning in that dimension. If a float is passed, it is expressed as a fraction of the span. Default is 0.015 (1.5% smoothing). Cannot smooth by more than the provided parallax will allow.

  • plot_kwargs (dict, optional) – Extra keyword arguments to be used when plotting the smoothed 2-D histograms.

  • truths (iterable with shape (ndim,), optional) – A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using None. Default is None.

  • truth_color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting truths. Default is ‘red’.

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

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

Returns:

hist2d – Output 2-D histogram.

Return type:

(counts, xedges, yedges, ~matplotlib.figure.Image)

Data binning utilities for plotting posterior distributions.

This module provides functions to bin posterior samples of distance and reddening for visualization purposes.

brutus.plotting.binning.bin_pdfs_distred(data, cdf=False, ebv=False, dist_type='distance_modulus', lndistprior=None, coord=None, avlim=(0.0, 6.0), rvlim=(1.0, 8.0), parallaxes=None, parallax_errors=None, Nr=100, bins=(750, 300), span=None, smooth=0.01, rstate=None, verbose=False, R_solar=8.2, Z_solar=0.025)[source]

Generate binned versions of the 2-D posteriors for the distance and reddening.

Parameters:
  • data (3-tuple or 4-tuple containing ~numpy.ndarray`s of shape `(Nsamps)) – The data that will be plotted. Either a collection of (dists, reds, dreds) that were saved, or a collection of (scales, avs, rvs, covs_sar) that will be used to regenerate (dists, reds) in conjunction with any applied distance and/or parallax priors.

  • cdf (bool, optional) – Whether to compute the CDF along the reddening axis instead of the PDF. Useful when evaluating the MAP LOS fit. Default is False.

  • ebv (bool, optional) – If provided, will convert from Av to E(B-V) when plotting using the provided Rv values. Default is False.

  • dist_type (str, optional) – The distance format to be plotted. Options include ‘parallax’, ‘scale’, ‘distance’, and ‘distance_modulus’. Default is ‘distance_modulus.

  • lndistprior (func, optional) – The log-distsance prior function used. If not provided, the galactic model from Green et al. (2014) will be assumed.

  • coord (2-tuple, optional) – The galactic (l, b) coordinates for the object, which is passed to lndistprior when re-generating the fits.

  • avlim (2-tuple, optional) – The Av limits used to truncate results. Default is (0., 6.).

  • rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is (1., 8.).

  • parallaxes (~numpy.ndarray of shape (Nobj,), optional) – The parallax estimates for the sources.

  • parallax_errors (~numpy.ndarray of shape (Nobj,), optional) – The parallax errors for the sources.

  • Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 100.

  • bins (int or list of ints with length (ndim,), optional) – The number of bins to be used in each dimension. Default is (750, 300) (distance, reddening).

  • span (iterable with shape (ndim, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds. If not provided, the x-axis will use the provided Av bounds while the y-axis will span (4., 19.) in distance modulus (both appropriately transformed).

  • smooth (float or list of floats with shape (ndim,), optional) – The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 2-D marginalized posteriors, expressed as a fraction of the span. Default is 0.01 (1% smoothing).

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

  • verbose (bool, optional) – Whether to print progress to ~sys.stderr. Default is False.

Returns:

  • binned_vals (~numpy.ndarray of shape (Nobj, Nxbin, Nybin)) – Binned versions of the PDFs or CDFs.

  • xedges (~numpy.ndarray of shape (Nxbin+1,)) – The edges defining the bins in distance.

  • yedges (~numpy.ndarray of shape (Nybin+1,)) – The edges defining the bins in reddening.

SED (Spectral Energy Distribution) plotting utilities.

This module contains functions for visualizing stellar SEDs and related posterior predictive distributions.

brutus.plotting.sed.posterior_predictive(models, idxs, reds, dreds, dists, weights=None, flux=False, data=None, data_err=None, data_mask=None, offset=None, vcolor='black', pcolor='black', labels=None, rstate=None, psig=2.0, fig=None)[source]

Plot the posterior predictive SED.

Parameters:
  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.

  • idxs (~numpy.ndarray of shape (Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • reds (~numpy.ndarray of shape (Nsamps)) – Reddening samples (in Av) associated with the model indices.

  • dreds (~numpy.ndarray of shape (Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.

  • dists (~numpy.ndarray of shape (Nsamps)) – Distance samples (in kpc) associated with the model indices.

  • weights (~numpy.ndarray of shape (Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • flux (bool, optional) – Whether to plot the SEDs in flux space rather than magniude space. Default is False.

  • data (~numpy.ndarray of shape (Nfilt), optional) – Observed data values (fluxes). If provided, these will be overplotted.

  • data_err (~numpy.ndarray of shape (Nfilt)) – Associated 1-sigma errors on the data values. If provided, these will be overplotted as psig-sigma error bars (default: 2-sigma).

  • data_mask (~numpy.ndarray of shape (Nfilt)) – Binary mask (0/1) indicating whether the data value was observed. If provided, these will be used to mask missing/bad data values.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets that will be applied to the data (i.e. data_new = data * phot_offsets) and errors when provided.

  • vcolor (str, optional) – Color used when plotting the violin plots that comprise the SED posterior predictive distribution. Default is ‘black’.

  • pcolor (str, optional) – Color used when plotting the provided data values. Default is ‘black’.

  • labels (iterable with shape (ndim,), optional) – A list of names corresponding to each filter. If not provided, an ascending set of integers (0, 1, 2, …) will be used.

  • rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.

  • psig (float, optional) – The number of sigma to plot when showcasing the error bars from any provided data_err. Default is 2..

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

Returns:

postpredplot – The associated figure, axes, and violinplot dictionary for the posterior predictive distribution.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes, dict)

Combined summary plot: corner plot + posterior predictive SED in one figure.

Places the posterior predictive SED in the upper-right triangle of the corner plot to eliminate white space and provide a single diagnostic view.

brutus.plotting.summary.summary_plot(models, idxs, reds, dreds, dists, params, data=None, data_err=None, data_mask=None, offset=None, coord=None, parallax=None, parallax_err=None, labels=None, weights=None, show_titles=True, color='black', vcolor='black', pcolor='black', R_solar=8.2, Z_solar=0.025, figsize=None, **corner_kwargs)[source]

Generate a combined corner plot with posterior predictive SED inset.

Creates a corner plot of the stellar parameter posteriors with the posterior predictive SED placed in the upper-right triangle, making efficient use of the figure space.

Parameters:
  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Model magnitude polynomial coefficients.

  • idxs (~numpy.ndarray of shape (Nsamps)) – Resampled model indices.

  • reds (~numpy.ndarray of shape (Nsamps)) – A(V) samples.

  • dreds (~numpy.ndarray of shape (Nsamps)) – R(V) samples.

  • dists (~numpy.ndarray of shape (Nsamps)) – Distance samples in kpc.

  • params (structured ~numpy.ndarray with shape (Nmodels,)) – Model parameters for the corner plot axes.

  • data (~numpy.ndarray of shape (Nfilt), optional) – Observed flux data for the posterior predictive.

  • data_err (~numpy.ndarray of shape (Nfilt), optional) – Observed flux errors.

  • data_mask (~numpy.ndarray of shape (Nfilt), optional) – Binary mask for valid bands.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets.

  • coord (tuple, optional) – Galactic (l, b) coordinates in degrees.

  • parallax (float, optional) – Parallax in mas.

  • parallax_err (float, optional) – Parallax error in mas.

  • labels (list, optional) – Filter names for the SED plot x-axis.

  • weights (~numpy.ndarray, optional) – Importance weights for the samples.

  • show_titles (bool, optional) – Whether to show parameter titles on the corner plot.

  • color (str, optional) – Color for the corner plot. Default is 'black'.

  • vcolor (str, optional) – Color for the SED violin plots. Default is 'black'.

  • pcolor (str, optional) – Color for the SED data points. Default is 'black'.

  • R_solar (float, optional) – Solar galactocentric radius in kpc. Default is 8.2.

  • Z_solar (float, optional) – Solar height above midplane in kpc. Default is 0.025.

  • figsize (tuple, optional) – Figure size. If None, determined automatically.

  • **corner_kwargs – Additional keyword arguments passed to cornerplot.

Returns:

  • fig (~matplotlib.figure.Figure) – The combined figure.

  • axes (~numpy.ndarray) – The corner plot axes array.

  • ax_sed (~matplotlib.axes.Axes) – The posterior predictive SED axes.

Photometric offset visualization functions.

This module provides functions for plotting photometric offsets in 1D and 2D formats.

brutus.plotting.offsets.photometric_offsets(phot, err, mask, models, idxs, reds, dreds, dists, x=None, flux=True, weights=None, bins=100, offset=None, dim_prior=True, plot_thresh=0.0, cmap='viridis', xspan=None, yspan=None, titles=None, xlabel=None, plot_kwargs=None, fig=None)[source]

Plot photometric offsets (mag_pred - mag_obs).

Parameters:
  • phot (~numpy.ndarray of shape (Nobj, Nfilt), optional) – Observed data values (fluxes). If provided, these will be overplotted.

  • err (~numpy.ndarray of shape (Nobj, Nfilt)) – Associated errors on the data values. If provided, these will be overplotted as error bars.

  • mask (~numpy.ndarray of shape (Nobj, Nfilt)) – Binary mask (0/1) indicating whether the data value was observed. If provided, these will be used to mask missing/bad data values.

  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.

  • idxs (~numpy.ndarray of shape (Nobj, Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • reds (~numpy.ndarray of shape (Nobj, Nsamps)) – Reddening samples (in Av) associated with the model indices.

  • dreds (~numpy.ndarray of shape (Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.

  • dists (~numpy.ndarray of shape (Nobj, Nsamps)) – Distance samples (in kpc) associated with the model indices.

  • x (~numpy.ndarray with shape (Nobj) or (Nobj, Nsamps), optional) – Corresponding values to be plotted on the x axis. If not provided, the default behavior is to plot as a function of observed magnitude.

  • flux (bool, optional) – Whether the photometry provided is in fluxes (instead of magnitudes). Default is True.

  • weights (~numpy.ndarray of shape (Nobj) or (Nobj, Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • bins (single value or iterable of length Nfilt, optional) – The number of bins to use. Passed to ~matplotlib.pyplot.hist2d. Default is 100.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets that will be applied to the data (i.e. data_new = data * phot_offsets) and errors when provided.

  • dim_prior (bool, optional) – Whether to apply a dimensional-based correction (prior) to the log-likelihood when reweighting the data while cycling through each band. Transforms the likelihood to a chi2 distribution with Nfilt - 3 degrees of freedom. Default is True.

  • plot_thresh (float, optional) – The threshold used to threshold the colormap when plotting. Default is 0..

  • cmap (colormap, optional) – The colormap used when plotting results. Default is ‘viridis’.

  • xspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the x-axis for each plot.

  • yspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the y-axis for each plot.

  • titles (iterable of str of length Nfilt, optional) – Titles for each of the subplots corresponding to each band. If not provided Band # will be used.

  • xlabel (str, optional) – Labels for the x-axis of each subplot. If not provided, these will default to the titles.

  • plot_kwargs (kwargs, optional) – Keyword arguments to be passed to ~matplotlib.pyplot.imshow.

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

Returns:

postpredplot – The associated figure and axes for the photometric offsets.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)

brutus.plotting.offsets.photometric_offsets_2d(phot, err, mask, models, idxs, reds, dreds, dists, x, y, flux=True, weights=None, bins=100, offset=None, dim_prior=True, plot_thresh=10.0, cmap='coolwarm', clims=(-0.05, 0.05), xspan=None, yspan=None, titles=None, show_off=True, xlabel=None, ylabel=None, plot_kwargs=None, fig=None)[source]

Plot photometric offsets (mag_pred - mag_obs).

Parameters:
  • phot (~numpy.ndarray of shape (Nobj, Nfilt), optional) – Observed data values (fluxes). If provided, these will be overplotted.

  • err (~numpy.ndarray of shape (Nobj, Nfilt)) – Associated errors on the data values. If provided, these will be overplotted as error bars.

  • mask (~numpy.ndarray of shape (Nobj, Nfilt)) – Binary mask (0/1) indicating whether the data value was observed. If provided, these will be used to mask missing/bad data values.

  • models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.

  • idxs (~numpy.ndarray of shape (Nobj, Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.

  • reds (~numpy.ndarray of shape (Nobj, Nsamps)) – Reddening samples (in Av) associated with the model indices.

  • dreds (~numpy.ndarray of shape (Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.

  • dists (~numpy.ndarray of shape (Nobj, Nsamps)) – Distance samples (in kpc) associated with the model indices.

  • x (~numpy.ndarray with shape (Nobj) or (Nobj, Nsamps)) – Values to be plotted on the x axis. Required.

  • y (~numpy.ndarray with shape (Nobj) or (Nobj, Nsamps)) – Values to be plotted on the y axis. Required.

  • flux (bool, optional) – Whether the photometry provided is in fluxes (instead of magnitudes). Default is True.

  • weights (~numpy.ndarray of shape (Nobj) or (Nobj, Nsamps), optional) – An optional set of importance weights used to reweight the samples.

  • bins (single value or iterable of length Nfilt, optional) – The number of bins to use. Passed to ~matplotlib.pyplot.hist2d. Default is 100.

  • offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative photometric offsets that will be applied to the data (i.e. data_new = data * phot_offsets) and errors when provided.

  • dim_prior (bool, optional) – Whether to apply a dimensional-based correction (prior) to the log-likelihood when reweighting the data while cycling through each band. Transforms the likelihood to a chi2 distribution with Nfilt - 3 degrees of freedom. Default is True.

  • plot_thresh (float, optional) – The threshold used to threshold the colormap when plotting. Default is 10..

  • cmap (colormap, optional) – The colormap used when plotting results. Default is ‘coolwarm’.

  • clims (2-tuple, optional) – Plotting bounds for the colorbar. Default is (-0.05, 0.05).

  • xspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the x-axis for each plot.

  • yspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the y-axis for each plot.

  • titles (iterable of str of length Nfilt, optional) – Titles for each of the subplots corresponding to each band. If not provided Band # will be used.

  • show_off (bool, optional) – Whether to include the offsets in the titles. Default is True.

  • xlabel (str, optional) – Label for the x-axis of each subplot. If not provided, this will default to X.

  • ylabel (str, optional) – Label for the y-axis of each subplot. If not provided, this will default to Y.

  • plot_kwargs (kwargs, optional) – Keyword arguments to be passed to ~matplotlib.pyplot.imshow.

  • fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.

Returns:

postpredplot – The associated figure and axes for the photometric offsets.

Return type:

(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)

Common plotting utilities for brutus visualization functions.

This module provides low-level plotting utilities shared across multiple plotting functions.

brutus.plotting.utils.hist2d(x, y, smooth=0.02, span=None, weights=None, levels=None, ax=None, color='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)[source]

Internal function used to generate a 2-D histogram/contour of samples.

This is the refactored version of _hist2d from the original plotting.py.

Parameters:
  • x (interable with shape (nsamps,)) – Sample positions in the first dimension.

  • y (iterable with shape (nsamps,)) – Sample positions in the second dimension.

  • span (iterable with shape (ndim,), optional) –

    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. An example would be:

    span = [(0., 10.), 0.95, (5., 6.)]
    

    Default is 0.99 (99% credible interval).

  • weights (iterable with shape (nsamps,)) – Weights associated with the samples. Default is None (no weights).

  • levels (iterable, optional) – The contour levels to draw. Default are [0.5, 1, 1.5, 2]-sigma.

  • ax (~matplotlib.axes.Axes, optional) – An ~matplotlib.axes.axes instance on which to add the 2-D histogram. If not provided, a figure will be generated.

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

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

  • plot_density (bool, optional) – Whether to draw the density colormap. Default is True.

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

  • no_fill_contours (bool, optional) – 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, optional) – 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.