def fit_observation( self, sme, star, segments="all", parameters=["teff", "logg", "monh", "vsini", "vmac", "vmic"], ): # Fit the observation with SME print("Fit stellar spectrum with PySME") # sme.cscale_flag = "linear" # sme.cscale_type = "mask" # sme.vrad_flag = "whole" solver = SME_Solver() sme = solver.solve(sme, param_names=parameters, segments=segments) fig = plot_plotly.FinalPlot(sme) fig.save(filename="solved.html") # Save output print("Save results") for param in parameters: unit = getattr(star, param).unit print(f"{param}: {sme[param]} {unit}") setattr(star, param, sme[param] * unit) # TODO: + barycentric correction star.radial_velocity = sme.vrad[0] << (u.km / u.s) return sme, star
# Start the logging to the file makedirs(dirname(log_file), exist_ok=True) util.start_logging(log_file) # Load your existing SME structure or create your own sme = SME.SME_Structure.load(in_file) # Change parameters if your want sme.vrad = 0.35 sme.vrad_flag = "whole" sme.cscale_flag = "linear" sme.cscale_type = "match" # Apply the parameters set via the command line sme.teff = teff sme.logg = logg sme.monh = monh # Start SME solver sme = synthesize_spectrum(sme) # Save results makedirs(dirname(out_file), exist_ok=True) sme.save(out_file) # Plot results makedirs(dirname(plot_file), exist_ok=True) fig = plot_plotly.FinalPlot(sme) fig.save(filename=plot_file)
orig = sme.synth.copy() sme.cscale_flag = "linear" sme.cscale_type = "match+mask" sme.cscale[0] = [0, 1] rvel = 100 wmin, wmax = sme.wran[0] wmin *= 1 - rvel / 3e5 wmax *= 1 + rvel / 3e5 sme.linelist = sme.linelist.trim(wmin, wmax) sme.specific_intensities_only = True wmod, smod, cmod = synthesize_spectrum(sme, segments=[0]) orig = readsav(in_file)["sme"] sint = orig["SINT"][0] wint = orig["JINT"][0] wind = orig["WIND"][0] sint = sint[0, 0:wind[0]] wint = wint[0:wind[0]] plt.plot(wint, sint) plt.plot(wmod[0], smod[0] * cmod[0]) plt.show() # Plot results fig = plot_plotly.FinalPlot(sme, orig=orig) fig.save(filename=plot_file) print(f"Finished: {target}")
# idl.nlte.set_nlte("Al", "nlte_Al_ama51_pysme.grd") # idl.nlte.set_nlte("Ba", "nlte_Ba_ama51_pysme.grd") # idl.nlte.set_nlte("Ca", "nlte_Ca_ama51_pysme.grd") # idl.nlte.set_nlte("C", "nlte_C_ama51_pysme.grd") # idl.nlte.set_nlte("H", "nlte_H_ama51_pysme.grd") # idl.nlte.set_nlte("K", "nlte_K_ama51_pysme.grd") # idl.nlte.set_nlte("Li", "nlte_Li_ama51_pysme.grd") # idl.nlte.set_nlte("Mg", "nlte_Mg_ama51_pysme.grd") # idl.nlte.set_nlte("Mn", "nlte_Mn_ama51_pysme.grd") # idl.nlte.set_nlte("Na", "nlte_Na_ama51_pysme.grd") # idl.nlte.set_nlte("N", "nlte_Na_ama51_pysme.grd") # idl.nlte.set_nlte("O", "nlte_O_ama51_pysme.grd") # idl.nlte.set_nlte("Si", "nlte_Si_ama51_pysme.grd") # idl.nlte.set_nlte("Fe", "marcs2012_Fe2016.grd") # idl = synthesize_spectrum(idl) # fp = ["teff", "logg", "monh", "vmic", "vmac", "vsini"] # idl = solve(idl, fp) # idl.save(join(cwd, "results/Cnc55_tanja.sme")) # idl_solved = SME_Structure.load(join(cwd, "results/Cnc55_tanja.sme")) fig = plot_plotly.FinalPlot(idl, orig=orig, labels={ "synth": "IDL SME", "orig": "PySME" }) fig.save(filename=join(cwd, "Cnc55_tanja.html")) pass
plot_file = os.path.join(examples_dir, f"results/{target}.html") log_file = os.path.join(examples_dir, f"results/{target}.log") # Start the logging to the file util.start_logging(log_file) # Load your existing SME structure or create your own sme = SME.SME_Structure.load(in_file) idl = SME.SME_Structure.load(idl_file) sme.cscale = [0, 1] sme.cscale_type = "match+mask" sme.vrad = idl.vrad sme.vrad_flag = "none" sme.cscale_flag = "none" sme = synthesize_spectrum(sme) # Save results sme.save(out_file) # Plot results fig = plot_plotly.FinalPlot(sme, orig=idl.synth, labels={ "synth": "PySME", "orig": "IDL SME" }) fig.save(filename=plot_file) pass