def main(chip=None, verbose=False, error_off=False, disable_wav_scale=False, renormalize=False, norm_method="scalar", betasigma=False): """Main function.""" wav_scale = not disable_wav_scale star = "HD211847" obsnum = 2 star = star.upper() setup_tcm_dirs(star) if chip is None: chip = 4 obs_name, params, output_prefix = tcm_helper_function(star, obsnum, chip) logging.debug(__("The observation used is {} \n", obs_name)) host_params = [params["temp"], params["logg"], params["fe_h"]] comp_params = [params["comp_temp"], params["logg"], params["fe_h"]] closest_host_model = closest_model_params(*host_params) # unpack temp, logg, fe_h with * closest_comp_model = closest_model_params(*comp_params) # Function to find the good models I need from parameters model1_pars = list(generate_close_params(closest_host_model, small=True)) model2_pars = list(generate_close_params(closest_comp_model, small=True)) # Load observation obs_spec = load_spectrum(obs_name) # Mask out bad portion of observed spectra obs_spec = spectrum_masking(obs_spec, star, obsnum, chip) # Barycentric correct spectrum _obs_spec = barycorr_crires_spectrum(obs_spec, extra_offset=None) # Determine Spectrum Errors try: if betasigma: errors = betasigma_error(obs_spec) logging.info(__("Beta-Sigma error value = {:6.5f}", errors)) else: errors = spectrum_error(star, obsnum, chip, error_off=error_off) logging.info(__("File obtained error value = {}", errors)) except KeyError as e: errors = None param_iter = len(alphas) * len(rvs) * len(gammas) * len(model2_pars) * len(model1_pars) logging.info(__("STARTING tcm_analysis\nWith {0} parameter iterations", param_iter)) logging.debug(__("model1_pars = {}, model2_pars = {} ", len(model1_pars), len(model2_pars))) tcm_analysis(obs_spec, model1_pars, model2_pars, alphas, rvs, gammas, errors=errors, verbose=verbose, norm=renormalize, prefix=output_prefix, wav_scale=wav_scale, norm_method=norm_method) return 0
def test_spectrum_error_error_off(star, obsnum, chip): assert spectrum_error(star, obsnum, chip, error_off=True) is None
def test_spectrum_error_expected(star, obsnum, chip, expected): assert spectrum_error(star, obsnum, chip) == expected
def test_spectrum_error_inverse_snr(star, obsnum, chip): assert spectrum_error(star, obsnum, chip) == 1 / get_snrinfo(star, obsnum, chip)[0]
def main(star, obsnum, chip=None, suffix=None, error_off=False, disable_wav_scale=False, renormalize=False, norm_method="scalar", betasigma=False): """Best Host modelling main function.""" wav_scale = not disable_wav_scale star = star.upper() setup_bhm_dirs(star) # Define the broadcasted gamma grid gammas = np.arange(*simulators.sim_grid["gammas"]) # print("bhm gammas", gammas) obs_name, params, output_prefix = bhm_helper_function(star, obsnum, chip) if suffix is not None: output_prefix = output_prefix + str(suffix) print("The observation used is ", obs_name, "\n") # Host Model parameters to iterate over # model_pars = get_bhm_model_pars(params, method="close") model_pars = get_bhm_model_pars(params, method="config") # Use config file # Load observation obs_spec = load_spectrum(obs_name) from spectrum_overload import Spectrum assert isinstance(obs_spec, Spectrum) # Mask out bad portion of observed spectra obs_spec = spectrum_masking(obs_spec, star, obsnum, chip) # Barycentric correct spectrum _obs_spec = barycorr_crires_spectrum(obs_spec, extra_offset=None) # Determine Spectrum Errors try: if betasigma: print("DOING BETASIGMA ERRORS") N = simulators.betasigma.get("N", 5) j = simulators.betasigma.get("j", 2) errors, derrors = betasigma_error(obs_spec, N=N, j=j) print("Beta-Sigma error value = {:6.5f}+/-{:6.5f}".format( errors, derrors)) logging.info( __("Beta-Sigma error value = {:6.5f}+/-{:6.5f}", errors, derrors)) else: print("NOT DOING BETASIGMA ERRORS") errors = spectrum_error(star, obsnum, chip, error_off=error_off) logging.info(__("File obtained error value = {0}", errors)) except KeyError as e: print("ERRORS Failed so set to None") errors = None bhm_analysis(obs_spec, model_pars, gammas, errors=errors, verbose=False, norm=renormalize, wav_scale=wav_scale, prefix=output_prefix, norm_method=norm_method) print("after bhm_analysis") print("\nNow use bin/coadd_bhm_db.py") return 0