GUIBRUSHR.Retrieval.ModelCalculation.ModelData module¶
ModelData Module
This module contains the core ModelData class for atmospheric retrieval calculations. It handles parameter management, model calculations, and likelihood evaluations for both high-resolution and low-resolution observations.
This is the CORE of the code - all logic and sequence of operations are preserved.
- class GUIBRUSHR.Retrieval.ModelCalculation.ModelData.ModelData(path_params=None, path_df=None, id_process=None, table_output_file=None, minwlen_lr=None, maxwlen_lr=None, minwlen_hr=None, maxwlen_hr=None, model_type='Retrieval', lbl_sampling_hr=None, lbl_sampling_lr=None, range_min=None, range_max=None, nlayers=None, manual_model_obj=None, load_new_opacities=True, path_default=None, plot_convolved_LR=False)[source]¶
Bases:
objectCore class for atmospheric retrieval model data and calculations.
This class manages all aspects of atmospheric modeling including: - Parameter initialization and management - Model calculations for both high and low resolution - Likelihood evaluations - MCMC chain operations
- Variables:
path_default – Default path for operations
params_list – List of all possible parameters
list_multiple_param – Parameters that can have multiple values
clight – Speed of light constant
model_type – Type of model (Retrieval, Model, etc.)
atmosphere – Atmosphere object for calculations
retrieval_data – Retrieval configuration data
bestpars_data – Best parameters data
random_obj – Random number generator object
- __init__(path_params=None, path_df=None, id_process=None, table_output_file=None, minwlen_lr=None, maxwlen_lr=None, minwlen_hr=None, maxwlen_hr=None, model_type='Retrieval', lbl_sampling_hr=None, lbl_sampling_lr=None, range_min=None, range_max=None, nlayers=None, manual_model_obj=None, load_new_opacities=True, path_default=None, plot_convolved_LR=False)[source]¶
Initialize ModelData object.
- Parameters:
path_params – Path to parameters file
path_df – Path to dataframe file
id_process – Process ID for parallel operations
table_output_file – Output file for table data
minwlen_lr – Minimum wavelength for low resolution
maxwlen_lr – Maximum wavelength for low resolution
minwlen_hr – Minimum wavelength for high resolution
maxwlen_hr – Maximum wavelength for high resolution
model_type – Type of model calculation
lbl_sampling_hr – Line-by-line sampling parameter hr
lbl_sampling_lr – Line-by-line sampling parameter lr
range_min – Minimum pressure range
range_max – Maximum pressure range
nlayers – Number of atmospheric layers
manual_model_obj – Manual model object for direct initialization
load_new_opacities – Whether to load new opacity data
path_default – Default working directory path
- populate_from_manual_model(*args, **kwargs)[source]¶
Delegate to ModelSetup. See ModelSetup.populate_from_manual_model.
- add_param_manual_model(*args, **kwargs)[source]¶
Delegate to ParameterHandler. See ParameterHandler.add_param_manual_model.
- read_df_parameters(path_df_parameters)[source]¶
Delegate to ParameterHandler. See ParameterHandler.read_df_parameters.
- parameter_management(*args, **kwargs)[source]¶
Delegate to ParameterHandler. See ParameterHandler.parameter_management.
- read_df_information(*args, **kwargs)[source]¶
Delegate to ModelSetup. See ModelSetup.read_df_information.
- get_value(params, name, single_value=True)[source]¶
Delegate to ParameterHandler. See ParameterHandler.get_value.
- calculate_mass_fraction(*args, **kwargs)[source]¶
Delegate to LikelihoodHR. See LikelihoodHR.calculate_mass_fraction.
- calculate_log_prior(params)[source]¶
Delegate to LikelihoodHR. See LikelihoodHR.calculate_log_prior.
- high_resolution_lhood(temperature, mass_fraction, vmr, MMW, dict_calc_model, chain=None, step=None)[source]¶
Delegate to LikelihoodHR. See LikelihoodHR.high_resolution_lhood.
- low_resolution_lhood(temperature, mass_fraction, vmr, MMW, dict_calc_model, rp)[source]¶
Delegate to LikelihoodLR. See LikelihoodLR.low_resolution_lhood.
- lh_function_gib(params, chain=None, step=None)[source]¶
Evaluate the core likelihood function for atmospheric retrieval.
This is the HEART of the atmospheric retrieval system. It takes input parameters, performs boundary checks, extracts all parameter values, calculates temperature profiles, computes mass fractions, and evaluates both high-resolution and low-resolution likelihoods.
The function preserves the exact sequence of operations critical for atmospheric modeling and MCMC retrieval.
- Parameters:
params – List of ParamForModel objects containing all retrieval parameters
chain – MCMC chain index. Forwarded to downstream prints (negative mass fractions, negative spectrum, TRPCA error) so operators can identify which chain is misbehaving. None outside an MCMC context.
step – MCMC outer step index. Used together with
chainto annotate diagnostic prints. None outside an MCMC context.
- Returns:
lhood: Log-likelihood value (float)
det: Determinant value for Bayesian priors (float)
not_retrieval_obj: NotRetrieval object with model results (or None)
- Return type:
Tuple containing
- parallel_chain(index_core, j, return_dict, oldpars, old_lhood, old_log_prior, all_pars_snapshot, nthin=1, worker_seed=None, debug_log_path=None, outer_step=None, sampler='DE-MC', archive=None)[source]¶
Execute parallel MCMC chain step for differential evolution.
This method implements one step of the differential evolution MCMC algorithm in parallel. It calculates new parameter values using the DE formula and evaluates the likelihood to decide whether to accept or reject the step.
When nthin > 1, each chain performs nthin proposals internally and saves only the final state, matching the IDL inner loop:
IDL: for k=0, nthin-1 do begin ... endfor
- Parameters:
index_core – Index of the core.
j – Chain index array (chains assigned to this core)
return_dict – Shared dictionary for returning results
oldpars – Current parameter values for this core’s chains, shape (nfit, chain_per_core)
old_lhood – Current log-likelihood values for this core’s chains # IDL: oldchi2
old_log_prior – Log of Gaussian prior product for this core’s chains (IDL: ‘olddet’ - see calculate_log_prior for rename rationale)
all_pars_snapshot – Frozen snapshot of ALL chains’ parameters at the start of this outer step, shape (nfit, nchains). Used to draw fresh DE reference chains r1, r2 inside each sub-step.
nthin – Number of internal proposals per saved step (default 1)
worker_seed – SeedSequence used to build an independent rng stream for this worker. Required for proper multi-core mixing.
debug_log_path – Path to the shared JSONL log file. None disables logging; safe for concurrent append on POSIX.
outer_step – Parent-side step index used to correlate all events from the same MCMC iteration across workers.
sampler – “DE-MC” (default, legacy byte-identical path) or “Snooker” (DE-MCzs: per sub-step a 10% snooker move + 90% parallel DE move, both drawing from the archive). See Retrieval/ExofastMCMC/snooker.py.
archive – Full pooled history Z of past+present states, shape (M, nfit), required when sampler == “Snooker”; ignored for DE-MC.
- run_multiple_processes_manager_version(old_pars, old_lhood, old_log_prior, nthin=1, outer_step=None, debug_log_path=None, sampler='DE-MC', archive=None)[source]¶
Run MCMC chain steps in parallel using multiprocessing Manager.
This method distributes chain steps across multiple processes using differential evolution MCMC, with a shared Manager dictionary for collecting results.
- Parameters:
old_pars – Current parameter values for all chains, shape (nfit, nchains)
old_lhood – Current log-likelihood values for all chains, shape (nchains,) # IDL: old_chi
old_log_prior – Log of Gaussian prior product for all chains, shape (nchains,) (IDL: ‘old_det’ - renamed; see calculate_log_prior)
nthin – Thinning factor passed through to each worker process
outer_step – MCMC iteration index (owned by exofast parent loop). Passed into every worker event so multi-core records can be grouped by step during offline analysis.
debug_log_path – Shared JSONL log path. If None, falls back to the project default derived from retrieval_data.path_results.
- Returns:
- Manager dictionary mapping core index to array of
StructReturnExofast results
- Return type:
return_dict
- run_multiple_processes(old_pars, old_lhood, old_log_prior, nthin=1, outer_step=None, debug_log_path=None, sampler='DE-MC', archive=None)[source]¶
Run MCMC chain steps in parallel using the Manager-based approach.
- Parameters:
old_pars – Current parameter values for all chains, shape (nfit, nchains)
old_lhood – Current log-likelihood values for all chains, shape (nchains,) # IDL: old_chi
old_log_prior – Log of Gaussian prior product for all chains, shape (nchains,) (IDL: ‘old_det’ - renamed; see calculate_log_prior)
nthin – Thinning factor - each worker performs nthin proposals, saves last
outer_step – MCMC iteration index owned by the exofast parent loop.
debug_log_path – Shared JSONL log path (None → project default).
sampler – “DE-MC” (default) or “Snooker” (DE-MCzs). Forwarded to each worker.
archive – Pooled history Z (M, nfit) for the snooker path; None for DE-MC.
- Returns:
Dictionary containing results from all processes
- Return type:
return_dict