GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution module

Module for plotting atmospheric model contributions and spectra.

This module provides functions to generate high-resolution and low-resolution plots of atmospheric models, including contribution functions and spectral data visualization with observational data comparison.

The module supports two main workflows: 1. Single model plotting - plots from best-fit parameters 2. Multi-model plotting - plots with confidence intervals from MCMC samples

Main Functions:
  • high_resolution_plot: Standard HR spectrum plot from single model

  • plot_envelope_model_HR: HR spectrum plot with confidence intervals

  • low_resolution_plot: Standard LR spectrum plot from single model

  • plot_envelope_model_LR: LR spectrum plot with confidence intervals

  • plot_contribution: Contribution function contour plots

  • main: Command-line entry point for plotting operations

Helper Functions:
  • _save_fits_file: Save numpy array to FITS file

  • _add_file_path_annotations: Add file path text to plot

  • _configure_wavelength_scale: Set wavelength axis scale (log/linear)

  • load_contribution_data: Load analysis parameters from pickle

  • save_model_outputs: Save model results to pickle files

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.high_resolution_plot(folder_retrieval, overplot, ylabel, wlen_list_overplot, not_retrieval_objf, rad_modef, wl_scalef)[source]

Generate high-resolution model spectrum plot from a single model.

Creates plots showing the full resolution atmospheric model spectrum, with optional overplotting of selected wavelength orders. This function is used when plotting a single best-fit model (not MCMC samples).

The function performs three main tasks: 1. Saves wavelength and spectrum data to FITS files 2. Creates a high-resolution plot with optional order highlighting 3. Saves the plot in multiple formats (PNG, PDF)

Parameters:
  • folder_retrieval (str) – Path to the retrieval folder

  • overplot (bool) – Flag indicating whether to overplot selected wavelength orders

  • ylabel (str) – Y-axis label for the spectrum

  • wlen_list_overplot (list) – List of wavelength arrays for highlighting specific orders

  • not_retrieval_objf – Model object containing spectrum data with attributes: - wl_full_resolution_HR: High-resolution wavelength array (nm) - depth_full_resolution_HR: High-resolution spectrum values

  • rad_modef (str) – Radiation mode (e.g., ‘Transmission’, ‘Emission’)

  • wl_scalef (str) – Wavelength scale - ‘log’ for logarithmic, otherwise linear

Output Files:
  • wavelength_HR.fits: High-resolution wavelength data

  • transit_depth_HR.fits: High-resolution spectrum data

  • high_res.pdf: Plot in PDF format

  • high_res.png: Plot in PNG format

  • model_high_low_res.png: Temporary plot file

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.plot_envelope_model_HR(folder_retrieval, wlen_hr, all_spectra_hr, ylabel, rad_mode, wl_scalef)[source]

Generate high-resolution spectrum plot with confidence intervals from MCMC samples.

Creates a plot showing the median model spectrum with 68% and 95% credible regions from multiple model realizations. This function is used when plotting results from MCMC sampling (multiple models) rather than a single best-fit model.

The function performs three main tasks: 1. Calculates median and percentiles from all model spectra 2. Saves median wavelength and spectrum data to FITS files 3. Creates a plot with confidence interval bands

Parameters:
  • folder_retrieval (str) – Path to the retrieval folder

  • wlen_hr (np.ndarray) – High-resolution wavelength array (nm), shape (n_wavelengths,)

  • all_spectra_hr (np.ndarray) – 2D array of spectra, shape (n_models, n_wavelengths)

  • ylabel (str) – Y-axis label for the spectrum

  • rad_mode (str) – Radiation mode (e.g., ‘Transmission’, ‘Emission’)

  • wl_scalef (str) – Wavelength scale - ‘log’ for logarithmic, otherwise linear

Output Files:
  • wavelength_HR.fits: High-resolution wavelength data

  • transit_depth_HR.fits: Median high-resolution spectrum

  • high_res.pdf: Plot in PDF format

  • high_res.png: Plot in PNG format

  • model_high_low_res.png: Temporary plot file

Note

The FITS files contain the median spectrum (50th percentile) rather than a single model realization.

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.low_resolution_plot(path_imm, not_retrieval_obj_f, instruments_LR, wl_scalef, ylabel)[source]
GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.plot_contribution(folder_retrieval, rad_mode, model_obj, wlen_mu_contribution, contribution_data, pressures, range_min_pressures, range_max_pressures, resolution, wl_scalef)[source]

