Example #1
0
class SrcMapTask(Task):

    default_config = { 'scfile'  : None,
                       'expcube'  : None,
                       'bexpmap' : None,
                       'cmap'    : None,
                       'srcmdl'  : None,
                       'chatter' : 2,
                       'irfs'     : None,
                       'resample' : 'yes',
                       'rfactor'  : 2,
                       'minbinsz' : 0.1 }

    def __init__(self,outfile,config=None,**kwargs):
        super(SrcMapTask,self).__init__()
        self.update_default_config(SrcMapTask)
        self.configure(config,subsection='gtsrcmaps',**kwargs)
        
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)
        
        self._gtapp = GtApp('gtsrcmaps','Likelihood')

    def run_task(self):

        config = self.config
        outfile = os.path.basename(self._output_files[0])        
        self._gtapp.run(outfile=outfile,emapbnds='no',**config)
Example #2
0
 def FindSource(self):
     """Run the gtfindsrc tool"""
     outfile = utils._dump_findsrcout(self.Configuration)
     if (self.clobber == "no" and os.path.isfile(outfile)):
         #print("File exists and clobber is False")
         return (0)
     findsrc = GtApp('gtfindsrc', 'Likelihood')
     findsrc['evfile'] = self.mktimefile
     findsrc['scfile'] = self.ft2
     if self.irfs != 'CALDB':
         findsrc['evtype'] = self.Configuration['event']['evtype']
     else:
         findsrc['evtype'] = 'INDEF'
     findsrc['irfs'] = self.irfs
     findsrc['expcube'] = self.Cubename
     findsrc['expmap'] = self.Mapname
     findsrc['srcmdl'] = utils._dump_xml(self.Configuration)
     findsrc['coordsys'] = self.Configuration['space']['coordsys']
     findsrc['target'] = self.srcname
     findsrc['optimizer'] = self.Configuration["fitting"]["optimizer"]
     findsrc['ftol'] = self.Configuration["fitting"]["ftol"]
     findsrc['clobber'] = self.clobber
     findsrc['reopt'] = self.Configuration["findsrc"]["Refit"]
     findsrc['outfile'] = outfile
     findsrc.run()
Example #3
0
    def __init__(self, config=None, opts=None, **kwargs):
        super(ObsSimTask, self).__init__(config, opts=opts, **kwargs)

        #        self._outfile = os.path.abspath(outfile)
        #        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtobssim')
Example #4
0
class MkTimeTask(Task):

    default_config = {
        'roicut': 'no',
        'filter': 'IN_SAA!=T&&DATA_QUAL==1&&LAT_CONFIG==1&&ABS(ROCK_ANGLE)<52',
        'evfile': None,
        'scfile': None
    }

    def __init__(self, infile, outfile, config=None, **kwargs):
        super(MkTimeTask, self).__init__()
        self.update_default_config(MkTimeTask)
        self.configure(config, subsection='gtmktime', **kwargs)

        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtmktime', 'dataSubselector')

    def run_task(self):

        config = self.config

        outfile = os.path.basename(self._output_files[0])

        self._gtapp.run(evfile=self._infile,
                        outfile=outfile,
                        filter=config['filter'],
                        roicut=config['roicut'],
                        scfile=config['scfile'])
Example #5
0
 def FindSource(self):
     """Run the gtfindsrc tool"""
     outfile = utils._dump_findsrcout(self.Configuration)
     if (self.clobber=="no" and os.path.isfile(outfile)):
         #print("File exists and clobber is False")
         return(0)
     findsrc = GtApp('gtfindsrc', 'Likelihood')
     findsrc['evfile'] = self.mktimefile
     findsrc['scfile'] = self.ft2
     if  self.irfs != 'CALDB':
         findsrc['evtype']= self.Configuration['event']['evtype']
     else :
         findsrc['evtype']= 'INDEF'
     findsrc['irfs'] = self.irfs
     findsrc['expcube'] = self.Cubename
     findsrc['expmap'] = self.Mapname
     findsrc['srcmdl'] = utils._dump_xml( self.Configuration)
     findsrc['coordsys'] = self.Configuration['space']['coordsys']
     findsrc['target'] = self.srcname
     findsrc['optimizer'] = self.Configuration["fitting"]["optimizer"]
     findsrc['ftol'] = self.Configuration["fitting"]["ftol"]
     findsrc['clobber'] = self.clobber
     findsrc['reopt'] = self.Configuration["findsrc"]["Refit"]
     findsrc['outfile'] = outfile
     findsrc.run()
