예제 #1
0
def create_job_array(jobname, commands, logfiles=None, sleep='1m'):
    subdir=mkdir("sub")
    outdir=mkdir("log")

    subbase=os.path.join(subdir,basename(jobname))
    outbase=os.path.join(outdir,basename(jobname))

    create_scripts(commands,subbase,sleep)
    if logfiles is not None:
        link_logfiles(logfiles,outbase)

    submit="sh "+subbase+".${LSB_JOBINDEX}"; 
    output=outbase+".%I"

    njobs = len(commands)
    params = dict(name=jobname,
                  cmnd=submit,
                  log=output,
                  njobs=njobs)
                  
    job = """-oo %(log)s -J %(name)s[1-%(njobs)i] %(cmnd)s"""%(params)
    return job
예제 #2
0
        (norm, flux, lnl, p1lnl, flnl) = pd[0]
        p2lnl = LnLFn(pd[1][0],pd[1][3])(norm)
        m1lnl = np.zeros(np.shape(p2lnl))
        ### FIXME! TRY WITH THIS ONE FIRST! --  still broken!
        #m1lnl = LnLFn(pd[2][0],pd[2][3])(norm)

        profile_data[spparam[i]] = dict(norm=norm,flux=flux,lnl=lnl,p1lnl=p1lnl,
                                        flnl=flnl,p2lnl=p2lnl,m1lnl=m1lnl)
        
        # Write logLike to text file
        if not opts.text_output: continue
        
        #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)
    
    """
예제 #3
0
def gtltcuber(queue='long',**kwargs):
    """ Submit a set of ltcubes to the batch and collect them at the end 
    evfile  : List of LAT ft1 fits files
    scfile  : LAT spacecraft file
    outfile : Output summed ltcube
    tmin    : Minimum time
    tmax    : Maximum time"""

    workdir = mkdtemp(dir='./')
    tmp = mkdir('/tmp/%s/'%os.environ['USER'])
    os.environ['PFILES']=tmp+';'+os.environ['PFILES'].split(';')[-1]

    tmin = kwargs.get('tmin',0)
    tmax = kwargs.get('tmax',0)
    zmax = kwargs.get('zmax',0)
    dcostheta = kwargs.get('dcostheta',180)
    binsz = kwargs.get('binsz',1)
    chatter = kwargs.get('chatter',2)
    sleep = kwargs.get('sleep','5m')

    if kwargs['evfile'].startswith('@'):
        evfiles = np.loadtxt(kwargs['evfile'].strip('@'),dtype='str')
    else:
        evfiles = [ kwargs['evfile'] ]

    #### Calculated the ltcubes ####
    jobname = 'gtltcube.%s'%os.path.basename(workdir)
    lst, cmnds,logs = [],[],[]
    i = 0
    for evfile in evfiles:
        #### gtltcube doesn't treat tmin/tmax sensibly ####
        header = pyfits.open(evfile)[0].header
        tstart = int(float(header['TSTART']))
        tstop  = int(float(header['TSTOP']))
        if tstart >= tmax or tstop <= tmin:
            print "Skipping %s"%evfile
            continue
        tbegin = tmin if tmin > tstart else tstart
        tend   = tmax if tmax < tstop else tstop

        i += 1
        ltfile = join(workdir,'ltcube_%03i.fits'%i)
        select = join(workdir,'select_%03i.fits'%i)
        params = dict( evfile=evfile,
                       select=select,
                       ltfile=ltfile,
                       scfile=kwargs['scfile'],
                       tmin=tbegin, tmax=tend,
                       zmax=zmax
                       )
        print params
        select = """gtselect \
 infile=%(evfile)s \
 outfile=%(select)s \
 tmin=%(tmin)s tmax=%(tmax)s zmax=%(zmax)s \
 ra=0 dec=0 rad=180 emin=1 emax=1e6 \
 chatter=4 clobber=yes;
"""%params

        #### tmin and tmax ignored by ltcube ####
        ltcube = """gtltcube\
 evfile="%(select)s" \
 outfile="%(ltfile)s" \
 scfile="%(scfile)s" \
 dcostheta=0.025 binsz=1 \
 zmax=%(zmax)d tmin=%(tmin)d tmax=%(tmax)d \
 chatter=4 clobber=yes;
"""%params
        cmnd = select + '\n\n' + ltcube
        cmnds.append(cmnd)
        lst.append(ltfile)
    bsub(jobname,cmnds,logfile=None,q=queue,sleep=sleep)
    ltcube_lst = join(workdir,'ltcubes.lst')
    np.savetxt(ltcube_lst,lst,fmt="%s")

    #### Combine ltcubes ####
    depend = "done(%s)"%jobname
    jobname='merge.%s'%os.path.basename(workdir)
    script = join(workdir,'merge.py')
    params = dict( script = script,
                   workdir=workdir)
    #cmnd ="""python %(script)s; rm -rf %(workdir)s"""%params
    cmnd ="""python %(script)s"""%params

    open(script,'w').write("""\
from dsphs.utils.apps import gtltsumr;
import os
gtltsumr("@%s","%s")
""" % (ltcube_lst,kwargs['outfile']) )
    bsub(jobname,[cmnd],q=queue,w=depend)