def test_get_host_params(sim_config): """Find host star parameters from param file.""" simulators = sim_config star = "test" simulators.paths["parameters"] = "tests/testdata" params = param_file.get_host_params(star) assert len(params) == 3 assert params == (5340, 4.65, -0.22)
def main(database, echo=False, mode="parabola"): path, star, obsnum, chip = decompose_database_name(database) os.makedirs(os.path.join(path, "plots"), exist_ok=True) # make dir for plots teff, logg, fe_h = closest_model_params(*get_host_params(star)) params = { "path": path, "star": star, "obsnum": obsnum, "chip": chip, "teff": teff, "logg": logg, "fe_h": fe_h } sqlite_db = 'sqlite:///{}'.format(database) try: engine = sa.create_engine(sqlite_db, echo=echo) table_names = engine.table_names() except Exception as e: print("\nAccessing sqlite_db = {}\n".format(sqlite_db)) print("cwd =", os.getcwd()) raise e print("Table names in database =", engine.table_names()) if len(table_names) == 1: tb_name = table_names[0] else: raise ValueError("Database has two many tables {}".format(table_names)) db_table = load_sql_table(database) print("Mode =", mode) if mode == "fixed_host_params": fix_host_parameters_reduced_gamma(engine, params, tb_name) fix_host_parameters(engine, params, tb_name) elif mode == "param_limits": get_column_limits(engine, params, tb_name) elif mode == "parabola": parabola_plots(db_table, params) elif mode == "smallest_chi2": smallest_chi2_values(engine, params, tb_name) elif mode == "contour": alpha_rv_contour(engine, params, tb_name) elif mode == "contour": alpha_rv_contour_old(engine, params, tb_name) elif mode == "test": test_figure(engine, params, tb_name) print("Done") return 0
def main(star, obsnum, chip, suffix="", echo=False): database = os.path.join( simulators.paths["output_dir"], star, "iam", "{0}-{1}_{2}_iam_chisqr_results{3}.db".format(star, obsnum, chip, suffix)) path, star, obsnum, chip = decompose_database_name(database) os.makedirs(os.path.join(path, "plots"), exist_ok=True) save_name = os.path.join( path, "{0}_iam_all_observation_min_chi2{1}.tsv".format(star, suffix)) teff, logg, fe_h = closest_model_params(*get_host_params(star)) params = { "path": path, "star": star, "obsnum": obsnum, "chip": chip, "teff": teff, "logg": logg, "fe_h": fe_h } # Hack to run from editor if os.getcwd().endswith("companion_simulations/bin"): database = "../" + database save_name = "../" + save_name if os.path.exists(database): engine = sa.create_engine('sqlite:///{0}'.format(database), echo=echo) else: raise IOError("Database does not exist.") table_names = engine.table_names() if len(table_names) == 1: tb_name = table_names[0] else: raise ValueError( "Database has two many tables {0}".format(table_names)) query = """SELECT * FROM {0} WHERE (teff_1 = {1} AND logg_1 = {2} AND feh_1 = {3}) ORDER BY chi2 LIMIT 1 """.format(tb_name, params["teff"], params["logg"], params["fe_h"]) df = pd.read_sql(sa.text(query), engine) df["obsnum"] = obsnum df["chip"] = chip columns = [ "obsnum", "chip", "teff_1", "logg_1", "feh_1", "teff_2", "logg_2", "feh_2", "alpha", "rv", "gamma", "chi2" ] if os.path.exists(save_name): df.to_csv(save_name, columns=columns, sep='\t', mode="a", index=False, header=False) else: df.to_csv(save_name, columns=columns, sep='\t', mode="a", index=False, header=True) return save_name
def main(star, obsnum, suffix=None, echo=False, mode="parabola", verbose=False, npars=3): star = star.upper() suffix = "" if suffix is None else suffix database = os.path.join( simulators.paths["output_dir"], star, "iam", "{0}-{1}_coadd_iam_chisqr_results{2}.db".format(star, obsnum, suffix)) if verbose: print("Database name ", database) print("Database exists", os.path.isfile(database)) if not os.path.isfile(database): raise IOError("Database '{0}' does not exist.".format(database)) path, dbstar, db_obsnum, chip = decompose_database_name(database) assert dbstar == star, "{} == {}".format(dbstar, star) assert str(db_obsnum) == str(obsnum), "{} == {}".format(db_obsnum, obsnum) assert chip == "coadd", "{} == {}".format(chip, "coadd") os.makedirs(os.path.join(path, "plots"), exist_ok=True) # make dir for plots teff, logg, fe_h = closest_model_params(*get_host_params(star)) params = { "path": path, "star": star, "obsnum": obsnum, "chip": chip, "suffix": suffix, "teff": int(teff), "logg": float(logg), "fe_h": float(fe_h), "npars": npars } db_table = load_sql_table(database, verbose=verbose, echo=echo) # Put pixel counts in params params["npix"] = get_npix_values(db_table) if verbose: print("Mode =", mode) try: if mode == "fixed_host_params": try: fix_host_parameters_reduced_gamma(db_table, params) fix_host_parameters(db_table, params) except Exception as e: print(e) elif mode == "param_limits": get_column_limits(db_table, params) elif mode == "parabola": parabola_plots(db_table, params) elif mode == "smallest_chi2": smallest_chi2_values(db_table, params) elif mode == "contour": contours(db_table, params) elif mode == "test": test_figure(db_table, params) elif mode == "rvplot": rv_plot(db_table, params) elif mode == "chi2_parabola": chi2_parabola_plots(db_table, params) chi2_individual_parabola_plots(db_table, params) elif mode == "compare_spectra": compare_spectra(db_table, params) elif mode == "contrast": contrast_iam_results(db_table, params) elif mode == "all": try: fix_host_parameters_reduced_gamma(db_table, params) fix_host_parameters(db_table, params) except: pass plt.close("all") try: get_column_limits(db_table, params) except: pass plt.close("all") try: smallest_chi2_values(db_table, params) except: pass plt.close("all") try: parabola_plots(db_table, params) except: pass plt.close("all") try: test_figure(db_table, params) except: pass plt.close("all") try: chi2_parabola_plots(db_table, params) except: pass plt.close("all") try: chi2_individual_parabola_plots(db_table, params) except: pass plt.close("all") try: compare_spectra(db_table, params) except: pass plt.close("all") try: contours(db_table, params) except: pass plt.close("all") try: contrast_iam_results(db_table, params) except: pass plt.close("all") else: warnings.warn("Incorrect Mode in iam analysis") except Exception as e: print(e) plt.close("all") return 1 plt.close("all") print("Done") return 0