Generate atmospheric contribution function contour plots.

Creates 2D contour plots showing how different atmospheric pressure layers contribute to the observed spectrum as a function of wavelength. This is a diagnostic tool to understand which atmospheric layers are being probed at different wavelengths.

The contribution function shows where in the atmosphere (at which pressure) photons are being absorbed or emitted for a given wavelength. High values indicate strong contribution from that layer.

Parameters:
  • folder_retrieval (str) – Path to the retrieval folder

  • rad_mode (str) – Radiative transfer mode (‘Transmission’ or ‘Emission’)

  • model_obj – Main model object containing atmosphere data with attributes: - atmosphere.pressure_data.pressures: Pressure grid (bar)

  • wlen_mu_contribution (np.ndarray) – Wavelength array in microns, shape (n_wavelengths,)

  • contribution_data (np.ndarray) – 2D contribution values, shape (n_pressures, n_wavelengths)

  • pressures (np.ndarray) – Pressure array in bars, shape (n_pressures,)

  • range_min_pressures (float) – Minimum pressure range in log10(bar)

  • range_max_pressures (float) – Maximum pressure range in log10(bar)

  • resolution (str) – Resolution identifier - ‘HR’ (high-res) or ‘LR’ (low-res)

  • wl_scalef (str) – Wavelength scale - ‘log’ for logarithmic, otherwise linear

Output Files:

In folder {folder_retrieval}/contribution/: - contribution_{resolution}.pdf/png: Contour plots - X_meshgrid_contribution_{resolution}.fits: Wavelength meshgrid - Y_meshgrid_contribution_{resolution}.fits: Pressure meshgrid - wlen_mu_contribution_{resolution}.fits: Wavelength array - pressures_contribution_{resolution}.fits: Pressure array - atmosphere.contr_tr_{resolution}.fits: Contribution function data

Notes

  • Y-axis (pressure) is always logarithmic

  • Colormap: ‘gnuplot2_r’ (reversed gnuplot2)

  • 30 contour levels are used for smooth visualization

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.load_contribution_data(folder_retrieval)[source]

Load contribution analysis configuration from pickle file.

Reads the analysis parameters that were saved by the GUI before launching the plotting script. These parameters control the model calculation and plotting behavior.

Parameters:

folder_retrieval (str) – Path to the retrieval folder containing ‘output_data_contribution.pkl’

Returns:

Configuration parameters in the following order:
  • best_fit_parameters (np.ndarray): Best-fit or MCMC sample parameters

  • contribution (str): Contribution mode flag

  • lbl_sampling_hr (int): Line-by-line sampling parameter for HR

  • lbl_sampling_lr (int): Line-by-line sampling parameter for LR

  • range_min (float): Minimum pressure range (log scale)

  • range_max (float): Maximum pressure range (log scale)

  • n_layers (int): Number of atmospheric layers

  • aic_var: AIC variance parameter

  • overplot (bool): Whether to overplot selected orders

  • min_wl_lr (float): Minimum wavelength for low-res (nm)

  • max_wl_lr (float): Maximum wavelength for low-res (nm)

  • min_wl_hr (float): Minimum wavelength for high-res (nm)

  • max_wl_hr (float): Maximum wavelength for high-res (nm)

  • wl_scale_hr (str): Wavelength scale for HR plots (‘log’ or ‘linear’)

  • wl_scale_lr (str): Wavelength scale for LR plots (‘log’ or ‘linear’)

  • plot_opacity (bool): Whether to plot opacity data

Return type:

tuple

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.save_model_outputs(folder_retrieval, not_retrieval_obj, model_obj)[source]

Save model calculation results to pickle files for later analysis.

Exports three types of data for post-processing and analysis: 1. VMR profiles - Volume mixing ratios as a function of pressure 2. VMR summary - Mean values and mass fractions 3. Distribution data - Full model object for further analysis

These files are used by the GUI for displaying results and by other analysis scripts for post-processing.

