Source code for GUIBRUSHR.General_Constants.FunctionsAndConstants.general_functions

"""
General utility functions for GUIBRUSHR atmospheric retrieval analysis.

This module re-exports functions from the new core/functions/ package for
backward compatibility. New code should import directly from the specific
submodules in GUIBRUSHR.core.functions instead.

Submodules:
    - core.functions.spectroscopy: Convolution, rotational broadening, mass calculations
    - core.functions.io_utils: FITS I/O, CSV handling, stellar spectrum management
    - core.functions.plotting: Colormaps, T-P profiles, VMR plots, contribution plots
    - core.functions.pca: PCA-based detrending
    - core.functions.cross_correlation: Radial velocity calculations
    - core.functions.statistics: MCMC statistics, transit durations, linear algebra
"""

from typing import Optional, Tuple

# ---------------------------------------------------------------------------
# Re-exports from core/functions (backward compatibility)
# ---------------------------------------------------------------------------

# Spectroscopy
from GUIBRUSHR.core.functions.spectroscopy import (
    kernel_solid_body_rotation,
    convolve_solid_body_rotation,
    convolve_resolution,
    calculate_mass_molecule,
    generate_chemcat,
    estimate_continuum,
    skewed_gaussian,
    compute_adjusted_abundance,
    spectral_convolution_ptr,
)

# I/O utilities
from GUIBRUSHR.core.functions.io_utils import (
    make_pyratbay_config,
    create_fits,
    create_path_night,
    get_csv_value,
    get_condensed_line_list,
    get_line_lists,
    read_fits,
    get_depth_filename,
    read_depth_fits,
    get_stellar_model,
    generate_star_model_hr,
    download_star_spectrum,
)

# Plotting
from GUIBRUSHR.core.functions.plotting import (
    make_smooth_mono_cmap,
    plot_tp_profile,
    plot_corner_metallicity,
    opacities_contribution_plot,
    plot_vmr,
)

# PCA
from GUIBRUSHR.core.functions.pca import trpca, linear_solver

# Cross-correlation
from GUIBRUSHR.core.functions.cross_correlation import (
    rv_planet_and_star,
    calculate_rv_planet_and_star,
    rv_DopplerShadow,
)

# Statistics and MCMC
from GUIBRUSHR.core.functions.statistics import (
    get_medians,
    pre_plot,
    get_keys_by_value,
    compute_transit_durations,
)

# ---------------------------------------------------------------------------
# GUI function — stays here (opens Tkinter dialog)
# ---------------------------------------------------------------------------
from GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameGenerationHRData.StellarDialog import StellarDialog


[docs] def ask_stellar_params(parent=None, stellar_teff: Optional[float] = None) -> Tuple[Optional[float], Optional[float], Optional[float]]: """ Open stellar parameter dialog and return user-specified stellar properties. This convenience function creates and displays a modal dialog for entering stellar atmospheric parameters needed for synthetic spectrum generation. The dialog allows input of effective temperature, surface gravity, and metallicity with validation and reasonable defaults. Parameters ---------- parent : tk.Misc or None, optional Parent widget for the dialog. If None, uses default root window or creates a new Tk instance, by default None stellar_teff : float or None, optional Initial effective temperature value to populate in the dialog, by default None Returns ------- tuple[float or None, float or None, float or None] Tuple containing stellar parameters: - T_eff : Effective temperature in Kelvin (rounded to 5 digits) - log_g : Surface gravity in cgs units (log10(g)) - Fe_H : Metallicity [Fe/H] in dex Returns (None, None, None) if user cancels or closes dialog Notes ----- The stellar parameters are used to select appropriate stellar atmosphere models for synthetic spectrum generation. The dialog provides validation to ensure physically reasonable values are entered. """ import tkinter as tk if parent is None: parent = tk._default_root or tk.Tk() dialog = StellarDialog(parent, stellar_teff) return getattr(dialog, "result", (None, None, None))