Exemple #1
0
    def _test_python(self):
        """
        Test csresmap from Python
        """
        # Set-up csresmap for event list
        resmap = cscripts.csresmap()
        resmap['inobs'] = self._events
        resmap['outmap'] = 'csresmap_py1.fits'
        resmap['inmodel'] = self._model
        resmap['caldb'] = self._caldb
        resmap['irf'] = self._irf
        resmap['emin'] = 0.1
        resmap['emax'] = 100.0
        resmap['enumbins'] = 20
        resmap['nxpix'] = 50
        resmap['nypix'] = 50
        resmap['binsz'] = 0.02
        resmap['coordsys'] = 'CEL'
        resmap['proj'] = 'CAR'
        resmap['xref'] = 83.63
        resmap['yref'] = 22.01
        resmap['algorithm'] = 'SUBDIV'
        resmap['logfile'] = 'csresmap_py1.log'
        resmap['chatter'] = 2

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

        # Check pull distribution file
        self._check_result_file('csresmap_py1.fits')

        # Set-up csresmap for counts cube
        resmap = cscripts.csresmap()
        resmap['inobs'] = self._cntcube
        resmap['modcube'] = 'NONE'
        resmap['expcube'] = 'NONE'
        resmap['psfcube'] = 'NONE'
        resmap['edispcube'] = 'NONE'
        resmap['bkgcube'] = 'NONE'
        resmap['caldb'] = self._caldb
        resmap['irf'] = self._irf
        resmap['inmodel'] = self._model
        resmap['outmap'] = 'csresmap_py2.fits'
        resmap['algorithm'] = 'SUBDIV'
        resmap['logfile'] = 'csresmap_py2.log'
        resmap['chatter'] = 3

        # Run csresmap script
        resmap.execute()

        # Check pull distribution file
        self._check_result_file('csresmap_py2.fits', nx=200, ny=200)

        # Return
        return
def generate_resmap(emin=0.3, emax=50.0, ebins=40, edisp=True):
    """
    Generate residual map

    Parameters
    ----------
    emin : float, optional
        Minimum energy (TeV)
    emax : float, optional
        Maximum energy (TeV)
    ebins : int, optional
        Number of energy bins
    edisp : bool, optional
        Enable energy dispersion?
    """
    # Set filenames
    inobs = 'obs_rx_selected.xml'
    inmodel = 'rx_results_map0.48_eplaw_lookup_grad_hess_edisp.xml'
    outmodel = 'rx_background_map0.48_eplaw_lookup_grad_hess_edisp.xml'
    outmap = 'rx_resmap.fits'
    logfile = 'rx_resmap.log'

    # Continue only if inmodel exists
    if os.path.isfile(inobs) and os.path.isfile(inmodel):

        # Create model definition XML file without source
        models = gammalib.GModels(inmodel)
        models.remove('RX J1713.7-3946')
        models.save(outmodel)

        # Setup task parameters
        resmap = cscripts.csresmap()
        resmap['inobs'] = inobs
        resmap['inmodel'] = outmodel
        resmap['edisp'] = edisp
        resmap['algorithm'] = 'SUB'
        resmap['ebinalg'] = 'LOG'
        resmap['emin'] = emin
        resmap['emax'] = emax
        resmap['enumbins'] = ebins
        resmap['coordsys'] = 'CEL'
        resmap['proj'] = 'CAR'
        resmap['xref'] = 258.1125
        resmap['yref'] = -39.6867
        resmap['nxpix'] = 300
        resmap['nypix'] = 300
        resmap['binsz'] = 0.02
        resmap['outmap'] = outmap
        resmap['logfile'] = logfile
        resmap.logFileOpen()

        # Generate residual map
        resmap.execute()

    # Return
    return
