GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.Frame_Cross_Correlation.run_lh_background module¶
Background likelihood computation module.
This script is launched as a subprocess by Frame_LH.py to perform the likelihood analysis without blocking the GUI. It reads parameters from exchange_lh.pkl, runs the computation, and writes results to result_lh.pkl or errors to error_lh.pkl.
- Usage:
python3 run_lh_background.py <exchange_path> <path_default>
- GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.Frame_Cross_Correlation.run_lh_background.compute_likelihood_for_order(h, night_obj, params, rvvec, kpvec, sfvec, csscaled, target_info)[source]¶
Compute the log-likelihood contribution for a single spectral order.
Iterates over the Kp and RV grids, Doppler-shifts the model, reprocesses it through the PCA pipeline, and evaluates the chi-square log-likelihood against the observed spectra. The scale factor (sf) loop is vectorized.
- Parameters:
h – Order index within the night object arrays.
night_obj – Night object containing spectra, wavelengths, masks, and PCA data.
params – Dict of computation parameters, including ‘rad_mode’ and ‘model_reprocessing’.
rvvec – 1D array of systemic radial velocity offsets to search (km/s).
kpvec – 1D array of planet orbital velocity amplitudes to search (km/s).
sfvec – 1D array of scale factors to search.
csscaled – Spline representation of the model depth spectrum.
target_info – Object with attributes mass, stellar_mass, and systemic_velocity.
- Returns:
- Log-likelihood cube of shape (len(kpvec), len(rvvec), len(sfvec))
representing the summed log-likelihood over all good pixels and in-transit frames for this order.
- Return type:
np.ndarray
- GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.Frame_Cross_Correlation.run_lh_background.compute_detection_significance(lhood)[source]¶
Convert a log-likelihood cube into a detection significance map.
Uses the delta-log-likelihood statistic with 2 degrees of freedom to compute p-values, then maps them to Gaussian sigma values. Infinite or NaN sigma values (from numerically exact p=0) are capped at 30.
- Parameters:
lhood – 3D log-likelihood array of shape (nkp, nrv, nsf).
- Returns:
sigma_map (np.ndarray): Detection significance in units of sigma, same shape as lhood.
max_idx (tuple): Index of the maximum likelihood point as returned by np.unravel_index.
- Return type:
tuple
- GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.Frame_Cross_Correlation.run_lh_background.create_diagnostic_plots(sigma_map, max_idx, rvvec, kpvec, sfvec, filepng1, filepng2, target_kp)[source]¶
Create and save the Kp-RV detection significance contour plots.
Produces two figures at the scale factor that maximises the likelihood: a discrete-contour plot with labelled 1/2/3-sigma contours saved to filepng2, and a continuous colormap (inferno) plot with a colorbar saved to filepng1.
- Parameters:
sigma_map – 3D significance array of shape (nkp, nrv, nsf).
max_idx – Tuple (ikp, irv, isf) of the maximum likelihood index.
rvvec – 1D array of RV grid values (km/s).
kpvec – 1D array of Kp grid values (km/s).
sfvec – 1D array of scale factor grid values.
filepng1 – Output path for the inferno colormap figure.
filepng2 – Output path for the labelled contour figure.
target_kp – Expected planet Kp value for the reference hline (km/s).
- GUIBRUSHR.GUI.Input_Output_Panels.Input_Panels.Frame_Cross_Correlation.run_lh_background.run_lh_func_bg(params, path_default)[source]¶
Run the full likelihood computation in the background subprocess.
Loads the cross-correlation model, builds the Kp/RV/sf search grids, accumulates the log-likelihood over all nights and spectral orders, computes detection significance, saves diagnostic plots, and serialises the likelihood cube to a pickle file.
- Parameters:
params – Dict of parameters loaded from exchange_lh.pkl. Required keys: rv_limit, rv_step, kp_limit, kp_step, sf_limit, sf_step, model_reprocessing, rad_mode, order_sel, tell_rm_method, dates, path_instruments, path_cc, filepng1, filepng2, path_pickle, target_limit_phase, target_mass, target_stellar_mass, target_systemic_velocity, target_kp, path_folder_targets, target_name.
path_default – Absolute path to the GUIBRUSHR project root. Used as the working directory and for resolving module imports.
- Returns:
- Absolute path to the inferno colormap figure (filepng1), which
is stored in result_lh.pkl so the GUI can display it.
- Return type:
str