Parameters:
  • folder_retrieval (str) – Path to the retrieval folder

  • not_retrieval_obj – Model calculation object containing: - vmr_dict: Dictionary of volume mixing ratios by species - MMW: Mean molecular weight - vmr: Volume mixing ratio array - mass_fraction_names_lr/hr: Species names for mass fractions - mean_VMR_and_MF_string/dict: Summary statistics

  • model_obj – Main model object with atmosphere data containing: - atmosphere.pressure_data.pressures: Pressure grid - atmosphere.resolution_obj.instruments_LR: Low-res instruments

Output Files:
  • vmr_profile.pkl: VMR profiles vs pressure

  • vmr.pkl: Mean VMR values and mass fractions

  • distribution.pkl: Complete model object and instrument data

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.plot_envelope_model_LR(wlen_nm, all_spectra, all_binned_spectra, datasets_lr, ylabel, wl_scalef, path_imm)[source]

Generate low-resolution spectrum plot with confidence intervals from MCMC samples.

Creates plots showing the median model spectrum with 68% and 95% credible regions from multiple model realizations, along with observational data and residuals. Similar to plot_envelope_model_HR but includes data comparison and residual panels.

The function creates two separate plots: 1. Regular flux plot (for non-normalized instruments) 2. Normalized flux plot (for normalized instruments)

Each plot has two panels: - Upper: Model confidence intervals with observational data points - Lower: Residuals (data - median binned model)

Parameters:
  • wlen_nm (np.ndarray) – Wavelength array in nm, shape (n_wavelengths,)

  • all_spectra (np.ndarray) – 2D array of full-resolution spectra, shape (n_models, n_wavelengths)

  • all_binned_spectra (list) – List of dictionaries, one per model, each containing binned spectra for each instrument (key: instrument name, value: binned spectrum)

  • datasets_lr (dict) – Dictionary of observational data, keyed by instrument name, each containing: - ldata: Wavelength data points - rdata: Flux data (offset-corrected) - errdata: Flux uncertainties - step: Wavelength bin width - flux_norm: Boolean indicating if flux is normalized

  • ylabel (str) – Y-axis label for the spectrum

  • wl_scalef (str) – Wavelength scale - ‘log’ for logarithmic, otherwise linear

  • path_imm (str) – Output path for the main plot (PNG format)

Output Files:
  • {path_imm}: Main plot (regular flux) in PNG format

  • {path_imm}.pdf: Main plot in PDF format

  • {path_imm}_normalized.png: Normalized flux plot (if applicable)

  • {path_imm}_normalized.pdf: Normalized flux plot PDF (if applicable)

Color Scheme:
  • Light orange (#fdc086): 95% credible region

  • Orange (#ff7f00): 68% credible region

  • Dark orange (#8c2d04): Median model line

  • Various colors for different instruments’ data points

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.Frame_Retrieval_Analysis.Tab_Analysis.Frame_Model_Plot.plot_contribution.main()[source]

Main entry point for atmospheric model plotting script.

This script is called by the GUIBRUSHR GUI after a retrieval analysis has completed. It generates various types of plots depending on the analysis configuration:

  1. Single Model Mode (best-fit parameters): - High-resolution spectrum plot (if HR data available) - Low-resolution spectrum plot with data comparison (if LR data available) - Contribution function plots (if requested)

  2. Multi-Model Mode (MCMC samples): - High-resolution spectrum with confidence intervals - Low-resolution spectrum with confidence intervals and data comparison

The script automatically determines which plots to generate based on: - Resolution mode (HR, LR, or both) - Contribution function flag - Number of parameter sets (single vs multiple models)

Command Line Usage:

python plot_contribution.py <folder_retrieval> <target> <path_default>

Args (from command line):

sys.argv[1] - folder_retrieval: Path to retrieval results folder sys.argv[2] - target: Target name (currently unused in code) sys.argv[3] - path_default: Default path for GUIBRUSHR modules

Input Files (in folder_retrieval):
  • output_data_contribution.pkl: Analysis configuration

  • df_general_info.csv: General retrieval information

  • df_parameters.csv: Parameter definitions

Output:

Various plots and FITS files (see individual plotting functions) error_log_model.pkl: Error log (None if successful)

Workflow:
  1. Load configuration from pickle file

  2. Initialize ModelData object with appropriate settings

  3. Determine if single model or multi-model mode

  4. Generate appropriate plots for each resolution

  5. Save results and error log