Example #6
0
class SrcModelTask(Task):

    default_config = {
        'srcmaps': None,
        'srcmdl': None,
        'expcube': None,
        'bexpmap': None,
        'srcmdl': None,
        'chatter': 2,
        'irfs': None,
        'outtype': 'ccube'
    }

    def __init__(self, outfile, config=None, opts=None, **kwargs):
        super(SrcModelTask, self).__init__(config, opts=opts, **kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtmodel')

    def run_task(self):

        outfile = os.path.basename(self._output_files[0])
        self._gtapp.run(outfile=outfile, **self.config)
Example #7
0
    def gtselect(self, phased, pulsarMode):
        if pulsarMode:
            if phased:
                phMin=self.phaseMin
                phMax=self.phaseMax
                outputFile = self.srcName+'_gti_'+self.phaseMin+'_'+self.phaseMax+'.fits'
                evfile=self.srcName+'_gti.fits'
                
            else:
                phMin=0 
                phMax=0
                evfile='@events.txt'
                outputFile = self.srcName+'_filtered.fits'
        else:
            outputFile = self.srcName+'_filtered.fits'
            evfile='@events.txt'
            phMin=0 
            phMax=0

        gtselect = GtApp('gtselect')
        gtselect.run(
            evclass=2,
            infile=evfile,
            outfile=outputFile,
            ra=self.RA,
            dec=self.DEC,
            rad=self.ROI,
            emin=self.EMIN,
            emax=self.EMAX,
            zmax=self.ZMAX,
            phasemin=phMin, 
            phasemax=phMax,
            tmin='0',
            tmax='0')
Example #8
0
 def gtexpcube2(self,mode):
     gtexpcube2 = GtApp('gtexpcube2')
     if mode=='_expcube_':
         nx=400
         ny=400
     elif mode=='_allsky_':
         nx=1800
         ny=900
     
     gtexpcube2.run(
         infile=self.srcName+'_ltcube_'+self.phaseMin+'_'+self.phaseMax+'.fits',
         outfile=self.srcName+mode+self.phaseMin+'_'+self.phaseMax+'.fits',
         cmap='none',
         irfs=self.irfs,
         nxpix=nx,
         nypix=ny,
         binsz='0.2',
         coordsys ='CEL',
         xref=self.RA,
         yref=self.DEC,
         axisrot='0',
         proj='AIT',
         emin=self.EMIN,
         emax=self.EMAX,
         enumbins=self.EBIN)
Example #9
0
class SrcModelTask(Task):

    default_config = {
        'srcmaps'    : None,
        'srcmdl'     : None,
        'expcube'    : None,
        'bexpmap'    : None,
        'srcmdl'     : None,
        'chatter'    : 2,
        'irfs'       : None,
        'outtype'    : 'ccube' }

    
    def __init__(self,outfile,config=None,opts=None,**kwargs):
        super(SrcModelTask,self).__init__(config,opts=opts,**kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)
        
        self._gtapp = GtApp('gtmodel')
    
    def run_task(self):

        outfile = os.path.basename(self._output_files[0])        
        self._gtapp.run(outfile=outfile,**self.config)
Example #10
0
class MkTimeTask(Task):

    default_config = { 'roicut' : 'no',
                       'filter' : 'IN_SAA!=T&&DATA_QUAL==1&&LAT_CONFIG==1&&ABS(ROCK_ANGLE)<52',
                       'evfile' : None,
                       'scfile' : None }               
    
    def __init__(self,infile,outfile,config=None,**kwargs):
        super(MkTimeTask,self).__init__()
        self.update_default_config(MkTimeTask)
        self.configure(config,subsection='gtmktime',**kwargs)

        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)
        
        self._gtapp=GtApp('gtmktime','dataSubselector')


    def run_task(self):
        
        config = self.config

        outfile = os.path.basename(self._output_files[0])
        
        self._gtapp.run(evfile=self._infile,
                        outfile=outfile,
                        filter=config['filter'],
                        roicut=config['roicut'],
                        scfile=config['scfile'])
Example #11
0
    def gtselect(self, phased, pulsarMode):
        if pulsarMode:
            if phased:
                phMin = self.phaseMin
                phMax = self.phaseMax
                outputFile = self.srcName + '_gti_' + self.phaseMin + '_' + self.phaseMax + '.fits'
                evfile = self.srcName + '_gti.fits'

            else:
                phMin = 0
                phMax = 0
                evfile = '@events.txt'
                outputFile = self.srcName + '_filtered.fits'
        else:
            outputFile = self.srcName + '_filtered.fits'
            evfile = '@events.txt'
            phMin = 0
            phMax = 0

        gtselect = GtApp('gtselect')
        gtselect.run(evclass=2,
                     infile=evfile,
                     outfile=outputFile,
                     ra=self.RA,
                     dec=self.DEC,
                     rad=self.ROI,
                     emin=self.EMIN,
                     emax=self.EMAX,
                     zmax=self.ZMAX,
                     phasemin=phMin,
                     phasemax=phMax,
                     tmin='0',
                     tmax='0')
