Esempio n. 1
0
def find_offpeak(ft1, name, rad, peaks, pwncat1phase, TSdc):
    """plot light curve using pointlike script in whixh is added a line to plot the edges of the offpulse region
    a=minimum of the edge
    b=maximum of the edge"""

    plc = lc_plotting_func.PulsarLightCurve(ft1, psrname=name, radius=rad, emin=50, emax=300000)
    plc.fill_phaseogram()

    phases = plc.get_phases()
    primitives = []
    for peak in peaks:
        if isinstance(peak, numbers.Real):
            primitives.append(lp.LCLorentzian2(p=[0.4, 0.05, 0.05, peak]))
        else:
            primitives.append(eval(peak))
    lct = lf.LCTemplate(primitives=primitives)

    init_template = copy.deepcopy(lct)

    print "WARNING: HERE I SHOULD BE USING A WEIGHTED LIGHT CURVE"

    lcf = lf.LCFitter(lct, phases)
    print lcf
    lcf.fit(quick_fit_first=True)
    print lcf
    lcf.plot()

    dom = np.linspace(0, 1, 200)
    P.plot(dom, init_template(dom), color="green", lw=1)

    # if np.any([isinstance(p, LCLorentzian) or isinstance(p, LCLorentzian2) for p in primitives]):
    #    TScontamination = 0.1
    # else:
    #    TScontamination = 1
    # contamination = 1/(np.sqrt(TSdc)*10)
    # contamination = .01*(100/TSdc)**(1./2)
    # contamination = .01*(100/TSdc)**(1./3)
    # contamination = .01*(100/TSdc)**(1./4)
    contamination = 0.01

    op = OffPeak(lcf, contamination=contamination)

    op.off_peak.axvspan(label="lande", alpha=0.25, color="green")

    pwncat1phase.axvspan(label="pwncat1", alpha=0.25, color="blue")

    P.legend()

    P.title(name)

    P.savefig("results_%s.pdf" % name)
    # P.savefig('phaseogram_%s.pdf' % name)

    global results
    results = tolist(
        dict(
            lande_phase=op.off_peak.tolist(), pwncat1phase=pwncat1phase.tolist(), TSdc=TSdc, contamitation=contamination
        )
    )

    yaml.dump(results, open("results_%s.yaml" % name, "w"))

    results["lcf"] = lcf
    results["init_template"] = init_template
    results["final_template"] = lct

    pickle.dump(results, open("results_%s.pickle" % name, "w"))
Esempio n. 2
0
        spec,lis,lisname=get_spec_par(like,liste_source[i])
        if liste_source[i]!=name:
            for j in range(len(lisname)):
                param=like.par_index(liste_source[i],lisname[j])
                like.freeze(param)

    ul,xx=gtlike_ul(like,args.emin,args.emax,name,sigma=2)
    r['gtlike_ul']=ul
    
# calculate TScutoff ...

#roi.save('roi_%s.dat' % name)

open('results_%s.yaml' % name,'w').write(
    yaml.dump(
        tolist(results)
    )
)

# save stuff out
roi.plot_tsmap(filename='residual_tsmap_0.1_%s.pdf' % name,pixelsize=0.10,size=8)
roi.plot_tsmap(filename='residual_tsmap_0.25_%s.pdf' % name,pixelsize=0.25,size=8)

roi.toRegion('Region_file_%s.reg'%name)

roi.plot_sources(filename='sources_%s.pdf' % name, size=8, label_psf=False)

roi.toXML(filename="srcmodel_res_%s"%name,convert_extended=True)

roi.plot_sed(which=name,filename="sed_%s.png"%name)
Esempio n. 3
0
def save_results(): 
    open('results_%s.yaml' % name,'w').write(
        yaml.dump(tolist(results)))
Esempio n. 4
0
def find_offpeak(ft1,name,rad,peaks,pwncat1phase):
    """plot light curve using pointlike script in whixh is added a line to plot the edges of the offpulse region
    a=minimum of the edge
    b=maximum of the edge"""
    
    plc = lc_plotting_func.PulsarLightCurve(ft1, 
                                           psrname=name, radius=rad,
                                           emin=50, emax=300000)
    plc.fill_phaseogram()

    phases = plc.get_phases()
    primitives = []
    for peak in peaks:
        if isinstance(peak,numbers.Real):
            primitives.append(lp.LCLorentzian2(p=[0.4,0.05,0.05,peak]))
        else:
            primitives.append(eval(peak))
    lct = lf.LCTemplate(primitives=primitives)

    init_template = copy.deepcopy(lct)

    lcf = lf.LCFitter(lct,phases)
    print lcf
    lcf.fit(quick_fit_first=True)
    print lcf
    lcf.plot()

    dom = np.linspace(0,1,200)
    P.plot(dom,init_template(dom),color='green',lw=1)


    op = OffPeak(lcf)

    for a,b in op.off_peak.tolist(dense=False):
        P.axvspan(a, b, label='lande', alpha=0.25, color='green')

    for a,b in pwncat1phase.tolist(dense=False):
        P.axvspan(a, b, label='pwncat1', alpha=0.25, color='blue')

    P.legend()

    P.title(name)

    P.savefig('results_%s.pdf' % name)
    #P.savefig('phaseogram_%s.pdf' % name)

    global results
    results=tolist(
            dict(
                lande_phase = op.off_peak.tolist(),
                pwncat1phase = pwncat1phase,
                )
            )

    yaml.dump(results,
              open('results_%s.yaml' % name,'w')
             )

    results['lcf'] = lcf
    results['init_template'] = init_template
    results['final_template'] = lct

    pickle.dump(
        results,
        open('results_%s.pickle' % name,'w')
        )
Esempio n. 5
0
def save_results():
    open("results_%s.yaml" % name, "w").write(yaml.dump(tolist(results)))
Esempio n. 6
0
        fit()

        try:
            roi.fit_extension(which=name_mc, bandfits=False, estimate_errors=False)
            ts_ext = roi.TS_ext(which=name_mc, bandfits=False)
        except Exception, err:
            print "\n\n\n\nERROR FITTING EXTENSION: %s\n\n\n" % (str(err))
            ts_ext = -99

        fit()

        ts = roi.TS(which=name_mc, bandfits=False)

        source = roi.get_source(which=name_mc)
        sigma = source.spatial_model["sigma"]

        results_dict[-1]["ts_%s" % fit_irf] = ts
        results_dict[-1]["ts_ext_%s" % fit_irf] = ts_ext
        results_dict[-1]["sigma_%s" % fit_irf] = sigma

        del roi

    results_dict = toolbag.tolist(results_dict)

    temp = open(results, "w")
    temp.write(yaml.dump(results_dict))
    temp.close()

shutil.rmtree(tempdir)