Exemplo n.º 1
0
    def _test_pickeling(self):
        """
        Test cstsdist pickeling
        """
        # Perform pickeling tests of empty class
        self._pickeling(cscripts.cstsdist())

        # Set-up cstsdist for event list
        tsdist = cscripts.cstsdist()
        tsdist['inobs'] = self._events
        tsdist['inmodel'] = self._model
        tsdist['srcname'] = 'Crab'
        tsdist['caldb'] = self._caldb
        tsdist['irf'] = self._irf
        tsdist['ntrials'] = 2
        tsdist[
            'nthreads'] = 1  # This tests at the same time no multiprocessing
        tsdist['outfile'] = 'cstsdist_py1_pickle.dat'
        tsdist['logfile'] = 'cstsdist_py1_pickle.log'
        tsdist['chatter'] = 3

        # Perform pickeling tests of filled class
        obj = self._pickeling(tsdist)

        # Run csphasecrv script and save light curve
        obj.logFileOpen()  # Make sure we get a log file
        obj.run()
        obj.save()

        # Check TS distribution file
        self._check_result_file('cstsdist_py1_pickle.dat')

        # Return
        return
Exemplo n.º 2
0
    def _test_python_binned(self):
        """
        Test cstsdist from Python
        """
        # Set-up cstsdist for counts cube
        tsdist = cscripts.cstsdist()
        tsdist['inobs']    = self._cntcube
        tsdist['inmodel']  = self._model
        tsdist['srcname']  = 'Crab'
        tsdist['expcube']  = 'NONE'
        tsdist['psfcube']  = 'NONE'
        tsdist['bkgcube']  = 'NONE'
        tsdist['caldb']    = self._caldb
        tsdist['irf']      = self._irf
        tsdist['ntrials']  = 2
        tsdist['outfile']  = 'cstsdist_py2.dat'
        tsdist['logfile']  = 'cstsdist_py2.log'
        tsdist['chatter']  = 4

        # Run cstsdist script
        tsdist.logFileOpen()   # Make sure we get a log file
        tsdist.execute()

        # Check pull distribution file
        self._check_result_file('cstsdist_py2.dat')

        # Return
        return
Exemplo n.º 3
0
    def _test_python_unbinned(self):
        """
        Test cstsdist from Python
        """
        # Set-up cstsdist for event list
        tsdist = cscripts.cstsdist()
        tsdist['inobs']    = self._events
        tsdist['inmodel']  = self._model
        tsdist['srcname']  = 'Crab'
        tsdist['caldb']    = self._caldb
        tsdist['irf']      = self._irf
        tsdist['ntrials']  = 2
        tsdist['outfile']  = 'cstsdist_py1.dat'
        tsdist['logfile']  = 'cstsdist_py1.log'
        tsdist['chatter']  = 3

        # Run cstsdist script
        tsdist.logFileOpen()   # Make sure we get a log file
        tsdist.run()
        tsdist.save()

        # Check pull distribution file
        self._check_result_file('cstsdist_py1.dat')

        # Return
        return
Exemplo n.º 4
0
    def _test_python_binned(self):
        """
        Test cstsdist from Python
        """
        # Set-up cstsdist for counts cube
        tsdist = cscripts.cstsdist()
        tsdist['inobs'] = self._cntcube
        tsdist['inmodel'] = self._model
        tsdist['srcname'] = 'Crab'
        tsdist['expcube'] = 'NONE'
        tsdist['psfcube'] = 'NONE'
        tsdist['bkgcube'] = 'NONE'
        tsdist['caldb'] = self._caldb
        tsdist['irf'] = self._irf
        tsdist['ntrials'] = 2
        tsdist['outfile'] = 'cstsdist_py2.dat'
        tsdist['logfile'] = 'cstsdist_py2.log'
        tsdist['chatter'] = 4

        # Run cstsdist script
        tsdist.logFileOpen()  # Make sure we get a log file
        tsdist.execute()

        # Check TS distribution file
        self._check_result_file('cstsdist_py2.dat')

        # Return
        return
Exemplo n.º 5
0
    def _test_python_unbinned(self):
        """
        Test cstsdist from Python
        """
        # Set-up cstsdist for event list
        tsdist = cscripts.cstsdist()
        tsdist['inobs'] = self._events
        tsdist['inmodel'] = self._model
        tsdist['srcname'] = 'Crab'
        tsdist['caldb'] = self._caldb
        tsdist['irf'] = self._irf
        tsdist['ntrials'] = 2
        tsdist['outfile'] = 'cstsdist_py1.dat'
        tsdist['logfile'] = 'cstsdist_py1.log'
        tsdist['chatter'] = 3

        # Run cstsdist script
        tsdist.logFileOpen()  # Make sure we get a log file
        tsdist.run()
        tsdist.save()

        # Check TS distribution file
        self._check_result_file('cstsdist_py1.dat')

        # Return
        return
