sheap.Utils.Paper module

Docstring for sheap.Utils.Paper

This requiere alot of cleaning

log10_to_linear(logval, logerr)[source]

Convert log10(x) with uncertainty to linear x with asymmetric errors.

Parameters:
  • logval (float or ndarray) – log10(x)

  • logerr (float or ndarray) – 1-sigma uncertainty in log10 space

Returns:

  • val (ndarray) – Linear value x

  • err_minus (ndarray) – Lower uncertainty (x - x_low)

  • err_plus (ndarray) – Upper uncertainty (x_high - x)

median_with_errors(x, low=0.16, high=0.84, ignore_nan=True, axis=None)[source]

Return median and asymmetric percentile errors.

Parameters:
  • x (array-like) – Input values.

  • low (float, optional) – Lower quantile. Default is 0.16.

  • high (float, optional) – Upper quantile. Default is 0.84.

  • ignore_nan (bool, optional) – If True, ignore NaN values.

  • axis (int or None, optional) – Axis along which to compute the percentiles.

Returns:

  • p_med (float or ndarray) – Median.

  • err_low (float or ndarray) – Median minus lower percentile.

  • err_high (float or ndarray) – Upper percentile minus median.

posterior_extraction(sheapspectral, posterior_idx=1, extra_key='extra_combined_params', method='montecarlo', low=0.16, high=0.84)[source]
Parameters:
  • posterior_idx (int)

  • extra_key (str)

Return type:

pandas.DataFrame

mad_std(x)[source]
median_abs_deviation(a)[source]
concordance_ccc(x, y)[source]
band_stats(x, y, band=0.3)[source]
summarize(name, S)[source]
concordance_corrcoef(x, y)[source]
agreement_stats(x, y, ci=True, n_boot=5000, rng=None)[source]

Bias, robust scatter, CCC, and fractions within common dex windows.

errors_to_logspace(vals, err_minus, err_plus, *, fill_value=0.30103)[source]

Convert linear errors on vals to log10-space errors.

If the log-error is undefined (e.g. v - err_minus <= 0), replace NaN with a conservative 100% error (log10(2) ≈ 0.301 dex).

Parameters:
  • vals (array-like) – Central values (linear space).

  • err_minus (array-like) – Lower and upper 1-sigma errors (linear space).

  • err_plus (array-like) – Lower and upper 1-sigma errors (linear space).

  • fill_value (float, optional) – Replacement value in log10-space for invalid errors. Default is log10(2) ≈ 0.301 dex.

Returns:

err_minus_log, err_plus_log – Log10-space asymmetric errors.

Return type:

ndarray

weighted_quantile(x, w, q)[source]
weighted_median(x, w)[source]
weighted_nmad(x, w)[source]
plot_ratio_with_sn(x, y, xerr_low=None, xerr_up=None, yerr_low=None, yerr_up=None, sn=None, *, lims=(-0.1, 1.1), label_template='', cmap='viridis', ms=70, alpha=0.8, label_colorbar='$\\log_{10}~\\mathrm{S/N}$', xlabel='$\\mathrm{Stars/Cont.~ratio~at~5100~\\AA~(Bernal+2025)}$', ylabel='$\\mathrm{Stars/Cont.~ratio~at~5100~\\AA~(SHEAP)}$', err_alpha=0.65, err_lw=1.2, capsize=2)[source]

Plot y vs x with asymmetric errorbars and encode S/N as point color.

This version draws per-point errorbars with the same color as the marker.

Parameters:
  • x (array-like, shape (N,)) – Values to plot (e.g. Bernal+2025 vs SHEAP).

  • y (array-like, shape (N,)) – Values to plot (e.g. Bernal+2025 vs SHEAP).

  • xerr_low (array-like, shape (N,), optional) – Asymmetric errors. If provided, they are used as [low, up].

  • xerr_up (array-like, shape (N,), optional) – Asymmetric errors. If provided, they are used as [low, up].

  • yerr_low (array-like, shape (N,), optional) – Asymmetric errors. If provided, they are used as [low, up].

  • yerr_up (array-like, shape (N,), optional) – Asymmetric errors. If provided, they are used as [low, up].

  • sn (array-like, shape (N,)) – Per-point S/N values (already in log10 if you want log10 on the colorbar).

extract_data(arr)[source]

Return (values, err_minus, err_plus) in linear space. err_minus/err_plus are positive magnitudes, or None.

plot_ratio_histogram(ratio, *, bins=30, range=None, figsize=(8, 6), color='steelblue', edgecolor='black', alpha=0.8, linewidth=1.2, label=None, xlabel=None, ylabel='Number of objects', title=None, legend=True, legend_fontsize=14, label_fontsize=16, tick_fontsize=14, add_median_value=False, median_linestyle='--', median_color='k', median_linewidth=1.8, legend_loc='best', ylim=None, xlim=None)[source]

Plot a histogram for a ratio distribution with optional median marker.