Exemple #3
0
def generate_map():
    """
    Generate MSH 15-52 map
    """
    # Define files
    inmodel = 'msh_results_egauss_plaw_lookup_grad_hess_edisp.xml'
    logfile = 'msh_skymap.log'
    outfile = 'msh_skymap.fits'
    modfile = 'msh_skymap.xml'

    # Continue only if map or result does not yet exist
    if not os.path.isfile(outfile) and os.path.isfile(inmodel):

        # Read input model
        models = gammalib.GModels(inmodel)

        # Remove MSH 15-52 component
        models.remove('MSH 15-52')

        # Save input model
        models.save(modfile)

        # Generate residual map
        resmap = cscripts.csresmap()
        resmap['inobs'] = 'obs_msh_selected.xml'
        resmap['inmodel'] = modfile
        resmap['outmap'] = outfile
        resmap['emin'] = 0.381
        resmap['emax'] = 40.0
        resmap['enumbins'] = 40
        resmap['nxpix'] = 200
        resmap['nypix'] = 200
        resmap['binsz'] = 0.005
        resmap['coordsys'] = 'CEL'
        resmap['proj'] = 'TAN'
        resmap['xref'] = 228.55
        resmap['yref'] = -59.17
        resmap['algorithm'] = 'SUB'
        resmap['logfile'] = logfile
        resmap['chatter'] = 4
        resmap.execute()

    # Load map if it exists
    if os.path.isfile(outfile):
        map = gammalib.GSkyMap(outfile)
    else:
        map = None

    # Return map
    return map
Exemple #4
0
import gammalib
import ctools
import cscripts

debug = True

like = ctools.ctlike()
like['inobs'] = 'cntcube.fits'
like['expcube'] = 'expcube.fits'
like['psfcube'] = 'psfcube.fits'
like['bkgcube'] = 'bkgcube.fits'
like['inmodel'] = 'models_cat_iem+fb+ts.xml'
like['outmodel'] = 'results_cat_iem+fb+ts.xml'
like["debug"] = debug
like.execute()

resmap = cscripts.csresmap()
resmap['inobs'] = 'cntcube.fits'
resmap['expcube'] = 'expcube.fits'
resmap['psfcube'] = 'psfcube.fits'
resmap['bkgcube'] = 'bkgcube.fits'
resmap['inmodel'] = 'results_cat_iem+fb+ts.xml'
resmap['modcube'] = 'NONE'
resmap['outmap'] = 'resmap_cat_iem+fb+ts.fits'
resmap['algorithm'] = 'SIGNIFICANCE'
resmap["debug"] = debug
resmap.execute()
Exemple #5
0
    def _test_python(self):
        """
        Test csresmap from Python
        """
        # Set-up csresmap for event list
        resmap = cscripts.csresmap()
        resmap['inobs']     = self._events
        resmap['outmap']    = 'csresmap_py1.fits'
        resmap['inmodel']   = self._model
        resmap['caldb']     = self._caldb
        resmap['irf']       = self._irf
        resmap['emin']      = 0.1
        resmap['emax']      = 100.0
        resmap['enumbins']  = 20
        resmap['nxpix']     = 50
        resmap['nypix']     = 50
        resmap['binsz']     = 0.02
        resmap['coordsys']  = 'CEL'
        resmap['proj']      = 'CAR'
        resmap['xref']      = 83.63
        resmap['yref']      = 22.01
        resmap['algorithm'] = 'SUB'
        resmap['logfile']   = 'csresmap_py1.log'
        resmap['chatter']   = 2

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

        # Check pull distribution file
        self._check_result_file('csresmap_py1.fits')

        # Set-up csresmap for counts cube
        resmap = cscripts.csresmap()
        resmap['inobs']     = self._cntcube
        resmap['modcube']   = 'NONE'
        resmap['expcube']   = 'NONE'
        resmap['psfcube']   = 'NONE'
        resmap['edispcube'] = 'NONE'
        resmap['bkgcube']   = 'NONE'
        resmap['caldb']     = self._caldb
        resmap['irf']       = self._irf
        resmap['inmodel']   = self._model
        resmap['outmap']    = 'csresmap_py2.fits'
        resmap['algorithm'] = 'SUBDIV'
        resmap['logfile']   = 'csresmap_py2.log'
        resmap['chatter']   = 3
        resmap['publish']   = True

        # Run csresmap script
        resmap.execute()

        # Check pull distribution file
        self._check_result_file('csresmap_py2.fits', nx=200, ny=200)

        # Run csresmap with SUBDIVSQRT algorithm
        resmap = cscripts.csresmap()
        resmap['inobs']     = self._cntcube
        resmap['modcube']   = 'NONE'
        resmap['expcube']   = 'NONE'
        resmap['psfcube']   = 'NONE'
        resmap['edispcube'] = 'NONE'
        resmap['bkgcube']   = 'NONE'
        resmap['caldb']     = self._caldb
        resmap['irf']       = self._irf
        resmap['inmodel']   = self._model
        resmap['outmap']    = 'csresmap_py3.fits'
        resmap['algorithm'] = 'SUBDIVSQRT'
        resmap['logfile']   = 'csresmap_py3.log'
        resmap['chatter']   = 3
        resmap['publish']   = True

        # Run csresmap script
        resmap.execute()

        # Check pull distribution file
        self._check_result_file('csresmap_py3.fits', nx=200, ny=200)

        # Run csresmap with SIGNIFICANCE algorithm
        resmap = cscripts.csresmap()
        resmap['inobs']     = self._cntcube
        resmap['modcube']   = 'NONE'
        resmap['expcube']   = 'NONE'
        resmap['psfcube']   = 'NONE'
        resmap['edispcube'] = 'NONE'
        resmap['bkgcube']   = 'NONE'
        resmap['caldb']     = self._caldb
        resmap['irf']       = self._irf
        resmap['inmodel']   = self._model
        resmap['outmap']    = 'csresmap_py4.fits'
        resmap['algorithm'] = 'SIGNIFICANCE'
        resmap['logfile']   = 'csresmap_py4.log'
        resmap['chatter']   = 3
        resmap['publish']   = True

        # Run csresmap script
        resmap.execute()

        # Check pull distribution file
        self._check_result_file('csresmap_py4.fits', nx=200, ny=200)


        # Return
        return