Exemplo n.º 6
0
    def _test_python(self):
        """
        Test cstsdist from Python
        """
        # Set-up cstsdist
        tsdist = cscripts.cstsdist()
        tsdist['inmodel'] = self._model
        tsdist['srcname'] = 'Crab'
        tsdist['caldb'] = self._caldb
        tsdist['irf'] = self._irf
        tsdist['outfile'] = 'cstsdist_py1.dat'
        tsdist['ntrials'] = 1
        tsdist['ra'] = 83.63
        tsdist['dec'] = 22.01
        tsdist['emin'] = 0.1
        tsdist['emax'] = 100.0
        tsdist['enumbins'] = 0
        tsdist['tmax'] = 1800.0
        tsdist['rad'] = 5.0
        tsdist['npix'] = 200
        tsdist['binsz'] = 0.05
        tsdist['logfile'] = 'cstsdist_py1.log'
        tsdist['chatter'] = 2

        # Run cstsdist script
        tsdist.logFileOpen()  # Make sure we get a log file
        tsdist.run()
        tsdist.save()

        # Check pull distribution file
        self._check_result_file('cstsdist_py1.dat')

        # Return
        return
Exemplo n.º 7
0
def create_ts(loge, emin, emax, ntrials=100, duration=180000.0,
                          enumbins=0, log=False):
    """
    Create TS distribution.

    Parameters:
     loge - Logarithm of mean energy in TeV
     emin - Minimum energy (TeV)
     emax - Maximum energy (TeV)
    Keywords:
     log  - Create log file(s)
    """
    # Generate output filename
    outfile = "ts_"+str(loge)+".dat"

    # Setup cstsdist tool
    tsdist = cstsdist()
    tsdist["inmodel"]  = "$CTOOLS/share/models/crab.xml"
    tsdist["srcname"]  = "Crab"
    tsdist["outfile"]  = outfile
    tsdist["ntrials"]  = ntrials
    tsdist["caldb"]    = "prod2"
    tsdist["irf"]      = "South_50h"
    tsdist["ra"]       = 83.63
    tsdist["dec"]      = 22.01
    tsdist["emin"]     = emin
    tsdist["emax"]     = emax
    tsdist["enumbins"] = enumbins
    tsdist["tmin"]     = 0
    tsdist["tmax"]     = duration
    tsdist["rad"]      = 5.0
    tsdist["npix"]     = 200
    tsdist["binsz"]    = 0.05
    #tsdist["debug"].boolean(True)

    # Optionally open the log file
    if log:
        tsdist.logFileOpen()

    # Run tool
    tsdist.run()

    # Return
    return
Exemplo n.º 8
0
    def _test_python_stacked(self):
        """
        Test cstsdist from Python
        """
        # Set-up cstsdist for stacked cube
        tsdist = cscripts.cstsdist()
        tsdist['inobs']    = self._stacked_inobs
        tsdist['inmodel']  = self._stacked_model
        tsdist['srcname']  = 'Crab'
        tsdist['ntrials']  = 2
        tsdist['outfile']  = 'cstsdist_py3.dat'
        tsdist['logfile']  = 'cstsdist_py3.log'
        tsdist['chatter']  = 4

        # Run cstsdist script
        tsdist.logFileOpen()   # Make sure we get a log file
        tsdist.execute()

        # Check pull distribution file
        self._check_result_file('cstsdist_py3.dat')

        # Return
        return
Exemplo n.º 9
0
    def _test_python_stacked(self):
        """
        Test cstsdist from Python
        """
        # Set-up cstsdist for stacked cube
        tsdist = cscripts.cstsdist()
        tsdist['inobs'] = self._stacked_inobs
        tsdist['inmodel'] = self._stacked_model
        tsdist['srcname'] = 'Crab'
        tsdist['ntrials'] = 2
        tsdist['outfile'] = 'cstsdist_py3.dat'
        tsdist['logfile'] = 'cstsdist_py3.log'
        tsdist['chatter'] = 4

        # Run cstsdist script
        tsdist.logFileOpen()  # Make sure we get a log file
        tsdist.execute()

        # Check TS distribution file
        self._check_result_file('cstsdist_py3.dat')

        # Return
        return
Exemplo n.º 10
0
def create_ts(datadir,
              loge,
              emin,
              emax,
              ntrials=100,
              duration=180000.0,
              enumbins=0,
              log=False):
    """
    Create TS distribution.

    Parameters
    ----------
    datadir : str
        Data directory
    loge : float
        Logarithm of mean energy (TeV)
    emin : float
        Minimum energy (TeV)
    emax : float
        Maximum energy (TeV)
    ntrials : int, optional
        Number of MC samples
    durations : float, optional
        Observation duration (s)
    enumbins : int, optional
        Number of energy bins
    log : bool, optional
        Create log file(s)
    """
    # Generate output filename
    outfile = 'ts_' + str(loge) + '.dat'

    # Setup cstsdist tool
    tsdist = cscripts.cstsdist()
    tsdist['inmodel'] = datadir + '/crab.xml'
    tsdist['srcname'] = 'Crab'
    tsdist['outfile'] = outfile
    tsdist['ntrials'] = ntrials
    tsdist['caldb'] = 'prod2'
    tsdist['irf'] = 'South_50h'
    tsdist['ra'] = 83.63
    tsdist['dec'] = 22.01
    tsdist['emin'] = emin
    tsdist['emax'] = emax
    tsdist['enumbins'] = enumbins
    tsdist['tmin'] = 0
    tsdist['tmax'] = duration
    tsdist['rad'] = 5.0
    tsdist['npix'] = 200
    tsdist['binsz'] = 0.05

    # Optionally open the log file
    if log:
        tsdist.logFileOpen()

    # Run tool
    tsdist.run()

    # Return
    return