def fitLag(linfile, linfchain, conthpd, names=None, lagrange=[50, 300], lagbinsize=1, threads=1, set_plot=False, nwalkers=100, nburn=100, nchain=100, mode="test"): """ fit the Rmap model. """ if mode == "run": linfile = ".".join([linfile, "myrun"]) zydata = get_data(linfile, names=names) rmap = Rmap_Model(zydata) if mode == "test": if zydata.nlc == 2: print(rmap([np.log(sigma), np.log(tau), lagy, widy, scaley])) elif zydata.nlc == 3: print( rmap([ np.log(sigma), np.log(tau), lagy, widy, scaley, lagz, widz, scalez ])) return (None) elif mode == "show": rmap.load_chain(linfchain, set_verbose=False) elif mode == "run": laglimit = [ [0.0, tau], ] * (zydata.nlc - 1) print(laglimit) # laglimit = "baseline" linfchain = ".".join([linfchain, "myrun"]) rmap.do_mcmc(conthpd=conthpd, lagtobaseline=0.5, laglimit=laglimit, nwalkers=nwalkers, nburn=nburn, nchain=nchain, fburn=None, fchain=linfchain, threads=threads) if set_plot: rmap.break_chain([ lagrange, ] * (zydata.nlc - 1)) rmap.get_hpd() if zydata.nlc == 2: figout = "mcmc1" else: figout = "mcmc2" rmap.show_hist(bins=100, lagbinsize=lagbinsize, figout=figout, figext=figext) return (rmap.hpd)
def fitLag(linfile, linfchain, conthpd, names=None, lagrange=[50, 300], lagbinsize=1, threads=1, set_plot=False, nwalkers=100, nburn=50, nchain=50, mode="test") : """ fit the Rmap model. """ if mode == "run" : linfile = ".".join([linfile, "myrun"]) zydata = get_data(linfile, names=names) rmap = Rmap_Model(zydata) if mode == "test" : if zydata.nlc == 2 : print(rmap([np.log(2.), np.log(100), lagy, widy, scaley ])) elif zydata.nlc == 3 : print(rmap([np.log(2.), np.log(100), lagy, widy, scaley, lagz, widz, scalez])) return(None) elif mode == "show" : rmap.load_chain(linfchain, set_verbose=False) elif mode == "run" : laglimit = [[0.0, 400.0],]*(zydata.nlc-1) print(laglimit) # laglimit = "baseline" linfchain = ".".join([linfchain, "myrun"]) rmap.do_mcmc(conthpd=conthpd, lagtobaseline=0.5, laglimit=laglimit, nwalkers=nwalkers, nburn=nburn, nchain=nchain, fburn=None, fchain=linfchain, threads=threads) if set_plot : rmap.break_chain([lagrange,]*(zydata.nlc-1)) rmap.get_hpd() if zydata.nlc == 2 : figout = "mcmc1" else : figout = "mcmc2" rmap.show_hist(bins=100, lagbinsize=lagbinsize, figout=figout, figext=figext) return(rmap.hpd)
def rm_single(rmid, nwalker, nchain, nburn, min_lag, max_lag, fig_out): # Input and output data position and name file_con = Location.project_loca + "result/light_curve/" + str(rmid) + \ "/cont.txt" file_hbeta = Location.project_loca + "result/light_curve/" + str(rmid) + \ "/Hbetab.txt" lc_plot = Location.project_loca + "result/light_curve/" + str(rmid) + \ "/lightcurve" data_out = Location.project_loca + "result/light_curve/" + str(rmid) + \ "/cont-hbeta.txt" last_mcmc = Location.project_loca + "result/light_curve/" + str(rmid) + \ "/last_mcmc" # Fit continuum c = get_data([file_con]) cmod = Cont_Model(c) cmod.do_mcmc(threads=100, nwalkers=nwalker, nchain=nchain, nburn=nburn) # Do mcmc cy = get_data([file_con, file_hbeta], names=["Continuum", "Hbeta"]) cy.plot(figout=lc_plot, figext="png") cymod = Rmap_Model(cy) cymod.do_mcmc(conthpd=cmod.hpd, threads=100, fchain=data_out, nwalkers=nwalker, nchain=2.0 * nchain, nburn=2.0 * nburn, laglimit=[[min_lag, max_lag]]) # Output mcmc result cymod.show_hist(figout=fig_out, figext="png") cypred = cymod.do_pred() cypred.plot(set_pred=True, obs=cy, figout=last_mcmc, figext="png") return [cymod.hpd[0][2], cymod.hpd[1][2], cymod.hpd[2][2]]
x = cont_best.jlist[:] y = cont_best.mlist[:] + cont_best.blist[:] ey = cont_best.elist[:] plt.plot(x[0], y[0] + javdata_con.cont_mean) plt.fill_between(x[0], y[0] - ey[0] + javdata_con.cont_mean, y[0] + ey[0] + javdata_con.cont_mean, where=None, color='grey') x = javdata_con.jlist[:] y = javdata_con.mlist[:] + javdata_con.blist[:] ey = javdata_con.elist[:] plt.errorbar(x[0], y[0] + javdata_con.cont_mean, yerr=ey[0], ls='none', marker='o') plt.show() rmap1 = Rmap_Model(javdata_rm) #rmap1.do_mcmc(conthpd=conthpd, fchain="mychain1.dat", laglimit=[[0, 10],], nwalkers=100, nburn=200, nchain=1000) rmap1.load_chain("mychain1.dat") rmap1.show_hist() rmap1.get_hpd() rmap1hpd = rmap1.hpd par_best = rmap1hpd[1, :] print(par_best) javdata_best = rmap1.do_pred(par_best) javdata_best.plot(set_pred=True, obs=javdata_rm)
from javelin.zylc import get_data from javelin.lcmodel import Cont_Model from javelin.lcmodel import Rmap_Model import numpy as np c = get_data(["dat/continuum.dat"]) cmod = Cont_Model(c) cmod.do_mcmc(nwalkers=100, nburn=100, nchain=100, threads=1) cmod.show_hist() print cmod.hpd javdata4 = get_data(["dat/continuum.dat", "dat/yelm.dat"], names=["Continuum", "Yelm"]) rmap2 = Rmap_Model(javdata4) rmap2.do_mcmc(conthpd=cmod.hpd, nwalkers=100, nburn=100, nchain=100, threads=1, laglimit=[ [10, 200], ], fixed=[1, 0, 1, 0, 1], p_fix=[np.log(0.1), np.log(400), 10, 2.0, 5.0]) rmap2.show_hist() print rmap2.hpd