def test_spectrum_masking(host, star, obsnum, chip): info = get_maskinfo(star, obsnum, chip)[0] assert host.xaxis[0] < info[0] assert host.xaxis[-1] > info[1] host = spectrum_masking(host, star, obsnum, chip) assert not host.xaxis[0] < info[0] assert not host.xaxis[-1] > info[1]
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_masking_50pixel_detector_4(host): start_len = len(host) host = spectrum_masking(host, "HD0", "1", "4") # Detector 4 but with no recored masks. end_len = len(host) assert start_len - end_len == 50
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
def main(star, obsnum, teff_1, logg_1, feh_1, teff_2, logg_2, feh_2, gamma, rv, plot_name=None): fig, axis = plt.subplots(2, 2, figsize=(15, 8), squeeze=False) for chip, ax in zip(range(1, 5), axis.flatten()): # Get observation data obs_name, params, output_prefix = iam_helper_function( star, obsnum, chip) # Load observed spectrum 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 # error_off = False # errors = spectrum_error(star, obsnum, chip, error_off=error_off) # Create model with given parameters host = load_starfish_spectrum([teff_1, logg_1, feh_1], limits=[2110, 2165], area_scale=True, hdr=True) if teff_2 is None: assert (logg_2 is None) and (feh_2 is None) and ( rv == 0), "All must be None for bhm case." companion = Spectrum(xaxis=host.xaxis, flux=np.zeros_like(host.flux)) else: companion = load_starfish_spectrum([teff_2, logg_2, feh_2], limits=[2110, 2165], area_scale=True, hdr=True) joint_model = inherent_alpha_model(host.xaxis, host.flux, companion.flux, gammas=gamma, rvs=rv) model_spec = Spectrum(xaxis=host.xaxis, flux=joint_model(host.xaxis).squeeze()) model_spec = model_spec.remove_nans() model_spec = model_spec.normalize("exponential") # plot obs_spec.plot(axis=ax, label="{}-{}".format(star, obsnum)) model_spec.plot(axis=ax, linestyle="--", label="Chi-squared model") ax.set_xlim([obs_spec.xmin() - 0.5, obs_spec.xmax() + 0.5]) ax.set_title("{} obs {} chip {}".format(star, obsnum, chip)) ax.legend() plt.tight_layout() if plot_name is None: fig.show() else: if not (plot_name.endswith(".png") or plot_name.endswith(".pdf")): raise ValueError("plot_name does not end with .pdf or .png") fig.savefig(plot_name) return 0