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)
- 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
- 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
- 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.