Example #12
0
    def __init__(self, outfile, config=None, **kwargs):
        super(LTSumTask, self).__init__(config, **kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtltsum')
Example #13
0
    def gtexpcube2(self, mode):
        gtexpcube2 = GtApp('gtexpcube2')
        if mode == '_expcube_':
            nx = 400
            ny = 400
        elif mode == '_allsky_':
            nx = 1800
            ny = 900

        gtexpcube2.run(infile=self.srcName + '_ltcube_' + self.phaseMin + '_' +
                       self.phaseMax + '.fits',
                       outfile=self.srcName + mode + self.phaseMin + '_' +
                       self.phaseMax + '.fits',
                       cmap='none',
                       irfs=self.irfs,
                       nxpix=nx,
                       nypix=ny,
                       binsz='0.2',
                       coordsys='CEL',
                       xref=self.RA,
                       yref=self.DEC,
                       axisrot='0',
                       proj='AIT',
                       emin=self.EMIN,
                       emax=self.EMAX,
                       enumbins=self.EBIN)
Example #14
0
class LTCubeTask(Task):

    default_config = {
        'dcostheta': 0.025,
        'binsz': 1.0,
        'evfile': None,
        'scfile': (None, 'spacecraft file'),
        'tmin': 0.0,
        'tmax': 0.0,
        'zmax': (100.0, 'Set the maximum zenith angle.')
    }

    def __init__(self, outfile, config=None, opts=None, **kwargs):
        super(LTCubeTask, self).__init__(config, opts=opts, **kwargs)

        self._config['scfile'] = os.path.abspath(self._config['scfile'])

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtltcube')

    def run_task(self):

        outfile = os.path.basename(self._output_files[0])
        self._gtapp.run(outfile=outfile, **self.config)
Example #15
0
    def __init__(self, outfile, config=None, opts=None, **kwargs):
        super(SrcModelTask, self).__init__(config, opts=opts, **kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtmodel')
Example #16
0
class SrcMapTask(Task):

    default_config = {
        'scfile': None,
        'expcube': None,
        'bexpmap': None,
        'cmap': None,
        'srcmdl': None,
        'chatter': 2,
        'irfs': None,
        'resample': 'yes',
        'rfactor': 2,
        'minbinsz': 0.1
    }

    def __init__(self, outfile, config=None, **kwargs):
        super(SrcMapTask, self).__init__()
        self.configure(config, **kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtsrcmaps', 'Likelihood')

    def run_task(self):

        config = self.config
        outfile = os.path.basename(self._output_files[0])
        self._gtapp.run(outfile=outfile, emapbnds='no', **config)
Example #17
0
class BinTask(Task):

    default_config = {
        'nxpix': 140,
        'nypix': None,
        'xref': 0.0,
        'yref': 0.0,
        'emin': 1000.0,
        'emax': 100000.0,
        'scfile': None,
        'chatter': 2,
        'proj': 'AIT',
        'hpx_order': 3,
        'enumbins': 16,
        'algorithm': 'ccube',
        'binsz': 0.1,
        'coordsys': 'CEL'
    }

    def __init__(self, infile, outfile, config=None, opts=None, **kwargs):
        super(BinTask, self).__init__()
        self.configure(config, opts=opts, **kwargs)

        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        if re.search('^(?!\@)(.+)(\.txt|\.lst)$', self._infile):
            self._infile = '@' + self._infile

        self._gtbin = GtApp('gtbin', 'evtbin')

    def run_task(self):

        config = copy.deepcopy(self.config)

        outfile = os.path.basename(self._output_files[0])

        if config['nypix'] is None:
            config['nypix'] = config['nxpix']

        self._gtbin.run(algorithm=config['algorithm'],
                        nxpix=config['nxpix'],
                        nypix=config['nypix'],
                        binsz=config['binsz'],
                        hpx_order=config['hpx_order'],
                        evfile=self._infile,
                        outfile=outfile,
                        scfile=config['scfile'],
                        xref=config['xref'],
                        yref=config['yref'],
                        axisrot=0,
                        proj=config['proj'],
                        ebinalg='LOG',
                        emin=config['emin'],
                        emax=config['emax'],
                        enumbins=config['enumbins'],
                        coordsys=config['coordsys'],
                        chatter=config['chatter'])
Example #18
0
 def GtExposure(self):
     exposure = GtApp("gtexposure", "Likelihood")
     exposure["infile"] = self.lcfile
     exposure["scfile"] = self.ft2
     exposure["irfs"] = self.irfs
     exposure["srcmdl"] = "none"
     exposure["specin"] = -self.Configuration["AppLC"]["index"]
     exposure.run()
Example #19
0
 def gtltcube(self):
     gtltcube = GtApp('gtltcube')
     gtltcube.run(
         evfile =self.srcName+'_gti_'+self.phaseMin+'_'+self.phaseMax+'.fits',
         scfile =self.scfile,
         outfile =self.srcName+'_ltcube_'+self.phaseMin+'_'+self.phaseMax+'.fits',
         dcostheta = '0.025',
         binsz = '1')
Example #20
0
 def GtExposure(self):
     exposure = GtApp('gtexposure', 'Likelihood')
     exposure['infile'] = self.lcfile
     exposure['scfile'] = self.ft2
     exposure['irfs'] = self.irfs
     exposure['srcmdl'] = "none"
     exposure['specin'] = -self.Configuration['AppLC']['index']
     exposure.run()
Example #21
0
    def __init__(self, outfile, config=None, **kwargs):
        super(SrcMapTask, self).__init__()
        self.configure(config, **kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtsrcmaps', 'Likelihood')
Example #22
0
class BinTask(Task):

    default_config = { 'nxpix' : 140,
                       'nypix' : None,
                       'xref' : 0.0,
                       'yref' : 0.0,
                       'emin' : 1000.0,
                       'emax' : 100000.0,
                       'scfile' : None,
                       'chatter' : 2,
                       'proj' : 'AIT',
                       'hpx_order' : 3,
                       'enumbins' : 16,
                       'algorithm' : 'ccube',
                       'binsz' : 0.1,
                       'coordsys' : 'CEL'}
    
    def __init__(self,infile,outfile,config=None,opts=None,**kwargs):
        super(BinTask,self).__init__()
        self.configure(config,opts=opts,subsection='gtbin',**kwargs)
        
        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        if re.search('^(?!\@)(.+)(\.txt|\.lst)$',self._infile):
            self._infile = '@'+self._infile
        
        self._gtbin=GtApp('gtbin','evtbin')
        

    def run_task(self):

        config = copy.deepcopy(self.config)

        outfile = os.path.basename(self._output_files[0])

        if config['nypix'] is None:
            config['nypix'] = config['nxpix']
        
        self._gtbin.run(algorithm=config['algorithm'],
                        nxpix=config['nxpix'],
                        nypix=config['nypix'],
                        binsz=config['binsz'],
                        hpx_order=config['hpx_order'],
                        evfile=self._infile,
                        outfile=outfile,
                        scfile=config['scfile'],
                        xref=config['xref'],
                        yref=config['yref'],
                        axisrot=0,
                        proj=config['proj'],
                        ebinalg='LOG',
                        emin=config['emin'],
                        emax=config['emax'],
                        enumbins=config['enumbins'],
                        coordsys=config['coordsys'],
                        chatter=config['chatter'])
Example #23
0
 def GtBinDef(self,filename):
     if (self.clobber=="no" and os.path.isfile(self.BinDef)):
         #print("File exists and clobber is False")
         return(0)
     bindef = GtApp('gtbindef', 'Likelihood')
     bindef['bintype'] = 'T'
     bindef['binfile'] = filename
     bindef['outfile'] = self.BinDef
     bindef.run()
Example #24
0
 def gtltcube(self):
     gtltcube = GtApp('gtltcube')
     gtltcube.run(evfile=self.srcName + '_gti_' + self.phaseMin + '_' +
                  self.phaseMax + '.fits',
                  scfile=self.scfile,
                  outfile=self.srcName + '_ltcube_' + self.phaseMin + '_' +
                  self.phaseMax + '.fits',
                  dcostheta='0.025',
                  binsz='1')
Example #25
0
 def GtBinDef(self, filename):
     if (self.clobber == "no" and os.path.isfile(self.BinDef)):
         #print("File exists and clobber is False")
         return (0)
     bindef = GtApp('gtbindef', 'Likelihood')
     bindef['bintype'] = 'T'
     bindef['binfile'] = filename
     bindef['outfile'] = self.BinDef
     bindef.run()
Example #26
0
 def GtExposure(self):
     exposure = GtApp('gtexposure', 'Likelihood')
     exposure['infile'] = self.lcfile
     exposure['scfile'] = self.ft2
     exposure['irfs'] = self.irfs
     exposure['srcmdl'] = "none"
     exposure['specin'] = -self.Configuration['AppLC']['index']
     exposure['clobber'] = self.clobber
     exposure.run()
Example #27
0
    def __init__(self, outfile, config=None, opts=None, **kwargs):
        super(LTCubeTask, self).__init__(config, opts=opts, **kwargs)

        self._config['scfile'] = os.path.abspath(self._config['scfile'])

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtltcube')
Example #28
0
class SelectorTask(Task):

    default_config = {
        'ra': 0.0,
        'dec': 0.0,
        'radius': 180.0,
        'tmin': 0.0,
        'tmax': 0.0,
        'zmax': 100.,
        'emin': 10.,
        'emax': 1000000.,
        'chatter': 2,
        'evclsmin': 'INDEF',
        'evclass': 'INDEF',
        'evtype': 'INDEF',
        'convtype': -1
    }

    def __init__(self, infile, outfile, config=None, opts=None, **kwargs):
        super(SelectorTask, self).__init__()
        self.configure(config, opts=opts, **kwargs)

        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        #        if re.search('^(?!\@)(.+)\.txt$',self._infile):
        if re.search('^(?!\@)(.+)(\.txt|\.lst)$', self._infile):
            self._infile = '@' + self._infile

        self._gtselect = GtApp('gtselect', 'dataSubselector')

    def run_task(self):

        config = self.config

        outfile = os.path.basename(self._output_files[0])

        #        print self._infile
        #        os.system('cat ' + self._infile[1:])

        self._gtselect.run(
            infile=self._infile,
            outfile=outfile,
            ra=config['ra'],
            dec=config['dec'],
            rad=config['radius'],
            tmin=config['tmin'],
            tmax=config['tmax'],
            emin=config['emin'],
            emax=config['emax'],
            zmax=config['zmax'],
            chatter=config['chatter'],
            evclass=config['evclass'],  # Only for Pass7
            evtype=config['evtype'],
            convtype=config['convtype'])  # Only for Pass6
Example #29
0
 def GtBinnedMap(self):
     """Run the gtexpcube2 tool for binned analysis"""
     expcube2 = GtApp("gtexpcube2", "Likelihood")
     expcube2["infile"] = self.Cubename
     expcube2["outfile"] = self.BinnedMapfile
     expcube2["cmap"] = self.ccube
     expcube2["irfs"] = self.irfs
     expcube2["emin"] = self.Emin
     expcube2["emax"] = self.Emax
     expcube2.run()
Example #30
0
    def __init__(self, infile, outfile, config=None, **kwargs):
        super(MkTimeTask, self).__init__()
        self.update_default_config(MkTimeTask)
        self.configure(config, subsection='gtmktime', **kwargs)

        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtmktime', 'dataSubselector')
Example #31
0
 def GtBinnedMap(self):
     """Run the gtexpcube2 tool for binned analysis"""
     expcube2 = GtApp('gtexpcube2', 'Likelihood')
     expcube2['infile'] = self.Cubename
     expcube2['outfile'] = self.BinnedMapfile
     expcube2['cmap'] = self.ccube
     expcube2['irfs'] = self.irfs
     expcube2['emin'] = self.Emin
     expcube2['emax'] = self.Emax
     expcube2.run()
Example #32
0
 def gtpphase(self, ephemeris, srcName, pulsarMode):
     if pulsarMode:
         gtpphase = GtApp('gtpphase')
         gtpphase.run(chatter='4',
                      evfile=self.srcName + '_gti.fits',
                      scfile=self.scfile,
                      psrdbfile=ephemeris,
                      psrname=srcName,
                      ephstyle='DB',
                      solareph='JPL DE200')
Example #33
0
 def gtpphase(self, ephemeris, srcName, pulsarMode):
     if pulsarMode:
         gtpphase = GtApp('gtpphase')
         gtpphase.run(
             chatter='4',
             evfile=self.srcName+'_gti.fits',
             scfile=self.scfile,
             psrdbfile=ephemeris,
             psrname=srcName,
             ephstyle='DB',
             solareph='JPL DE200')
Example #34
0
 def SrcProb(self):
     """Run the gtsrcprob tool"""
     srcprob = GtApp('gtsrcprob', 'Likelihood')
     srcprob['evfile'] = self.eventfile
     srcprob['scfile'] = self.ft2
     srcprob['irfs'] = self.irfs
     srcprob['srcmdl'] = self.xmlfile
     srcprob['outfile'] = self.Probfile
     srcprob['srclist'] = self.Configuration['srcprob']['srclist']
     srcprob['clobber'] = self.clobber
     srcprob.run()
Example #35
0
 def GtBinnedMap(self):
     """Run the gtexpcube2 tool for binned analysis"""
     expcube2 = GtApp('gtexpcube2', 'Likelihood')
     expcube2['infile'] = self.Cubename
     expcube2['outfile'] = self.BinnedMapfile
     expcube2['cmap'] = self.ccube
     expcube2['irfs'] = self.irfs
     expcube2['emin'] = self.Emin
     expcube2['emax'] = self.Emax
     expcube2['clobber'] = self.clobber
     expcube2.run()
Example #36
0
 def gtsrcmaps(self, model):
     gtsrcmaps = GtApp('gtsrcmaps')
     gtsrcmaps.run(
         scfile=self.scfile,
         expcube=self.srcName+'_ltcube_'+self.phaseMin+'_'+self.phaseMax+'.fits',
         cmap=self.srcName+'_ccube_'+self.phaseMin+'_'+self.phaseMax+'.fits',
         srcmdl=model,
         bexpmap=self.srcName+'_allsky_'+self.phaseMin+'_'+self.phaseMax+'.fits',
         outfile=self.srcName+'_scrmap_'+self.phaseMin+'_'+self.phaseMax+'.fits',
         irfs=self.irfs,
         chatter='4',
         emapbnds="no")
Example #37
0
    def __init__(self, infile, outfile, config=None, opts=None, **kwargs):
        super(BinTask, self).__init__()
        self.configure(config, opts=opts, **kwargs)

        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        if re.search('^(?!\@)(.+)(\.txt|\.lst)$', self._infile):
            self._infile = '@' + self._infile

        self._gtbin = GtApp('gtbin', 'evtbin')
Example #38
0
 def GtExposure(self):
     exposure = GtApp('gtexposure', 'Likelihood')
     exposure['infile'] = self.lcfile
     exposure['scfile'] = self.ft2
     exposure['target'] = self.srcname
     if  self.Configuration['event']['irfs'] != 'CALDB':
         exposure['evtype']= self.Configuration['event']['evtype'] 
     exposure['irfs'] = self.irfs
     exposure['srcmdl'] = "none"
     exposure['specin'] = -self.Configuration['AppLC']['index']
     exposure['clobber'] = self.clobber
     exposure.run()
Example #39
0
    def __init__(self, infile, outfile, config=None, opts=None, **kwargs):
        super(SelectorTask, self).__init__()
        self.configure(config, opts=opts, **kwargs)

        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        #        if re.search('^(?!\@)(.+)\.txt$',self._infile):
        if re.search('^(?!\@)(.+)(\.txt|\.lst)$', self._infile):
            self._infile = '@' + self._infile

        self._gtselect = GtApp('gtselect', 'dataSubselector')
Example #40
0
 def GtBinnedMap(self):
     """Run the gtexpcube2 tool for binned analysis"""
     expcube2 = GtApp('gtexpcube2', 'Likelihood')
     expcube2['infile'] = self.Cubename
     expcube2['outfile'] = self.BinnedMapfile
     expcube2['cmap'] = self.ccube
     expcube2['irfs'] = self.irfs
     expcube2['emin'] = self.Emin
     expcube2['emax'] = self.Emax
     expcube2['coordsys'] = self.Configuration['space']['coordsys']
     expcube2['proj'] = self.Configuration['space']['proj'] #"AIT"
     expcube2['clobber'] = self.clobber
     expcube2.run()
def merge_LAT_data(ft1s,
                   destination_directory: str = ".",
                   outfile: str = 'ft1_merged.fits',
                   Emin: float = 30.0,
                   Emax: float = 1e6) -> Path:

    outfile: Path = Path(destination_directory) / outfile

    if outfile.exists():
        log.warning(
            f"Existing merged event file {outfile} correspond to the same selection. "
            "We assume you did not tamper with it, so we will return it instead of merging it again. "
            "If you want to redo the FT1 file again, remove it from the outdir"
        )
        return outfile

    if len(ft1s) == 1:

        log.warning('Only one FT1 file provided. Skipping the merge...')
        import shutil

        shutil.copyfile(ft1s[0], outfile)
        return outfile

    _filelist = "_filelist.txt"

    infile: Path = Path(destination_directory) / _filelist

    infile_list = infile.open('w')

    for ft1 in ft1s:
        infile_list.write(str(ft1) + '\n')

    infile_list.close()

    from GtApp import GtApp

    gtselect = GtApp('gtselect')

    gtselect['infile'] = '@' + str(infile)
    gtselect['outfile'] = str(outfile)
    gtselect['ra'] = 'INDEF'
    gtselect['dec'] = 'INDEF'
    gtselect['rad'] = 'INDEF'
    gtselect['tmin'] = 'INDEF'
    gtselect['tmax'] = 'INDEF'
    gtselect['emin'] = '%.3f' % Emin
    gtselect['emax'] = '%.3f' % Emax
    gtselect['zmax'] = 180
    gtselect.run()
    return outfile
Example #42
0
class SelectorTask(Task):

    default_config = { 'ra' : 0.0,
                       'dec' : 0.0,
                       'radius' : 180.0,
                       'tmin' : 0.0,
                       'tmax' : 0.0,
                       'zmax' : 100.,
                       'emin' : 10.,
                       'emax' : 1000000.,
                       'chatter' : 2,
                       'evclsmin' : 'INDEF',
                       'evclass' : 'INDEF',
                       'evtype'  : 'INDEF',
                       'convtype' : -1 }               
    
    def __init__(self,infile,outfile,config=None,opts=None,**kwargs):
        super(SelectorTask,self).__init__()        
        self.configure(config,opts=opts,**kwargs)
        
        self._infile = os.path.abspath(infile)
        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

#        if re.search('^(?!\@)(.+)\.txt$',self._infile):
        if re.search('^(?!\@)(.+)(\.txt|\.lst)$',self._infile):
            self._infile = '@'+self._infile
            
        self._gtselect=GtApp('gtselect','dataSubselector')


    def run_task(self):
        
        config = self.config

        outfile = os.path.basename(self._output_files[0])


#        print self._infile
#        os.system('cat ' + self._infile[1:])
        
        self._gtselect.run(infile=self._infile,
                           outfile=outfile,
                           ra=config['ra'], dec=config['dec'], 
                           rad=config['radius'],
                           tmin=config['tmin'], tmax=config['tmax'],
                           emin=config['emin'], emax=config['emax'],
                           zmax=config['zmax'], chatter=config['chatter'],
                           evclass=config['evclass'],   # Only for Pass7
                           evtype=config['evtype'],
                           convtype=config['convtype']) # Only for Pass6
Example #43
0
    def gtmktime(self, pulsarMode):

        if pulsarMode:
            outputFile = self.srcName + '_filtered.fits'
        else:
            outputFile = self.srcName + '_gti_' + self.phaseMin + '_' + self.phaseMax + '.fits'

        gtmktime = GtApp('gtmktime')
        gtmktime.run(
            scfile=self.scfile,
            evfile=self.srcName + '_filtered.fits',
            outfile=outputFile,
            filter='DATA_QUAL==1 && LAT_CONFIG==1 && ABS(ROCK_ANGLE)<52',
            roicut='yes')
Example #44
0
 def _gtbin_lc(self, dtime):
     from GtApp import GtApp
     gtbin = GtApp('gtbin')
     gtbin['algorithm'] = 'LC'
     gtbin['tbinalg'] = 'LIN'
     gtbin['evfile'] = self.ft1File
     gtbin['outfile'] = 'lc.fits'
     gtbin['tstart'] = self.tstart
     gtbin['tstop'] = self.tstop
     gtbin['dtime'] = dtime
     gtbin['chatter'] = 0
     gtbin.run()
     lc = FitsNTuple('lc.fits', 'RATE')
     return lc.COUNTS
Example #45
0
    def gtmktime(self, pulsarMode):
        
        if pulsarMode:
            outputFile=self.srcName+'_filtered.fits'
        else:
            outputFile = self.srcName+'_gti_'+self.phaseMin+'_'+self.phaseMax+'.fits'

        gtmktime = GtApp('gtmktime')
        gtmktime.run(
            scfile=self.scfile,
            evfile=self.srcName+'_filtered.fits',
            outfile=outputFile,
            filter='DATA_QUAL==1 && LAT_CONFIG==1 && ABS(ROCK_ANGLE)<52',
            roicut='yes')
Example #46
0
 def GtPSF(self):
     Nbdecade = log10(self.Emax)-log10(self.Emin)#Compute the number of decade
     irfs,_ = utils.GetIRFS(self.Configuration['event']['evclass'],self.Configuration['event']['evtype'])
     psf = GtApp('gtpsf', 'Likelihood')
     psf["expcube"] = self.Cubename
     psf["outfile"] = self.psf
     psf["irfs"]    = irfs
     psf["evtype"]  = self.Configuration['event']['evtype']
     psf["ra"]      = self.ra 
     psf["dec"]     = self.dec
     psf["emin"]    = self.Emin
     psf["emax"]    = self.Emax
     psf["nenergies"] = int(Nbdecade*self.Configuration['energy']['enumbins_per_decade'])
     psf["thetamax"] = 5.
     psf.run()
Example #47
0
 def gtsrcmaps(self, model):
     gtsrcmaps = GtApp('gtsrcmaps')
     gtsrcmaps.run(scfile=self.scfile,
                   expcube=self.srcName + '_ltcube_' + self.phaseMin + '_' +
                   self.phaseMax + '.fits',
                   cmap=self.srcName + '_ccube_' + self.phaseMin + '_' +
                   self.phaseMax + '.fits',
                   srcmdl=model,
                   bexpmap=self.srcName + '_allsky_' + self.phaseMin + '_' +
                   self.phaseMax + '.fits',
                   outfile=self.srcName + '_scrmap_' + self.phaseMin + '_' +
                   self.phaseMax + '.fits',
                   irfs=self.irfs,
                   chatter='4',
                   emapbnds="no")
Example #48
0
 def SrcProb(self):
     """Run the gtsrcprob tool"""
     srcprob = GtApp('gtsrcprob', 'Likelihood')
     srcprob['evfile'] = self.eventfile
     srcprob['scfile'] = self.ft2
     if self.Configuration['event']['irfs'] != 'CALDB':
         srcprob['evtype'] = self.Configuration['event']['evtype']
     else:
         srcprob['evtype'] = 'INDEF'
     srcprob['irfs'] = self.irfs
     srcprob['srcmdl'] = self.xmlfile
     srcprob['outfile'] = self.Probfile
     srcprob['srclist'] = self.Configuration['srcprob']['srclist']
     srcprob['clobber'] = self.clobber
     srcprob.run()
Example #49
0
def remote_gtselect():
    gtsel=GtApp('gtselect')
    outs=[]
    for type_name,type_bit  in evt_info:
        out = outbase + '_%s.fits'%type_name
        outs+=[out]
        
        if not os.access(out,os.F_OK):
            print 'Selecting %s %s events from %s, saving as %s.'%(evclass,type_name,ev,out)
            gtsel.run(infile=ev, outfile=out, ra=0.0,dec=0.0,\
                          rad=180., tmin=0., tmax=0., emin=0.,emax=0.,\
                          zmin=0.,zmax=0.,evclass=evclass,evtype=type_bit)
        else:
            print 'File %s already exists, skipping gtselect for %s.'%(out, ev)
    return
Example #50
0
class LTSumTask(Task):

    default_config = { 'infile1' : None }

    def __init__(self,outfile,config=None,**kwargs):
        super(LTSumTask,self).__init__(config,**kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)
        
        self._gtapp = GtApp('gtltsum')
    
    def run_task(self):

        outfile = os.path.basename(self._output_files[0])        
        self._gtapp.run(outfile=outfile,**self.config)
Example #51
0
class LTSumTask(Task):

    default_config = {'infile1': None}

    def __init__(self, outfile, config=None, **kwargs):
        super(LTSumTask, self).__init__(config, **kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtltsum')

    def run_task(self):

        outfile = os.path.basename(self._output_files[0])
        self._gtapp.run(outfile=outfile, **self.config)
Example #52
0
    def __init__(self,outfile,config=None,**kwargs):
        super(LTSumTask,self).__init__(config,**kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)
        
        self._gtapp = GtApp('gtltsum')
Example #53
0
    def __init__(self,outfile,config=None,opts=None,**kwargs):
        super(SrcModelTask,self).__init__(config,opts=opts,**kwargs)

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)
        
        self._gtapp = GtApp('gtmodel')
Example #54
0
    def __init__(self, outfile, config=None, **kwargs):
        super(BExpTask, self).__init__()
        self.configure(config, **kwargs)

        if self.config['allsky']:
            self.set_config('nxpix', 360)
            self.set_config('nypix', 180)
            self.set_config('xref', 0.0)
            self.set_config('yref', 0.0)
            self.set_config('binsz', 1.0)
            self.set_config('proj', 'CAR')

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtexpcube2')
Example #55
0
    def __init__(self,config=None,opts=None,**kwargs):
        super(ObsSimTask,self).__init__(config,opts=opts,**kwargs)

#        self._outfile = os.path.abspath(outfile)
#        self.register_output_file(self._outfile)
        
        self._gtapp = GtApp('gtobssim')
Example #56
0
def makeExpMaps(likeIn):
	gtexpmap=GtApp('gtexpmap') #note, checks for existence of band expMaps, won't overwrite
	Src=likeIn.source
	NBins=likeIn.NBins
	IRFs=likeIn.IRFs
	ft2=likeIn.ft2
	expCube=likeIn.expCube
	radius=likeIn.ft1ROI[2]+10.
	for i in range(0,likeIn.nbins):
		ev='%s_%ibins_band%i.fits' %(Src.replace(' ','_'),NBins,i)
		out='%s_%ibins_band%i_%s_em.fits' %(Src.replace(' ','_'),NBins,i,IRFs) #add IRFs name to file to be specific
		if(not os.access(out,os.F_OK)):
			gtexpmap.run(evfile=ev,scfile=ft2,expcube=expCube,outfile=out, irfs=IRFs,srcrad=radius,nlong=120,nlat=120,nenergies=20,chatter=0)
		else:
			print '  -%s' %out,'already exists, skipping gtexpmap for this energy band.-'
	return 
Example #57
0
def makeFT1Bands(likeIn,evmin,evmax,evclass):
	gtselect=GtApp('gtselect') #note, checks for existence of ft1 bands, if found won't remake 
	Src=likeIn.source
	NBins=likeIn.NBins
	ft1=likeIn.ft1
	ebins=likeIn.bins
	for i in range(0,likeIn.nbins):
		out='%s_%ibins_band%i.fits' %(Src.replace(' ','_'),NBins,i) #ft1 has name of source and number of bins to be specific about what was done
		if(not os.access(out,os.F_OK)):
			if evclass==None:
				gtselect.run(infile=ft1,outfile=out,ra=0,dec=0,rad=180,tmin=0,tmax=0,emin=ebins[0][i],emax=ebins[1][i],evclsmin=evmin,evclsmax=evmax,zmax=0,chatter=0) #zmax=0 makes no zenith selection
			else:
				gtselect.run(infile=ft1,outfile=out,ra=0,dec=0,rad=180,tmin=0,tmax=0,emin=ebins[0][i],emax=ebins[1][i],evclass=evclass,zmax=0,chatter=0)
		else:
			print '  -%s' %out,'already exists, skipping gtselect for this energy band.-'
	return
Example #58
0
 def GtBinnedMap(self):
     """Run the gtexpcube2 tool for binned analysis"""
     Nbdecade = log10(self.Emax)-log10(self.Emin)#Compute the number of decade
     expcube2 = GtApp('gtexpcube2', 'Likelihood')
     expcube2['infile'] = self.Cubename
     expcube2['outfile'] = self.BinnedMapfile
     expcube2['cmap'] = self.ccube
     if  self.Configuration['event']['irfs'] != 'CALDB':
         expcube2['evtype']= self.Configuration['event']['evtype'] 
     expcube2['irfs'] = self.irfs
     expcube2['emin'] = self.Emin
     expcube2['emax'] = self.Emax
     expcube2['enumbins'] = int(Nbdecade*self.Configuration['energy']['enumbins_per_decade'])
     expcube2['coordsys'] = self.Configuration['space']['coordsys']
     expcube2['proj'] = self.Configuration['space']['proj'] #"AIT"
     expcube2['clobber'] = self.clobber
     expcube2.run()
Example #59
0
 def FindSource(self):
     """Run the gtfindsrc tool"""
     findsrc = GtApp('gtfindsrc', 'Likelihood')
     findsrc['evfile'] = self.eventfile
     findsrc['scfile'] = self.ft2
     findsrc['irfs'] = self.irfs
     findsrc['expcube'] = self.Cubename
     findsrc['expmap'] = self.Mapname
     findsrc['srcmdl'] = utils._dump_xml( self.Configuration)
     findsrc['coordsys'] = self.Configuration['space']['coordsys']
     findsrc['target'] = self.srcname
     findsrc['optimizer'] = self.Configuration["fitting"]["optimizer"]
     findsrc['ftol'] = self.Configuration["fitting"]["ftol"]
     findsrc['clobber'] = self.clobber
     findsrc['reopt'] = self.Configuration["findsrc"]["Refit"]
     findsrc['outfile'] = utils._dump_findsrcout(self.Configuration)
     findsrc.run()
Example #60
0
class BExpTask(Task):

    default_config = {
        'nxpix': 360.,
        'nypix': 180.,
        'allsky': True,
        'xref': 0.0,
        'yref': 0.0,
        'emin': 1000.0,
        'emax': 100000.0,
        'chatter': 2,
        'proj': 'CAR',
        'enumbins': 16,
        'infile': None,
        'irfs': None,
        'evtype': None,
        'cmap': 'none',
        'coordsys': 'CEL',
        'ebinalg': 'LOG',
        'binsz': 1.0
    }

    def __init__(self, outfile, config=None, **kwargs):
        super(BExpTask, self).__init__()
        self.configure(config, **kwargs)

        if self.config['allsky']:
            self.set_config('nxpix', 360)
            self.set_config('nypix', 180)
            self.set_config('xref', 0.0)
            self.set_config('yref', 0.0)
            self.set_config('binsz', 1.0)
            self.set_config('proj', 'CAR')

        self._outfile = os.path.abspath(outfile)
        self.register_output_file(self._outfile)

        self._gtapp = GtApp('gtexpcube2')

    def run_task(self):

        config = copy.deepcopy(self.config)
        del (config['allsky'])
        outfile = os.path.basename(self._output_files[0])
        self._gtapp.run(outfile=outfile, **config)