def resmap(inobs,
           inmodel,
           output_map,
           npix,
           reso,
           cra,
           cdec,
           emin=1e-2,
           emax=1e+3,
           enumbins=20,
           ebinalg='LOG',
           modcube=None,
           expcube=None,
           psfcube=None,
           bkgcube=None,
           edispcube=None,
           caldb=None,
           irf=None,
           edisp=False,
           algo='SIGNIFICANCE',
           logfile=None,
           silent=False):
    """
    Compute a residual map.
    
    Parameters
    ----------
    - inobs (string): input observation file
    - inmodel (string): input model
    - output_map (string): output map file
    - npix (int): number of map pixel
    - reso (float): map resolution in degrees
    - cra, cdec (float): map center RA,Dec in degrees
    - emin,emax (float) min and max energy considered in TeV
    - enumbins (int): number of energy bins
    - ebinalg (string): energy bining algorithm
    - modcube (string): model map cube
    - expcube (string): exposure map cube
    - psfcube (string): psfcube 
    - bkgcube (string): background cube
    - edispcube (string): energy dispersion cube
    - caldb (string): calibration database
    - irf (string): instrument response function
    - edisp (bool): apply energy dispersion
    - algo (string): wich algorithm to use
    - silent (bool): print information or not

    Outputs
    --------
    - create residual map fits
    - return a residual map object
    """

    rmap = cscripts.csresmap()

    rmap['inobs'] = inobs
    rmap['inmodel'] = inmodel
    if modcube is not None: rmap['modcube'] = modcube
    if expcube is not None: rmap['expcube'] = expcube
    if psfcube is not None: rmap['psfcube'] = psfcube
    if edispcube is not None: rmap['edispcube'] = edispcube
    if bkgcube is not None: rmap['bkgcube'] = bkgcube
    if caldb is not None: rmap['caldb'] = caldb
    if irf is not None: rmap['irf'] = irf
    rmap['edisp'] = edisp
    rmap['outmap'] = output_map
    rmap['ebinalg'] = ebinalg
    rmap['emin'] = emin
    rmap['emax'] = emax
    rmap['enumbins'] = enumbins
    rmap['ebinfile'] = 'NONE'
    rmap['coordsys'] = 'CEL'
    rmap['proj'] = 'TAN'
    rmap['xref'] = cra
    rmap['yref'] = cdec
    rmap['nxpix'] = npix
    rmap['nypix'] = npix
    rmap['binsz'] = reso
    rmap['algorithm'] = algo
    if logfile is not None: rmap['logfile'] = logfile

    if logfile is not None: rmap.logFileOpen()
    rmap.execute()
    if logfile is not None: rmap.logFileClose()

    if not silent:
        print(rmap)
        print('')

    return rmap