def runSrcMaps(self, run=True):

        """Generates a source map for your region.  Checks to make
        sure that there's an XML model to be had and if not, creates
        one from the 2FGL."""

        self.generateXMLmodel()

        try:
            qU.checkForFiles(self.logger,[self.commonConf['base']+"_CCUBE.fits",
                                       self.commonConf['base']+"_ltcube.fits",
                                       self.commonConf['base']+"_BinnedExpMap.fits",
                                       self.commonConf['base']+"_SC.fits",])
        except(qU.FileNotFound):
            self.logger.critical("One or more needed files do not exist")
            sys.exit()

        srcMaps['scfile'] = self.commonConf['base']+"_SC.fits"
        srcMaps['expcube'] = self.commonConf['base']+"_ltcube.fits"
        srcMaps['cmap'] = self.commonConf['base']+"_CCUBE.fits"
        srcMaps['srcmdl'] = self.commonConf['base']+"_model.xml"
        srcMaps['bexpmap'] = self.commonConf['base']+"_BinnedExpMap.fits"
        srcMaps['outfile'] = self.commonConf['base']+"_srcMaps.fits"
        srcMaps['irfs'] = self.commonConf['irfs']
        srcMaps['rfactor'] = 4
        srcMaps['emapbnds'] = "yes"

        qU.runCommand(srcMaps,self.logger,run)
    def runSelect(self,run = True,printCmd=False, **kwargs):

        """Runs gtselect on the data using the initialization
        parameters. User selected parameters include the conversion
        type and the eventclass."""

        filter['rad'] = self.analysisConf['rad']
        filter['evclass'] = self.commonConf['eventclass']
        filter['evclsmin'] = 0
        filter['evclsmax'] = 10
        filter['infile'] = "@"+self.commonConf['base']+".list"
        filter['outfile'] = self.commonConf['base']+"_filtered.fits"
        filter['ra'] = self.analysisConf['ra']
        filter['dec'] = self.analysisConf['dec']
        filter['tmin'] = self.analysisConf['tmin']
        filter['tmax'] = self.analysisConf['tmax']
        filter['emin'] = self.analysisConf['emin']
        filter['emax'] = self.analysisConf['emax']
        filter['zmax'] = self.analysisConf['zmax']
        filter['convtype'] = self.analysisConf['convtype']

        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            filter[name] = value

        qU.runCommand(filter,self.logger,run,printCmd)
    def runExpMap(self, run=True):

        """Generates an exposure map that is 10 degrees larger than
        the ROI and has 120 pixels in each direction."""

        expMap['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        expMap['scfile'] = self.commonConf['base']+'_SC.fits'
        expMap['expcube'] = self.commonConf['base']+'_ltcube.fits'
        expMap['outfile'] = self.commonConf['base']+'_expMap.fits'
        expMap['irfs'] = self.commonConf['irfs']
        expMap['srcrad'] = float(self.analysisConf['rad']) + 10.
        expMap['nlong'] = 120
        expMap['nlat'] = 120
        expMap['nenergies'] = 20

        np = int(self.commonConf['multicore'])
        
        if(np > 0):
            import gtexpmap_mp as expmp
            expmp.gtexpmap_mp(expMap['nlong'],expMap['nlat'],np,1,
                              expMap['scfile'],expMap['evfile'],expMap['expcube'], 
                              expMap['irfs'],expMap['srcrad'],expMap['nenergies'],
                              expMap['outfile'],False)
        else:
            qU.runCommand(expMap,self.logger,run)
    def runSelect(self,run = True,printCmd=False, **kwargs):

        """Runs gtselect on the data using the initialization
        parameters. User selected parameters include the conversion
        type and the eventclass."""

        filter['rad'] = self.analysisConf['rad']
        filter['evclass'] = self.commonConf['eventclass']
        filter['evclsmin'] = 0
        filter['evclsmax'] = 10
        filter['infile'] = "@"+self.commonConf['base']+".list"
        filter['outfile'] = self.commonConf['base']+"_filtered.fits"
        filter['ra'] = self.analysisConf['ra']
        filter['dec'] = self.analysisConf['dec']
        filter['tmin'] = self.analysisConf['tmin']
        filter['tmax'] = self.analysisConf['tmax']
        filter['emin'] = self.analysisConf['emin']
        filter['emax'] = self.analysisConf['emax']
        filter['zmax'] = self.analysisConf['zmax']
        filter['convtype'] = self.analysisConf['convtype']

        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            filter[name] = value

        qU.runCommand(filter,self.logger,run,printCmd)
    def runExpMap(self, run=True, **kwargs):

        """Generates an exposure map that is 10 degrees larger than
        the ROI and has 120 pixels in each direction."""

        expMap['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        expMap['scfile'] = self.commonConf['base']+'_SC.fits'
        expMap['expcube'] = self.commonConf['base']+'_ltcube.fits'
        expMap['outfile'] = self.commonConf['base']+'_expMap.fits'
        expMap['irfs'] = self.commonConf['irfs']
        expMap['srcrad'] = float(self.analysisConf['rad']) + 10.
        expMap['nlong'] = 120
        expMap['nlat'] = 120
        expMap['nenergies'] = 20

        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            expMap[name] = value

        np = int(self.commonConf['multicore'])
        
        if(np > 0):
            import gtexpmap_mp as expmp
            expmp.gtexpmap_mp(expMap['nlong'],expMap['nlat'],np,1,
                              expMap['scfile'],expMap['evfile'],expMap['expcube'], 
                              expMap['irfs'],expMap['srcrad'],expMap['nenergies'],
                              expMap['outfile'],False)
        else:
            qU.runCommand(expMap,self.logger,run)
    def runSrcMaps(self, run=True, makeModel=True, **kwargs):

        """Generates a source map for your region.  Checks to make
        sure that there's an XML model to be had and if not, creates
        one from the 2FGL."""

	if makeModel:
		self.generateXMLmodel()
	"""
	# This clashes with quickCurve. If you want this functionality back, put it in runAll() and the cli

        try:
            qU.checkForFiles(self.logger,[self.commonConf['base']+"_CCUBE.fits",
                                       self.commonConf['base']+"_ltcube.fits",
                                       self.commonConf['base']+"_BinnedExpMap.fits",
                                       self.commonConf['base']+"_SC.fits",])
        except(qU.FileNotFound):
            self.logger.critical("One or more needed files do not exist")
            sys.exit()"""

        srcMaps['scfile'] = self.commonConf['base']+"_SC.fits"
        srcMaps['expcube'] = self.commonConf['base']+"_ltcube.fits"
        srcMaps['cmap'] = self.commonConf['base']+"_CCUBE.fits"
        srcMaps['srcmdl'] = self.commonConf['base']+"_model.xml"
        srcMaps['bexpmap'] = self.commonConf['base']+"_BinnedExpMap.fits"
        srcMaps['outfile'] = self.commonConf['base']+"_srcMaps.fits"
        srcMaps['irfs'] = self.commonConf['irfs']
        srcMaps['rfactor'] = 4
        srcMaps['emapbnds'] = "yes"

	#Override settings from kwargs if they exist
	for name, value in kwargs.items():
		srcMaps[name] = value

        qU.runCommand(srcMaps,self.logger,run)
    def runSrcMaps(self, run=True):

        """Generates a source map for your region.  Checks to make
        sure that there's an XML model to be had and if not, creates
        one from the 2FGL."""

        self.generateXMLmodel()

        try:
            qU.checkForFiles(self.logger,[self.commonConf['base']+"_CCUBE.fits",
                                       self.commonConf['base']+"_ltcube.fits",
                                       self.commonConf['base']+"_BinnedExpMap.fits",
                                       self.commonConf['base']+"_SC.fits",])
        except(qU.FileNotFound):
            self.logger.critical("One or more needed files do not exist")
            sys.exit()

        srcMaps['scfile'] = self.commonConf['base']+"_SC.fits"
        srcMaps['expcube'] = self.commonConf['base']+"_ltcube.fits"
        srcMaps['cmap'] = self.commonConf['base']+"_CCUBE.fits"
        srcMaps['srcmdl'] = self.commonConf['base']+"_model.xml"
        srcMaps['bexpmap'] = self.commonConf['base']+"_BinnedExpMap.fits"
        srcMaps['outfile'] = self.commonConf['base']+"_srcMaps.fits"
        srcMaps['irfs'] = self.commonConf['irfs']
        srcMaps['rfactor'] = 4
        srcMaps['emapbnds'] = "yes"

        qU.runCommand(srcMaps,self.logger,run)
    def runCCUBE(self, run=True,nbins=30):

        """Generates a counts cube.  The dimensions of which are the
        largest square subtended by the ROI.  Note that if the ROI is
        exceptionally small or the bin size exceptionally large, the
        square might not be the largest posible since the npix
        calculation floors the calculated value.  The number of energy
        bins is logarithmic and is defined by the nbins variable."""
        
        if nxpix < 0 or nypix < 0:
            nxpix = NumberOfPixels(float(rad),float(binsize))
            nypix = NumberOfPixels(float(rad),float(binsize))
        
        evtbin['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        evtbin['outfile'] = self.commonConf['base']+'_CCUBE.fits'
        evtbin['algorithm'] = 'CCUBE'
        evtbin['nxpix'] = self.analysisConf['nxpix']
        evtbin['nypix'] = self.analysisConf['nypix']
        evtbin['binsz'] = self.analysisConf['binsize']
        evtbin['coordsys'] = 'CEL'
        evtbin['xref'] = self.analysisConf['ra']
        evtbin['yref'] = self.analysisConf['dec']
        evtbin['axisrot'] = 0
        evtbin['proj'] = 'AIT'
        evtbin['ebinalg'] = 'LOG'
        evtbin['emin'] = self.analysisConf['emin']
        evtbin['emax'] = self.analysisConf['emax']
        evtbin['enumbins'] = nbins
        evtbin['scfile'] = self.commonConf['base']+"_SC.fits"

        qU.runCommand(evtbin,self.logger,run)
    def runCCUBE(self, run=True,nbins=30):

        """Generates a counts cube.  The dimensions of which are the
        largest square subtended by the ROI.  Note that if the ROI is
        exceptionally small or the bin size exceptionally large, the
        square might not be the largest posible since the npix
        calculation floors the calculated value.  The number of energy
        bins is logarithmic and is defined by the nbins variable."""
    
        if float(self.analysisConf['nxpix']) < 0 or float(self.analysisConf['nypix']) < 0:
            self.logger.info("Autocalculating nxpix and nypix.")
            self.analysisConf['nxpix'] = qU.NumberOfPixels(float(self.analysisConf['rad']),
                                                           float(self.analysisConf['binsize']))
            self.analysisConf['nypix'] = self.analysisConf['nxpix']
            print self.analysisConf['nypix']
            

        evtbin['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        evtbin['outfile'] = self.commonConf['base']+'_CCUBE.fits'
        evtbin['algorithm'] = 'CCUBE'
        evtbin['nxpix'] = self.analysisConf['nxpix']
        evtbin['nypix'] = self.analysisConf['nypix']
        evtbin['binsz'] = self.analysisConf['binsize']
        evtbin['coordsys'] = 'CEL'
        evtbin['xref'] = self.analysisConf['ra']
        evtbin['yref'] = self.analysisConf['dec']
        evtbin['axisrot'] = 0
        evtbin['proj'] = 'AIT'
        evtbin['ebinalg'] = 'LOG'
        evtbin['emin'] = self.analysisConf['emin']
        evtbin['emax'] = self.analysisConf['emax']
        evtbin['enumbins'] = nbins
        evtbin['scfile'] = self.commonConf['base']+"_SC.fits"

        qU.runCommand(evtbin,self.logger,run)
    def runExpMap(self, run=True, **kwargs):

        """Generates an exposure map that is 10 degrees larger than
        the ROI and has 120 pixels in each direction."""

        expMap['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        expMap['scfile'] = self.commonConf['base']+'_SC.fits'
        expMap['expcube'] = self.commonConf['base']+'_ltcube.fits'
        expMap['outfile'] = self.commonConf['base']+'_expMap.fits'
        expMap['irfs'] = self.commonConf['irfs']
        expMap['srcrad'] = float(self.analysisConf['rad']) + 10.
        expMap['nlong'] = 120
        expMap['nlat'] = 120
        expMap['nenergies'] = 20

        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            expMap[name] = value

        np = int(self.commonConf['multicore'])
        
        if(np > 0):
            import gtexpmap_mp as expmp
            expmp.gtexpmap_mp(expMap['nlong'],expMap['nlat'],np,1,
                              expMap['scfile'],expMap['evfile'],expMap['expcube'], 
                              expMap['irfs'],expMap['srcrad'],expMap['nenergies'],
                              expMap['outfile'],False)
        else:
            qU.runCommand(expMap,self.logger,run)
    def runGTI(self, run = True, filterString="DATA_QUAL==1 && LAT_CONFIG==1 && ABS(ROCK_ANGLE)<52",roi = 'yes'):

        """Executes gtmktime with the given filter"""

        maketime['scfile'] = self.commonConf['base']+'_SC.fits'
        maketime['filter'] = filterString
        maketime['roicut'] = roi
        maketime['evfile'] = self.commonConf['base']+'_filtered.fits'
        maketime['outfile'] = self.commonConf['base']+'_filtered_gti.fits'

        qU.runCommand(maketime,self.logger,run)
    def runDIFRSP(self, run = True, **kwargs):

        """Executes gtdiffrsp with the given arguments"""

        diffResps['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        diffResps['scfile'] = self.commonConf['base']+'_SC.fits'
        diffResps['srcmdl'] = self.analysisConf['model']
        diffResps['irfs'] = self.commonConf['irfs']
    
        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            diffResps[name] = value

        qU.runCommand(diffResps,self.logger,run)
    def runGTI(self, run = True, **kwargs):

        """Executes gtmktime with the given filter"""

        maketime['scfile'] = self.commonConf['base']+'_SC.fits'
        maketime['filter'] = self.analysisConf['filter']
        maketime['roicut'] = self.analysisConf['roicut']
        maketime['evfile'] = self.commonConf['base']+'_filtered.fits'
        maketime['outfile'] = self.commonConf['base']+'_filtered_gti.fits'
    
        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            maketime[name] = value

        qU.runCommand(maketime,self.logger,run)
    def runGTI(self, run = True, **kwargs):

        """Executes gtmktime with the given filter"""

        maketime['scfile'] = self.commonConf['base']+'_SC.fits'
        maketime['filter'] = self.analysisConf['filter']
        maketime['roicut'] = self.analysisConf['roicut']
        maketime['evfile'] = self.commonConf['base']+'_filtered.fits'
        maketime['outfile'] = self.commonConf['base']+'_filtered_gti.fits'
    
        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            maketime[name] = value

        qU.runCommand(maketime,self.logger,run)
    def runLTCube(self, run=True, zmax=180):

        """Generates a livetime cube"""

        expCube['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        expCube['scfile'] = self.commonConf['base']+'_SC.fits'
        expCube['outfile'] = self.commonConf['base']+'_ltcube.fits'
        expCube['dcostheta'] = 0.025
        expCube['binsz'] = 1
        expCube['zmax'] = zmax

        np = int(self.commonConf['multicore'])
        
        if(np > 0):
            import gtltcube_mp as ltmp
            ltmp.gtltcube_mp(np, expCube['scfile'], expCube['evfile'], expCube['outfile'],False,expCube['zmax'])
        else:
            qU.runCommand(expCube,self.logger,run)
    def runCCUBE(self, run=True,nbins=30, **kwargs):

        """Generates a counts cube.  The dimensions of which are the
        largest square subtended by the ROI.  Note that if the ROI is
        exceptionally small or the bin size exceptionally large, the
        square might not be the largest posible since the npix
        calculation floors the calculated value.  The number of energy
        bins is logarithmic and is defined by the nbins variable."""
    
        if float(self.analysisConf['nxpix']) < 0 or float(self.analysisConf['nypix']) < 0:
            self.logger.info("Autocalculating nxpix and nypix.")
            self.analysisConf['nxpix'] = qU.NumberOfPixels(float(self.analysisConf['rad']),
                                                           float(self.analysisConf['binsize']))
            self.analysisConf['nypix'] = self.analysisConf['nxpix']
            print self.analysisConf['nypix']
            

        evtbin['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        evtbin['outfile'] = self.commonConf['base']+'_CCUBE.fits'
        evtbin['algorithm'] = 'CCUBE'
        evtbin['nxpix'] = self.analysisConf['nxpix']
        evtbin['nypix'] = self.analysisConf['nypix']
        evtbin['binsz'] = self.analysisConf['binsize']
        evtbin['coordsys'] = 'CEL'
        evtbin['xref'] = self.analysisConf['ra']
        evtbin['yref'] = self.analysisConf['dec']
        evtbin['axisrot'] = 0
        evtbin['proj'] = self.analysisConf['proj']
        evtbin['ebinalg'] = 'LOG'
        evtbin['emin'] = self.analysisConf['emin']
        evtbin['emax'] = self.analysisConf['emax']
        evtbin['enumbins'] = nbins
        evtbin['scfile'] = self.commonConf['base']+"_SC.fits"

	#Override settings above with kwargs if they exist
	for name, value in kwargs.items():
		evtbin[name] = value

        qU.runCommand(evtbin,self.logger,run)
    def runSelect(self,run = True, printCmd=False):

        """Runs gtselect on the data using the initialization
        parameters. User selected parameters include the conversion
        type and the eventclass."""

        filter['rad'] = self.analysisConf['rad']
        filter['evclass'] = self.commonConf['eventclass']
        filter['evclsmin'] = 0
        filter['evclsmax'] = 10
        filter['infile'] = "@"+self.commonConf['base']+".list"
        filter['outfile'] = self.commonConf['base']+"_filtered.fits"
        filter['ra'] = self.analysisConf['ra']
        filter['dec'] = self.analysisConf['dec']
        filter['tmin'] = self.analysisConf['tmin']
        filter['tmax'] = self.analysisConf['tmax']
        filter['emin'] = self.analysisConf['emin']
        filter['emax'] = self.analysisConf['emax']
        filter['zmax'] = self.analysisConf['zmax']
        filter['convtype'] = self.analysisConf['convtype']

        qU.runCommand(filter,self.logger,run,printCmd)
    def runLTCube(self, run=True, **kwargs):

        """Generates a livetime cube"""

        expCube['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        expCube['scfile'] = self.commonConf['base']+'_SC.fits'
        expCube['outfile'] = self.commonConf['base']+'_ltcube.fits'
        expCube['dcostheta'] = 0.025
        expCube['binsz'] = 1
        expCube['zmax'] = self.analysisConf['ltzmax']

        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            expCube[name] = value

        np = int(self.commonConf['multicore'])
        
        if(np > 0):
            import gtltcube_mp as ltmp
            ltmp.gtltcube_mp(np, expCube['scfile'], expCube['evfile'], expCube['outfile'],
                             False,expCube['zmax'], 0, 0)
        else:
            qU.runCommand(expCube,self.logger,run)
    def runLTCube(self, run=True, **kwargs):

        """Generates a livetime cube"""

        expCube['evfile'] = self.commonConf['base']+'_filtered_gti.fits'
        expCube['scfile'] = self.commonConf['base']+'_SC.fits'
        expCube['outfile'] = self.commonConf['base']+'_ltcube.fits'
        expCube['dcostheta'] = 0.025
        expCube['binsz'] = 1
        expCube['zmax'] = self.analysisConf['ltzmax']

        #Override the settings above with the kwargs if they exist.
        for name,value in kwargs.items():
            expCube[name] = value

        np = int(self.commonConf['multicore'])
        
        if(np > 0):
            import gtltcube_mp as ltmp
            ltmp.gtltcube_mp(np, expCube['scfile'], expCube['evfile'], expCube['outfile'],
                             False,expCube['zmax'], 0, 0)
        else:
            qU.runCommand(expCube,self.logger,run)
    def runExpCube(self,run=True,nbins=30, ExpBuffer=30, **kwargs):

        """Generates a binned exposure map that is 30 degrees larger
        than the ROI.  The binned exposure map needs to take into
        account the exposure on sources outside of the ROI.  30
        degrees is the size of the PSF at low energies plus some extra
        tens of degrees for security.  You can adjust this buffer by
        setting the ExpBuffer option.  The energy binning is
        logarithmic and the number of energy bins is defined by the
        nbins variable."""

        npix = qU.NumberOfPixels(float(self.analysisConf['rad'])+ExpBuffer, float(self.analysisConf['binsize']))

    	gtexpcube2['infile'] = self.commonConf['base']+"_ltcube.fits"
    	gtexpcube2['cmap'] = self.commonConf['base']+'_CCUBE.fits'
    	gtexpcube2['outfile'] = self.commonConf['base']+"_BinnedExpMap.fits"
    	gtexpcube2['irfs'] = self.commonConf['irfs']
    	gtexpcube2['xref'] = str(self.analysisConf['ra'])
    	gtexpcube2['yref'] = str(self.analysisConf['dec'])
    	gtexpcube2['nxpix'] = str(npix)
    	gtexpcube2['nypix'] = str(npix)
    	gtexpcube2['binsz'] = str(self.analysisConf['binsize'])
    	gtexpcube2['coordsys'] = "CEL"
    	gtexpcube2['axisrot'] = 0
    	gtexpcube2['proj'] = str(self.analysisConf['proj'])
    	gtexpcube2['ebinalg'] = "LOG"
    	gtexpcube2['emin'] = str(self.analysisConf['emin'])
    	gtexpcube2['emax'] = str(self.analysisConf['emax'])
    	gtexpcube2['enumbins'] = str(nbins)

    	#Override settings above with kwargs if they exist
    	for name, value in kwargs.items():
    		gtexpcube2[name] = value
	
    	qU.runCommand(gtexpcube2, self.logger, run)
	
	"""