GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl module

Generate correlated-k opacity files from petitRADTRANS line-by-line files.

This script converts high-resolution line-by-line opacity files to correlated-k format using the official petitRADTRANS correlated-k algorithm. This method is more accurate than simple Gaussian convolution because it preserves the statistical distribution of opacities within each spectral bin.

Usage:

python generate_correlated_k_from_lbl.py –input-file <path> –resolution <R>

Arguments:
--input-file

Path to line-by-line opacity HDF5 file

--resolution

Target resolving power (default: 20000)

--no-plots

Skip diagnostic plot generation

--rewrite

Overwrite existing output files

Author: Francesco / GUIBRUSHR Team Date: 2026-01-14

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.write_correlated_k(file, doi, wavenumbers, wavenumbers_bins_edges, cross_sections, mol_mass, species, opacities_pressures, opacities_temperatures, g_gauss, weights_gauss, wavelengths=None, n_g=None, contributor=None, description=None)[source]
class GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.Config[source]

Bases: object

Configuration parameters for correlated-k generation.

INPUT_FILE = '/home/francesco/petitRADTRANS/input_data/opacities/lines/line_by_line/H2O/1H2-16O/1H2-16O__POKAZATEL.R1e6_0.3-28mu.xsec.petitRADTRANS.h5'
R_TARGET = 20000
G_SAMPLES = array([0.01786956, 0.09150009, 0.21351042, 0.36745441, 0.53254559,        0.68648958, 0.80849991, 0.88213044, 0.90198551, 0.91016668,        0.92372338, 0.94082827, 0.95917173, 0.97627662, 0.98983332,        0.99801449])
G_WEIGHTS = array([0.04555284, 0.10007147, 0.14116799, 0.1632077 , 0.1632077 ,        0.14116799, 0.10007147, 0.04555284, 0.00506143, 0.01111905,        0.01568533, 0.01813419, 0.01813419, 0.01568533, 0.01111905,        0.00506143])
DOI = 'Converted from line-by-line using correlated-k method'
CONTRIBUTOR = 'GUIBRUSHR Team'
DESCRIPTION = 'Correlated-k opacities at R=20000 generated from high-resolution line-by-line data'
USE_LEGACY_MODE = False
REWRITE = True
MAKE_PLOTS = True
GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.load_line_by_line_file(filepath: str) dict[source]

Load line-by-line opacity data from petitRADTRANS HDF5 file.

Parameters:

filepath (str) – Path to the input HDF5 file

Returns:

Dictionary containing: - pressures: Pressure grid (bar) - temperatures: Temperature grid (K) - wavenumbers: Wavenumber bin edges (cm^-1) - cross_sections: Cross-section array (n_p, n_t, n_wn) in cm^2/molecule - mol_mass: Molecular mass (AMU) - mol_name: Molecule name - wlrange: Wavelength range (μm) - wnrange: Wavenumber range (cm^-1)

Return type:

dict

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.write_correlated_k_file(filepath: str, wavenumbers_centers: ndarray, wavenumbers_edges: ndarray, cross_sections: ndarray, pressures: ndarray, temperatures: ndarray, mol_mass: float, mol_name: str, g_samples: ndarray, g_weights: ndarray, doi: str, contributor: str | None = None, description: str | None = None)[source]

Write correlated-k opacity file in petitRADTRANS format.

This follows the exact structure of petitRADTRANS write_correlated_k function.

Parameters:
  • filepath (str) – Output file path

  • wavenumbers_centers (np.ndarray) – Center wavenumbers of bins (cm^-1)

  • wavenumbers_edges (np.ndarray) – Edge wavenumbers of bins (cm^-1)

  • cross_sections (np.ndarray) – Correlated-k coefficients (n_p, n_t, n_wn, n_g) in cm^2/molecule

  • pressures (np.ndarray) – Pressure grid (bar)

  • temperatures (np.ndarray) – Temperature grid (K)

  • mol_mass (float) – Molecular mass (AMU)

  • mol_name (str) – Molecule name

  • g_samples (np.ndarray) – G-space sample points

  • g_weights (np.ndarray) – G-space quadrature weights

  • doi (str) – Data identifier or DOI

  • contributor (str, optional) – Contributor name

  • description (str, optional) – Additional description

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.compute_resolving_power(wavenumbers: ndarray) float[source]

Compute the mean resolving power of a wavenumber grid.

Parameters:

wavenumbers (np.ndarray) – Wavenumber array (cm^-1)

Returns:

Mean resolving power R = ν/Δν

Return type:

float

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.create_correlated_k_grid(wavenumbers_input: ndarray, R_input: float, R_target: float, use_legacy_mode: bool = False) tuple[ndarray, ndarray][source]

Create wavenumber grid for correlated-k at target resolution.

This follows the exact algorithm from petitRADTRANS format2petitradtrans.

Parameters:
  • wavenumbers_input (np.ndarray) – Input wavenumber grid (cm^-1), must be in increasing order

  • R_input (float) – Input resolving power

  • R_target (float) – Target resolving power

  • use_legacy_mode (bool) – Use legacy (pRT v2) wavenumber sampling

Returns:

  • bin_edges (np.ndarray) – Wavenumber bin edges (cm^-1)

  • bin_centers (np.ndarray) – Wavenumber bin centers (cm^-1)

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.compute_correlated_k_coefficients(cross_sections: ndarray, wavenumbers: ndarray, bin_edges: ndarray, g_samples: ndarray) ndarray[source]

