コード例 #1
0
def main(eventname):
    alpha,delta,datfiles,oblats,oblongs,obgammas,isspitz,parmref,parmfit,parmflx,errfacs,namefit,nameflx,use_color,I_minus_L = getparm.getEventInfo(eventname)
    data = getdat.getalldat(datfiles,errfacs,isspitz,parmref)
    tbegin,talert,t0par,t0base,mjd = parmref
### use more intensive time sequence ###
    date_mod = np.linspace(6700,7000,2000)
##### choose s and q for sensitivity mapping ###
#    ## for ob0124 ##
#    ntheta = 300
#    qList = np.logspace(np.log10(1e-5),np.log10(1e-2),20)
#    sList = np.logspace(-0.6,0.6,30)
#    nprocesses = 25
#    ## for ob0939 ##
#    ntheta = 300
#    qList = np.logspace(np.log10(1e-4),np.log10(1e-2),20)
#    sList = np.logspace(-0.4,0.4,100)
#    nprocesses = 6
#    ### pool.apply_async to parallelize ###
#    pool = mp.Pool(nprocesses)
#    for q in qList:
#        for s in sList:
#            pool.apply_async(get_q_s_prob,args=(q,s,eventname,[alpha,delta,oblats,oblongs,obgammas],data,[parmfit,namefit,parmflx,nameflx,parmref],isspitz,use_color,I_minus_L,ntheta),callback=mycallback)
#    pool.close()
#    pool.join()
#################################################
#### for test purpose ###
    plot_opt = True
    finmod_opt = True
    ntheta = 5
    qList = [7e-4]
    sList = [0.94]
#######################
    for q in qList:
        for s in sList:
            trials = get_q_s_prob(q,s,eventname,[alpha,delta,oblats,oblongs,obgammas],data,[parmfit,namefit,parmflx,nameflx,parmref],isspitz,use_color,I_minus_L,ntheta,outputlc=True,finmod_opt=True,date_mod=date_mod)
            mycallback(trials)
    return
コード例 #2
0
ファイル: splot.py プロジェクト: zhu-wei-pku/SFITPY
def main():
    eventname = 'ob150448'
#    eventname = raw_input('Please give the event name (eg, ob140124): ')
    alpha,delta,datfiles,oblats,oblongs,obgammas,isspitz,parmref,parmfit,parmflx,errfacs,namefit,nameflx,use_color,I_minus_L = getparm.getEventInfo(eventname)
    data = getdat.getalldat(datfiles,errfacs,isspitz,parmref)
    tbegin,talert,t0par,t0base,mjd = parmref
    parms_names = [parmfit,namefit,parmflx,nameflx,parmref]
    parmfree,namefree,parmfix,namefix = sfitpy.initialization(parms_names,isspitz)
    ## generating fake data ##
    q,s,theta = 1e-6,10,0.
    parmbfit = np.hstack([parmfit,[theta,q,s]])
    parmbflx = parmflx
#    data_fake = []
#    for iob in range(len(data)):
#        date,flux,ferr,mag,merr = data[iob]
#        ibinlc,xcau,ycau = genlc.getbinlc(alpha,delta,oblats[iob],oblongs[iob],date,parmbfit,parmbflx[iob],obgammas[iob],t0par,isspitz[iob],True)
#        imag = 18-2.5*np.log10(ibinlc[:,2])
#        ## save the fake data sets ##
#        np.savetxt('fake-data-%d.dat'%(iob+1),np.vstack([date,imag,merr,np.ones_like(date),np.ones_like(date)]).T,fmt='%f')
#        data_fake.append([date,ibinlc[:,2],ferr,imag,merr])
#    data = data_fake
#   ## change (pien,piee) ##
#    parmfree[namefree=='pien'] = 0.2
#    parmfree[namefree=='piee'] = 1.
#    print parmfree
    ### Downhill simplex method ###
#    parmfit,parmflx,chi2s,dof = sfitpy.downhill(sfitpy.lnprob_func,namefree,parmfree,namefix,parmfix,data,[alpha,delta,oblats,oblongs,obgammas],parmref,isspitz,use_color=use_color,I_minus_L=I_minus_L)
    ### MCMC to minimize the chisq ###
#    parmfit,parmflx,chi2s,dof = sfitpy.mcmc(sfitpy.lnprob_func,eventname,namefree,parmfree,namefix,parmfix,data,[alpha,delta,oblats,oblongs,obgammas],parmref,isspitz,use_color=use_color,I_minus_L=I_minus_L)
#### use getchi2 instead of lnprob_func: TBD ###
    ### Downhill simplex method ###
    parmfit,parmflx,chi2s,dof = sfitpy.downhill(sfitpy.getchi2,namefree,parmfree,namefix,parmfix,data,[alpha,delta,oblats,oblongs,obgammas],parmref,isspitz,use_color=use_color,I_minus_L=I_minus_L)
    ### MCMC to minimize the chisq ###
#    parmfit,parmflx,chi2s,dof = sfitpy.mcmc(sfitpy.getchi2,eventname,namefree,parmfree,namefix,parmfix,data,[alpha,delta,oblats,oblongs,obgammas],parmref,isspitz,use_color=use_color,I_minus_L=I_minus_L)
#### Find the model according to the given parameters ###
    fmod,mmod = [],[] ## model in flux and magnitude
    trajmod = []
    fmod_fin,mmod_fin = [],[]
    trajmod_fin = []
#    parmfit,parmflx = sfitpy.getparmfit(parmfree,parmfix,namefree,namefix)
    te = parmfit[namefit=='te']
    npts = (7300-6500)*10000./te
    npts = min([npts,100000])
    tmod = np.linspace(6500,7300,int(npts))
    for iob in range(len(data)):
        ## find model ##
        date,flux,ferr = data[iob][:3]
        itraj,ifmod = genlc.getslc(alpha,delta,oblats[iob],oblongs[iob],date,parmfit,parmflx[iob],obgammas[iob],t0par,isspitz[iob],False,True)
        immod = 18.-2.5*np.log10(ifmod)
        fmod.append(ifmod)
        mmod.append(immod)
        trajmod.append(itraj)
        ## find a finer light curve ##
        date = tmod
        itraj,ifmod = genlc.getslc(alpha,delta,oblats[iob],oblongs[iob],date,parmfit,parmflx[iob],obgammas[iob],t0par,isspitz[iob],False,True)
        immod = 18.-2.5*np.log10(ifmod)
        fmod_fin.append(ifmod)
        mmod_fin.append(immod)
        trajmod_fin.append(itraj)
#    fmod = np.array(fmod)
#    mmod = np.array(mmod)
    trajmod = np.array(trajmod)
    trajmod_fin = np.array(trajmod_fin)
    print 'Total chisq = ',chi2s[0]
    print ['%.2f/%d'%(chi2s[i+1],dof[i]) for i in range(len(dof))]