coplot.plot_contours

class coplot.plot_contours.Chains[source]

Bases: object

static bestFit(chain, best_type='mode', out_sigma=1, symmetry_error=True)[source]

Get the best-fit parameters from the chain.

Parameters:
  • chain (array-like) – The ANN chain.
  • best_type (str, optional) – The type of the best values of parameters, ‘mode’ or ‘median’. If ‘mode’, it will take the mode as the best value. If ‘median’, it will take the median as the best value. Default: ‘mode’
  • out_sigma (int) – The output sigma, which can be 1, 2, or 3. Default: 1
  • symmetry_error (bool, optional) – If True, obtain symmetrical errors, otherwise, obtain unsymmetrical errors. Default: True
static best_median(chain)[source]

Take the median as the best value.

static best_mode(chain, bins=100, smooth=5)[source]

Take the mode as the best value.

static error_devs(chain_1, chain_true)[source]

Get the absolute values of the relative deviations of error of parameters obtained from two chains.

static param_devs(chain_1, chain_2)[source]

Get deviations of parameters obtained from two chains.

static params_n(chain)[source]
static reshape_chain(chain)[source]
static sigma(chain, best_values, out_sigma=1)[source]

Calculate the standard deviations.

Parameters:
  • chain (array-like) – The ANN chain.
  • best_values (1-dimension array) – The best values of parameters.
  • out_sigma (int) – The output sigma, which can be 1, 2, or 3. Default: 1
Returns:

  • sigma_1l, sigma_2l, sigma_3l (1-dimension array) – The left 1 sigma, 2 sigma, or 3sigma deviations.
  • sigma_1r, sigma_2r, sigma_3r (1-dimension array) – The right 1 sigma, 2 sigma, or 3sigma deviations.

class coplot.plot_contours.Contours(data)[source]

Plot 1-D and 2-D contours for several sets of data.

plot(bins=None, labels=None, colors=None, line_styles=None, same_line_styles=True, sigma=2, smooth=3, minor_locator=True, major_locator_N=None, minor_locator_N=None, ticks_size=None, layout_adjust=None, lims=None, line_width=None, show_titles=False, title_fontsize=None, title_sigma=1, fill_contours=True, best_values=None, best_value_styles=None, best_value_colors=None, show_best_value_lines=False, legend=False, legend_labels=None, legend_size=None, equal_1d=True, pdf_method='2', subplots_adjust=True)[source]

Plot 1-D and 2-D contours for several sets of data.

Parameters:
  • bins – bins for 1-D and 2-D contours
  • labels – labels of panels
  • colors – colors of 1-D and 2-D contours
  • line_styles – lines styles of 1-D and 2-D contour for a set of data
  • same_line_styles – if True, 2-D contour have the same line styles with 1-D contours
  • sigma – contour levels, if sigma=2(3), plot with 2-sigma(3-sigma) contour levels
  • smooth – the number passed to ‘scipy.ndimage.gaussian_filter’ to smooth the probability density function
  • minor_locator – small scale of xticks and yticks
  • major_locator_N – the number of major scale of xticks and yticks
  • minor_locator_N – the number of minor locators
  • ticks_size – the size of xticklabel and yticklabel
  • layout_adjust – adjust the distance of panels
  • lims – xlim and ylim for every panels, lims=[[min_x1, min_x2,],[max_x1,max_x2,]]
  • line_width – the width of lines for 1-D contours
  • show_titles – if True(False), show(don’t show) the best fit values
  • title_fontsize – the font size of titles
  • title_sigma – show 1-sigma errors if title_sigma=1, and 2-sigma errors if title_sigma=2
  • fill_contours – fill contours with colors
  • best_values – plot the best fit value in the 2-D contour
  • best_value_styles – the styles of best values, eg: ‘o’/’^’
  • equal_1d – making the maximum of the probability density function of multiple data sets equal
  • pdf_method – ‘1’ or ‘2’, the method to estimate the probability density function for the given data, see the method pdf_1 and pdf_2
plot_1d(bins=None, labels=None, colors=None, line_styles=None, same_line_styles=True, sigma=2, smooth=3, minor_locator=True, major_locator_N=None, minor_locator_N=None, ticks_size=None, lims=None, line_width=None, best_values=None, best_value_styles=None, best_value_colors=None, show_best_value_lines=False, legend=False, legend_labels=None, legend_size=None, equal_1d=True, pdf_method='2', subplots_adjust=True, lat_n=3, panel_size=(5.0, 3.75), layout_adjust=[0.18, 0.18])[source]

lat_n: The number of panels in latitude (or transverse) direction. lon_n: The number of panels in longitude (or longitudinal) direction.

plot_2d(bins=None, labels=None, colors=None, line_styles=None, same_line_styles=True, sigma=2, smooth=2, minor_locator=True, major_locator_N=None, minor_locator_N=None, ticks_size=None, layout_adjust=None, lims=None, line_width=None, show_titles=False, title_fontsize=None, title_sigma=1, fill_contours=True, best_values=None, best_value_styles=None, best_value_colors=None, show_best_value_lines=False, legend=False, legend_labels=None, legend_size=None, equal_1d=True, pdf_method='2', subplots_adjust=True)[source]

Plot 2-D contours for several sets of data.