Compute correlated-k coefficients from line-by-line cross-sections.

This implements the exact algorithm from petitRADTRANS format2petitradtrans. For each spectral bin: 1. Select cross-sections in that bin 2. Sort them in increasing order 3. Divide into g-space intervals 4. Average within each g interval

Parameters:
  • cross_sections (np.ndarray) – Line-by-line cross-sections (n_p, n_t, n_wn) in cm^2/molecule

  • wavenumbers (np.ndarray) – Wavenumber grid (cm^-1)

  • bin_edges (np.ndarray) – Correlated-k bin edges (cm^-1)

  • g_samples (np.ndarray) – G-space sample points

Returns:

Correlated-k coefficients (n_p, n_t, n_bins, n_g) in cm^2/molecule

Return type:

np.ndarray

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.plot_resolution_check(bin_centers: ndarray, R_target: float, output_dir: Path, mol_name: str)[source]

Plot resolving power vs wavenumber to verify target resolution.

Parameters:
  • bin_centers (np.ndarray) – Wavenumber bin centers (cm^-1)

  • R_target (float) – Target resolving power

  • output_dir (Path) – Directory to save plot

  • mol_name (str) – Molecule name for title

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.plot_g_space_distribution(correlated_k: ndarray, bin_centers: ndarray, g_samples: ndarray, g_weights: ndarray, pressures: ndarray, temperatures: ndarray, output_dir: Path, mol_name: str, n_bins_to_plot: int = 6)[source]

Plot g-space distribution for selected spectral bins.

Shows how opacities are distributed across g-space for different bins.

Parameters:
  • correlated_k (np.ndarray) – Correlated-k coefficients (n_p, n_t, n_bins, n_g)

  • bin_centers (np.ndarray) – Wavenumber bin centers (cm^-1)

  • g_samples (np.ndarray) – G-space sample points

  • g_weights (np.ndarray) – G-space weights

  • pressures (np.ndarray) – Pressure grid (bar)

  • temperatures (np.ndarray) – Temperature grid (K)

  • output_dir (Path) – Directory to save plot

  • mol_name (str) – Molecule name

  • n_bins_to_plot (int) – Number of spectral bins to plot

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.plot_lbl_vs_ck_comparison(cross_sections_lbl: ndarray, correlated_k: ndarray, wavenumbers_lbl: ndarray, bin_centers_ck: ndarray, bin_edges_ck: ndarray, g_weights: ndarray, pressures: ndarray, temperatures: ndarray, output_dir: Path, mol_name: str, R_input: float, R_target: float)[source]

Compare line-by-line and correlated-k opacities.

Reconstructs spectrum from correlated-k and compares with original line-by-line.

Parameters:
  • cross_sections_lbl (np.ndarray) – Line-by-line cross-sections (n_p, n_t, n_wn)

  • correlated_k (np.ndarray) – Correlated-k coefficients (n_p, n_t, n_bins, n_g)

  • wavenumbers_lbl (np.ndarray) – Line-by-line wavenumbers (cm^-1)

  • bin_centers_ck (np.ndarray) – Correlated-k bin centers (cm^-1)

  • bin_edges_ck (np.ndarray) – Correlated-k bin edges (cm^-1)

  • g_weights (np.ndarray) – G-space weights

  • pressures (np.ndarray) – Pressure grid (bar)

  • temperatures (np.ndarray) – Temperature grid (K)

  • output_dir (Path) – Directory to save plot

  • mol_name (str) – Molecule name

  • R_input (float) – Input resolution

  • R_target (float) – Target resolution

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.plot_pt_grid_heatmap(correlated_k: ndarray, bin_centers: ndarray, pressures: ndarray, temperatures: ndarray, g_weights: ndarray, output_dir: Path, mol_name: str)[source]

Plot heatmap of mean opacity across P-T grid.

Parameters:
  • correlated_k (np.ndarray) – Correlated-k coefficients (n_p, n_t, n_bins, n_g)

  • bin_centers (np.ndarray) – Wavenumber bin centers (cm^-1)

  • pressures (np.ndarray) – Pressure grid (bar)

  • temperatures (np.ndarray) – Temperature grid (K)

  • g_weights (np.ndarray) – G-space weights

  • output_dir (Path) – Directory to save plot

  • mol_name (str) – Molecule name

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.plot_statistics_summary(correlated_k: ndarray, bin_centers: ndarray, g_samples: ndarray, g_weights: ndarray, output_dir: Path, mol_name: str, R_target: float)[source]

Plot statistical summary of correlated-k coefficients.

Parameters:
  • correlated_k (np.ndarray) – Correlated-k coefficients (n_p, n_t, n_bins, n_g)

  • bin_centers (np.ndarray) – Wavenumber bin centers (cm^-1)

  • g_samples (np.ndarray) – G-space samples

  • g_weights (np.ndarray) – G-space weights

  • output_dir (Path) – Directory to save plot

  • mol_name (str) – Molecule name

  • R_target (float) – Target resolution

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.generate_correlated_k(config: Config)[source]

Main function to generate correlated-k opacities from line-by-line data.

Parameters:

config (Config) – Configuration object with all parameters

GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.TabPanels.FrameDBInteractions.generate_correlated_k_from_lbl.main()[source]

Main entry point.