Ejemplo n.º 1
0
 def write_yaml(self, filename):
     """ Write an SED object to a yaml file """
     #if not isinstance(cls, SED): raise TypeError("Not SED object")
     tools.yaml_dump(self.tolist(),filename)
Ejemplo n.º 2
0
        
        #outfile=join(workdir,splitext(basename(infile))[0]+"_logLike.dat")
        outfile=join(workdir,outfile)
        mkdir(dirname(outfile))
        print "Writing %s"%outfile
        data = np.vstack( (norm, flux, lnl, p1lnl, flnl, p2lnl, m1lnl) ).T
        out = open(outfile,'w')
        out.write('%-15s %-15s %-15s %-15s %-15s %-15s %-15s\n'%('# normPar','flux[ph/cm2/s]','logLike',
                                                                 'p1logLike','flogLike','p2logLike','m1logLike'))
        np.savetxt(out,data,fmt='%-15.6g %-15.6g %-15.6g %-15.6g %-15.6g %-15.6g %-15.6g')
        out.close()

    lnlfile = join(workdir,'%s_%s.yaml'%(target,suffix))
    print "Writing %s"%lnlfile
    tools.yaml_dump(dict(lnldata = profile_data,param=spparam,
                         jvalue=jvalue,jsigma=jsigma,
                         jnominal=jnominal,rjvalues=rjvalues),lnlfile)
    
    """
    if opts.plot:
        import pylab as plt

        sed_emin, sed_emax = sed.get_emins(),sed.get_emaxs()
        sed_energy = np.sqrt(sed_emin*sed_emax)
        
        sed_eflux = sed.get_efluxes()
        sed_lnl=sed.get_logLikes()
        sed_ul = sed.get_ulimits(alpha=0.05)
        
        x = np.logspace(-3,5,100)
        xmin = x.min(); xmax = x.max()
Ejemplo n.º 3
0
    print 'Calculating limits.'
    try:
        lnlfn = LnLFn(lnlx,lnly)
        p1lnlfn = LnLFn(lnlx,p1lnl)
        r['models'][i]=str(model)
        r['mle'][i] = lnlfn.mle()
        r['ulimits68'][i]  = ProfileLimit( lnlx, lnly).getLimit( 0.32 )        
        r['fluxes68'][i]  = ProfileLimit( flux, flnl).getLimit( 0.32 )
        r['ulimits95'][i]  = ProfileLimit( lnlx, lnly).getLimit( 0.05 )        
        r['fluxes95'][i]  = ProfileLimit( flux, flnl).getLimit( 0.05 )
        r['ulimits99'][i]  = ProfileLimit( lnlx, lnly).getLimit( 0.01 )
        r['fluxes99'][i]  = ProfileLimit( flux, flnl).getLimit( 0.01 )
        r['ts'][i] = float(2*(p1lnlfn(p1lnlfn.mle()) - p1lnlfn(0)))
        r['matching_radius'][i]=matching_disk
        r['fom']=foms 
    except Exception, message:
        print 'caught exception ',message
        continue
    safe_copy("srcmap.fits","%s_srcmap.fits"%model)
    [os.remove(f) for f in ["gtsrcmaps.par","srcmap.fits"]]

if opts.bracket != "None":
    if opts.bracket == "plus": config['outfile']=config['outfile'].replace(".yaml","_plus.yaml")
    else:   config['outfile']=config['outfile'].replace(".yaml","_minus.yaml")
print "Writing output",config['outfile']
yaml_dump(r,config['outfile']) # keep track of things!
print 'cleaning up...'
files = glob.glob("*_spatial.fits")
[os.remove(f) for f in files]
print 'Done.'