plot_logdex_agreement(data_dict, sn=None, xlabel='$\\log_{10}(\\mathrm{FWHM}_{\\mathrm{ref}}\\ [\\mathrm{km\\ s^{-1}}])$', ylabel='$\\log_{10}(\\mathrm{FWHM}_{\\mathrm{SHEAP}}\\ [\\mathrm{km\\ s^{-1}}])$', label_colorbar='$\\log_{10}\\,\\mathrm{S/N}$', ref_label='ref', band=0.3, lims='auto', lims_pad=0.05, save_file=None, dpi=300, save_format='pdf', markers=('o', 's', 'X', 'D', '^', 'v', 'P', '*'), colors=('#000000', '#fd04046c', '#2ca02c', '#d62728', '#6b67bd', '#8c564b', '#e377c2', '#7f7f7f'), markersize=10, legend_fontsize=30, label_fontsize=30, tick_fontsize=30, what='', label_mode=None, add_numbers=False, name_line='line', legend_loc='lower right', cmap='viridis', colorbar=True, colorbar_pad=0.08, colorbar_size='4%', alpha=0.9, err_alpha=1.0, err_lw=1.0, capsize=3, ref_wavelenght=3000, markeredgewidth=0.5, text=None, ref_work=None, remove_scater_legend=False, vmax=None, vmin=None)[source]

?

compare_xy_stats(x_arr, y_arr, *, transform='log10', outlier_thresh=0.3, require_finite_errors_for_z=False)[source]

Compute comparison stats between x and y given arrays shaped (k,N) where k in {1,2,3}.

Returns a dict with:

N, bias_median, scatter_nmad, mean, std, frac_within_thresh, frac_outliers, z_mean, z_std, z_n (normalized residuals count), plus some helpful diagnostics.

compare_from_data_dict(data_dict, *, transform='log10', outlier_thresh=0.3)[source]
data_dict format:
{

“Label A”: {“x”: (k,N), “y”: (k,N)}, “Label B”: {“x”: …, “y”: …},

}

Returns dict of stats per label.

summary_similarity(info, *, name=None, decimals=3)[source]

Summarize similarity between two methods using robust, interpretable stats.

Expected keys:
  • n_tot, band, frac_within, bias_med, scatter_nmad

Optional:
  • mean, std

bins_centered_on_zero(x, nbins=60, clip=None)[source]
compare_res(dictionaries, labels, main_key='Values Bernal+25', compared_xlabel='None', save_file=None)[source]
add_colorbar_from_dict(ax, colorbar_dict)[source]

Recreate a colorbar from a saved dictionary.

Parameters:
  • ax (matplotlib.axes.Axes) – Axis where the colorbar will be attached.

  • colorbar_dict (dict) – Dictionary with colorbar configuration.

Returns:

cbar – The created colorbar, or None if not used.

Return type:

matplotlib.colorbar.Colorbar or None

plot_main_plot_panel(main_plot_dict, ax=None, panel_title=None, tick_labelsize=None, legend_fontsize=None, label_fontsize=None)[source]

Plot one agreement panel from a stats_host[“main_plot”] dictionary.

Parameters:
  • main_plot_dict (dict) – Dictionary with the structure of stats_host[“main_plot”].

  • ax (matplotlib.axes.Axes, optional) – Axis where the panel will be drawn. If None, a new figure/axis is created.

  • panel_title (str, optional) – Title for the panel.

Returns:

ax – Axis with the plot.

Return type:

matplotlib.axes.Axes

plot_main_plot_subplots(main_plot_list, titles=None, ncols=2, figsize_per_panel=(8, 8), sharex=False, sharey=False, tick_labelsize=None, legend_fontsize=None, label_fontsize=None, wspace=None, hspace=None, left=None, right=None, top=None, bottom=None)[source]

Plot multiple stats_host[“main_plot”] dictionaries as subplots.

Parameters:
  • main_plot_list (list of dict) – List where each element is a stats_host[“main_plot”] dictionary.

  • titles (list of str, optional) – Titles for each subplot.

  • ncols (int, optional) – Number of columns in subplot grid.

  • figsize_per_panel (tuple, optional) – Size (width, height) per panel.

  • sharex (bool, optional) – Whether to share x axis.

  • sharey (bool, optional) – Whether to share y axis.

  • tick_labelsize (float, optional) – Tick label font size.

  • legend_fontsize (float, optional) – Legend font size.

  • label_fontsize (float, optional) – Axis label font size.

  • wspace (float, optional) – Width spacing between subplots.

  • hspace (float, optional) – Height spacing between subplots.

  • left (float, optional) – Margins for subplot layout.

  • right (float, optional) – Margins for subplot layout.

  • top (float, optional) – Margins for subplot layout.

  • bottom (float, optional) – Margins for subplot layout.

Returns:

  • fig (matplotlib.figure.Figure) – Figure object.

  • axes (numpy.ndarray) – Array of axes.