Parameters:
  • bins – bins for 1-D and 2-D contours
  • labels – labels of panels
  • colors – colors of 1-D and 2-D contours
  • line_styles – lines styles of 1-D and 2-D contour for a set of data
  • same_line_styles – if True, 2-D contour have the same line styles with 1-D contours
  • sigma – contour levels, if sigma=2(3), plot with 2-sigma(3-sigma) contour levels
  • smooth – the number passed to ‘scipy.ndimage.gaussian_filter’ to smooth the probability density function
  • minor_locator – small scale of xticks and yticks
  • major_locator_N – the number of major scale of xticks and yticks
  • minor_locator_N – the number of minor locators
  • ticks_size – the size of xticklabel and yticklabel
  • layout_adjust – adjust the distance of panels
  • lims – xlim and ylim for every panels, lims=[[min_x1, min_x2,],[max_x1,max_x2,]]
  • line_width – the width of lines for 1-D contours
  • show_titles – if True(False), show(don’t show) the best fit values
  • title_fontsize – the font size of titles
  • title_sigma – show 1-sigma errors if title_sigma=1, and 2-sigma errors if title_sigma=2
  • fill_contours – fill contours with colors
  • best_values – plot the best fit value in the 2-D contour
  • best_value_styles – the styles of best values, eg: ‘o’/’^’
  • equal_1d – making the maximum of the probability density function of multiple data sets equal
  • pdf_method – ‘1’ or ‘2’, the method to estimate the probability density function for the given data, see the method pdf_1 and pdf_2
class coplot.plot_contours.Plot_1d(data)[source]

Plot 1-dimensional distribution of parameters.

plot(bins=100, smooth=3, x_lims=None, colors=None, line_styles=None, line_width=None, labels=None, ticks_size=None, major_locator_N=None, minor_locator=True, minor_locator_N=None, legend=False, legend_labels=None, legend_size=None, legend_loc=None, equal_1d=True, pdf_method='2', fig_size=None, show_title=False, title_fontsize=None, title_sigma=1)[source]

plot the probability density function (PDF)

Parameters:
  • bins – the number of bins
  • smooth – the number passed to ‘scipy.ndimage.gaussian_filter’ to smooth the probability density function.
  • colors – the colors of lines
  • line_styles – the styles of lines
  • line_width – the width of lines
  • labels – the labels of panels
  • ticks_size – the size of ticks
  • major_locator_N – the number of major locators
  • minor_locator – if True(False), show the minor locators
  • minor_locator_N – the number of minor locators
  • equal_1d – making the maximum of the probability density function of multiple data sets equal
  • pdf_method – ‘1’ or ‘2’, the method to estimate the probability density function for the given data, see the method pdf_1 and pdf_2
  • show_title – if True(False), show(don’t show) the best fit values
  • title_fontsize – the font size of titles
  • title_sigma – show 1-sigma errors if title_sigma=1, and 2-sigma errors if title_sigma=2
reshape_chain(chain)[source]
class coplot.plot_contours.Plot_2d(data)[source]

Plot 2-dimensional distribution of parameters.

plot(sigma=2, bins=None, smooth=3, lims=None, colors=None, line_styles=None, line_width=None, labels=None, best_values=None, best_values_styles=None, ticks_size=None, major_locator_N=None, minor_locator=True, minor_locator_N=None, fill_contours=True, legend=False, legend_labels=None, legend_size=None, legend_loc=None, bbox_to_anchor=(1, 1), show_title=False, title_fontsize=None, title_sigma=1, fig_size=None, output_ax=False)[source]

plot 2-D contours

Parameters:
  • sigma – contour levels, if sigma=2(3), plot with 2-sigma(3-sigma) contour levels
  • bins – the number of bins
  • smooth – the number passed to ‘scipy.ndimage.gaussian_filter’ to smooth the probability density function.
  • colors – the colors of lines
  • line_styles – the styles of lines
  • line_width – the width of lines
  • labels – labels of the panel
  • best_values – the best fit values
  • best_value_styles – the styles of best fit values
  • ticks_size – the size of ticks
  • major_locator_N – the number of major locators
  • minor_locator – if True(False), show the minor locators
  • minor_locator_N – the number of minor locators
  • show_title – if True(False), show(don’t show) the best fit values
  • title_fontsize – the font size of titles
  • title_sigma – show 1-sigma errors if title_sigma=1, and 2-sigma errors if title_sigma=2
coplot.plot_contours.best_params(chains, best_values=None, chi2=None, bins=None, N_decimal=6, print_info=True, sigma=1)[source]
Parameters:
  • chains – The mcmc results
  • best_values – The best values for parameters, 1 dimension array
  • bins – The bins for calculate the best values by using “find_best_para”
  • N_decimal – The number of decimal -> this parameter is not used
Returns:

the best fit values with 1-sigma error

coplot.plot_contours.find_best_para(para_trace, bins)[source]

find the best parameter and its 1-sigma/2-sigma for (non) Gaussian distribution

coplot.plot_contours.find_best_para2(para_trace, bins)[source]
coplot.plot_contours.find_best_para_plt(para_trace, bins)[source]
coplot.plot_contours.get_best_params(chain)[source]

this function is used to get the best-fit parameters calculated with best_params

return: the best-fit values of parameters in numpy array

coplot.plot_contours.params_deviation(chain_2, chain_1)[source]

get deviation of parameters in two chains

coplot.plot_contours.pdf_1(X, bins, smooth)[source]

estimate the probability density function for the given data

coplot.plot_contours.pdf_2(X, smooth)[source]

the same as pdf_1, but using different method

coplot.plot_contours.remove_unreliableData(data, filter_N=0)[source]

remove unreliable data, eg: very large or small data for a simulated distribution

Parameters:
  • data – the input data, one-dimension or multi-dimension array
  • filter_N – a number, the column that was chosen to filter

Note: the selection interval is [best_fit-3*sigma_3l, best_fit+3*sigma_3r]