def test_simple(): sme = SME_Struct.load(filename) sme2 = solve(sme, ["teff"]) assert sme2.synth is not None assert sme2.fitresults is not None assert sme2.fitresults.covar is not None assert isinstance(sme2.fitresults.covar, np.ndarray) assert np.all(sme2.fitresults.covar != 0) assert isinstance(sme2.fitresults.punc, dict) assert len(sme2.fitresults.punc) == 1 assert len(sme2.fitresults.punc.keys()) == 1 assert list(sme2.fitresults.punc.keys())[0] == "teff" assert list(sme2.fitresults.punc.values())[0] != 0 assert np.array_equal(sme2.fitresults.covar.shape, [1, 1]) assert sme2.fitresults.covar.ndim == 2 assert sme2.fitresults.chisq != 0
def test_simple(): sme = SME_Struct.load(filename) sme2 = solve(sme, ["teff"]) assert sme2.synth is not None assert sme2.fitresults is not None assert sme2.fitresults.covariance is not None assert isinstance(sme2.fitresults.covariance, np.ndarray) assert np.all(sme2.fitresults.covariance != 0) assert isinstance(sme2.fitresults.uncertainties, np.ndarray) assert len(sme2.fitresults.uncertainties) == 1 assert sme2.fitresults.parameters[0] == "teff" assert sme2.fitresults.uncertainties[0] != 0 assert np.array_equal(sme2.fitresults.covariance.shape, [1, 1]) assert sme2.fitresults.covariance.ndim == 2 assert sme2.fitresults.chisq is not None assert sme2.fitresults.chisq != 0
def main(fname_in, fname_out, fit_parameters, log_file=None): if log_file is not None: start_logging(log_file) sme = SME_Structure.load(fname_in) sme = solve(sme, fit_parameters) sme.save(fname_out)
else: param = [5000, 4.4, 0.4] # 5000.00, 4.00, 0.00 sme.teff = float(param[0]) sme.logg = float(param[1]) sme.monh = float(param[2]) sme.vmic = 1 sme.vmac = 3.4 sme.vsini = 0.5 # Like HARPS? sme.iptype = "gauss" sme.ipres = 100_500 * 2 # try: fp = ["teff", "logg", "monh"] sme = solve(sme, fp) sme.save( join( examples_dir, f"results/convergence_teff_{param[0]}_logg_{param[1]}_monh_{param[2]}.sme", )) print( f"{param[0]}, {param[1]}, {param[2]}, {sme.teff}, {sme.logg}, {sme.monh}" ) plot_file = join( examples_dir, f"results/convergence_teff_{param[0]}_logg_{param[1]}_monh_{param[2]}.html", ) fig = FinalPlot(sme) fig.save(filename=plot_file)
# wmax *= 1 + rvel / 3e5 # sme.linelist = sme.linelist.trim(wmin, wmax) # Start SME solver # sme = synthesize_spectrum(sme, segments=np.arange(6, 31)) # sme.cscale_flag = "fix" # sme.wave = sme.wave[6:31] # sme.spec = sme.spec[6:31] # sme.synth = sme.synth[6:31] # sme.mask = sme.mask[6:31] # sme.telluric = sme.telluric[6:31] # save_as_idl(sme, "epseri.inp") # sme.save(out_file) for fp in fitparameters: sme = solve(sme, fp, segments=np.arange(6, 31)) fname = f"{target}_mask_2_out_{'_'.join(fp)}" out_file = os.path.join(examples_dir, "results", fname + ".sme") sme.save(out_file) plot_file = os.path.join(examples_dir, "results", fname + ".html") fig = plot_plotly.FinalPlot(sme) fig.save(filename=plot_file) # print(sme.citation()) # Save results # sme.save(out_file) # Plot results fig = plot_plotly.FinalPlot(sme)
vald_file = join(dirname(__file__), "data/sun_full.lin") sme.linelist = ValdFile(vald_file) # TODO: is this correct? sme.linelist.medium = "air" sme.cscale_flag = "none" sme.vrad_flag = "whole" sme.atmo.source = "marcs2012.sav" sme.atmo.depth = "RHOX" sme.atmo.interp = "TAU" sme.mask = 1 idl_file = join(dirname(__file__), "sun.inp") save_as_idl(sme, idl_file) # sme = synthesize_spectrum(sme) sme = solve(sme, ["teff", "logg", "monh"]) sme.save(save_file) save_file = join(dirname(__file__), "results/sun_compare.sme") sme = SME_Structure.load(save_file) idl_file = join(dirname(__file__), "sun1.out") idl = SME_Structure.load(idl_file) # for i in range(30): # plt.hist( # sme.fitresults.residuals[i * 1024 : (i + 1) * 1024] # / sme.fitresults.derivative[i * 1024 : (i + 1) * 1024, 0], # bins="auto", # histtype="step", # )
# Load your existing SME structure or create your own sme = SME.SME_Structure.load(in_file) sme.abund = Abund(0, "asplund2009") sme.linelist = ValdFile(os.path.join(examples_dir, "sun.lin")) # Change parameters if your want sme.vsini = 0 sme.vrad = 0.35 sme.vrad_flag = "each" sme.cscale_flag = "linear" sme.cscale_type = "mask" # Define any fitparameters you want # For abundances use: 'abund {El}', where El is the element (e.g. 'abund Fe') # For linelist use: 'linelist {Nr} {p}', where Nr is the number in the # linelist and p is the line parameter (e.g. 'linelist 17 gflog') fitparameters = ["teff", "logg", "monh"] # Start SME solver # sme = synthesize_spectrum(sme) sme = solve(sme, fitparameters) print(sme.citation()) # Save results sme.save(out_file) # Plot results fig = plot_plotly.FinalPlot(sme) fig.save(filename=plot_file)