Beispiel #1
0
    def LoadConfiguration(self):
        #Read the configuration object and init all the variable
        filetag = self.Configuration['file']['tag']
        inttag = "_" + filetag
        if not (self.tag == ""):
            inttag += "_" + self.tag

        self.srcname = self.Configuration['target']['name']
        self.modelname = self.Configuration['target']['spectrum']
        self.ft1 = self.Configuration['file']['event']
        self.ft2 = self.Configuration['file']['spacecraft']
        self.xmlfile = self.Configuration['file']['xml']

        #Fits files
        self.eventcoarse = self.folder + '/' + self.srcname + "_" + filetag + "_EvtCoarse.fits"
        self.eventfile = self.folder + '/' + self.srcname + inttag + "_Evt.fits"
        self.mktimefile = self.folder + '/' + self.srcname + inttag + "_MkTime.fits"
        self.Cubename = self.folder + '/' + self.srcname + inttag + "_ltCube.fits"
        self.Mapname = self.folder + '/' + self.srcname + inttag + "_ExpMap.fits"
        self.BinnedMapfile = self.folder + '/' + self.srcname + inttag + "_BinnedMap.fits"
        self.cmapfile = self.folder + '/' + self.srcname + inttag + "_CountMap.fits"
        self.lcfile = self.folder + '/' + self.srcname + inttag + "_applc.fits"
        self.ccube = self.folder + '/' + self.srcname + inttag + "_CCUBE.fits"
        self.srcMap = self.folder + '/' + self.srcname + inttag + "_" + self.modelname + "_srcMap.fits"
        self.ModelMap = self.folder + '/' + self.srcname + inttag + "_" + self.modelname + "_ModelMap.fits"
        self.BinDef = self.folder + '/' + self.srcname + inttag + "_BinDef.fits"
        self.Probfile = self.folder + '/' + self.srcname + inttag + "_" + self.modelname + "_prob.fits"
        self.psf = self.folder + '/' + self.srcname + inttag + "_" + self.modelname + "_psf.fits"

        #Variables
        self.t1 = float(self.Configuration['time']['tmin'])
        self.t2 = float(self.Configuration['time']['tmax'])
        self.Emin = float(self.Configuration['energy']['emin'])
        self.Emax = float(self.Configuration['energy']['emax'])
        self.ra = float(self.Configuration['space']['xref'])
        self.dec = float(self.Configuration['space']['yref'])
        self.roi = float(self.Configuration['space']['rad'])
        self.irfs, _ = utils.GetIRFS(self.Configuration['event']['evclass'],
                                     self.Configuration['event']['evtype'])
        #self.irfs      = self.irfs
        self.likelihood = self.Configuration['analysis']['likelihood']

        #Apply cuts in event selections? (roicuts should not be applied twice, it makes ST to crash)
        self.roicuts = bool(
            self.Configuration['analysis']['evtroicuts'] == 'yes')
        self.timecuts = bool(
            self.Configuration['analysis']['evttimecuts'] == 'yes')

        #diffuse Response
        self.diffrspflag = self.folder + '/' + self.srcname + inttag + "_diffrsp.flag"

        #Maps binning
        self.binsz = self.Configuration['space']['binsz']
        self.npix = int(2 * self.roi / sqrt(2.) / self.binsz)

        #tool options
        self.clobber = self.Configuration['clobber']
Beispiel #2
0
 def printSum(self):
     """Print a summary of the value stored in the class"""
     print "Source\t=\t", self.srcname
     print "RA\t=\t", self.ra, " degrees"
     print "Dec\t=\t", self.dec, " degrees"
     print "Start\t=\t", self.t1, "  MET (s)"
     print "Stop\t=\t", self.t2, "  MET (s)"
     print "ROI\t=\t", self.roi, " degrees"
     print "E min\t=\t", self.Emin, " MeV"
     print "E max\t=\t", self.Emax, " MeV"
     print "IRFs\t=\t", self.irfs
     print "evclass\t=\t", self.Configuration['event']['evclass']
     print "evtype\t=\t", self.Configuration['event']['evtype']
     if self.irfs == 'CALDB':
         print "Corresponding IRFs\t=\t",\
         utils.GetIRFS(self.Configuration['event']['evclass'],\
         self.Configuration['event']['evtype'])
Beispiel #3
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()
Beispiel #4
0
 def GtPSF(self):
     if (self.clobber == "no" and os.path.isfile(self.psf)):
         #print("File exists and clobber is False")
         return (0)
     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'] +
         0.5)
     psf["thetamax"] = 5.
     psf.run()
Beispiel #5
0
def query_config():
    import os
    """Make a new config object, asking the user for required options"""
    config = ConfigObj(indent_type='\t')
    mes = Loggin.Message()
    mes.info('Please provide the following required options [default] :')
    config['out'] = os.getcwd()
    out = raw_input('Output directory [' + config['out'] + '] : ')
    if not (out == ''):
        config['out'] = out

#    Informations about the source
    config['target'] = {}
    config['target']['name'] = raw_input('Target Name : ')
    config['target']['ra'] = raw_input('Right Ascension: ')
    config['target']['dec'] = raw_input('Declination: ')

    config['target']['redshift'] = '0'
    redshift = raw_input('redshift, no effect if null [0] : ')
    if not (redshift == ''):
        config['target']['redshift'] = redshift
        config['target']['ebl_model'] = raw_input(
            'ebl model to used\n'
            '0=Kneiske, 1=Primack05, 2=Kneiske_HighUV, 3=Stecker05, '
            '4=Franceschini, 5=Finke, 6=Gilmore : ')

    message = (
        'Options are : PowerLaw, PowerLaw2, LogParabola, '
        'PLExpCutoff, Generic\nGeneric is design to allow the user to fit with non-supported models\n'
        'EBL absorption can be added for PowerLaw2, LogParabola, PLExpCutoff\n'
        'Spectral Model [PowerLaw] : ')
    config['target']['spectrum'] = 'PowerLaw'
    model = raw_input(message)
    if not (model == ''):
        config['target']['spectrum'] = model

#    informations about the ROI
    config['space'] = {}
    config['space']['xref'] = config['target']['ra']
    config['space']['yref'] = config['target']['dec']
    config['space']['rad'] = '15'
    roi = raw_input('ROI Size [15] : ')
    if not (roi == ''):
        config['space']['rad'] = roi

#    informations about the input files
    config['file'] = {}
    if USE_FULLMISSION_SPACECRAFT:
        config['file'][
            'spacecraft'] = DOWNLOAD_DIR + '/lat_spacecraft_merged.fits'
    else:
        config['file']['spacecraft'] = '@' + DOWNLOAD_DIR + '/spacecraft.lis'
    ft2 = raw_input('FT2 file [' + config['file']['spacecraft'] + '] : ')
    if not (ft2 == ''):
        config['file']['spacecraft'] = ft2
    config['file']['event'] = DOWNLOAD_DIR + '/events.lis'
    ft1list = raw_input('FT1 list of files [' + config['file']['event'] +
                        '] : ')
    if not (ft1list == ''):
        config['file']['event'] = ft1list
    config['file']['xml'] = config['out'] + '/' + config['target'][
        'name'] + '_' + config['target']['spectrum'] + '_model.xml'
    tag = raw_input('tag [LAT_Analysis] : ')
    if not (tag == ''):
        config['file']['tag'] = tag
    else:
        config['file']['tag'] = 'LAT_Analysis'

#    informations about the time
    config['time'] = {}
    tmin = raw_input('Start time [-1=START] : ')
    ft2 = config['file']['spacecraft']
    if not (tmin == '') and float(tmin) >= 0:
        config['time']['tmin'] = tmin
    else:
        config['time']['tmin'] = get_times_from_spacecraft(ft2,
                                                           target=['tmin'])[0]
    tmax = raw_input('End time [-1=END] : ')
    if not (tmax == '') and float(tmax) >= 0:
        config['time']['tmax'] = tmax
    else:
        config['time']['tmax'] = get_times_from_spacecraft(ft2,
                                                           target=['tmax'])[1]

#    informations about the energy
    config['energy'] = {}
    emin = raw_input('Emin [100] : ')
    if not (emin == ''):
        config['energy']['emin'] = emin
    else:
        config['energy']['emin'] = '100'
    emax = raw_input('Emax [300000] : ')
    if not (emax == ''):
        config['energy']['emax'] = emax
    else:
        config['energy']['emax'] = '300000'

#    informations about the event class
    config['event'] = {}
    irfs = raw_input('IRFs [CALDB] : ')
    if not (irfs == ''):
        config['event']['irfs'] = irfs
    else:
        config['event']['irfs'] = 'CALDB'

    if irfs == '':
        ok = False
        while not (ok):
            evclass = raw_input('evclass [128] : ')
            if not (evclass == ''):
                config['event']['evclass'] = evclass
            else:
                config['event']['evclass'] = '128'

            evtype = raw_input('evtype [3] : ')
            if not (evtype == ''):
                config['event']['evtype'] = evtype
            else:
                config['event']['evtype'] = '3'
            print "Corresponding IRFs\t=\t", utils.GetIRFS(
                float(config['event']['evclass']),
                float(config['event']['evtype']))
            ans = raw_input('Is this ok? [y] : ')
            if ans == "y" or ans == '':
                ok = True

    config['analysis'] = {}
    zmax = utils.GetZenithCut(float(config['event']['evclass']),
                              float(config['event']['evtype']),
                              float(config['energy']['emin']))
    print "Corresponding zmax = ", zmax
    config["analysis"]["zmax"] = zmax

    return get_config(config)
Beispiel #6
0
    def LoadConfiguration(self):
        #Read the configuration object and init all the variable
        filetag = self.Configuration['file']['tag']
        self.inttag = "_" + filetag
        if not (self.tag == ""):
            self.inttag += "_" + self.tag

        self.srcname = self.Configuration['target']['name']
        self.modelname = self.Configuration['target']['spectrum']
        self.ft1 = self.Configuration['file']['event']
        self.ft2 = self.Configuration['file']['spacecraft']
        self.xmlfile = self.Configuration['file']['xml']

        #Fits files
        self.eventcoarse = self.folder + '/' + self.srcname + "_" + filetag + "_EvtCoarse.fits"
        self.eventfile = self.folder + '/' + self.srcname + self.inttag + "_Evt.fits"
        self.mktimefile = self.folder + '/' + self.srcname + self.inttag + "_MkTime.fits"
        self.Cubename = self.folder + '/' + self.srcname + self.inttag + "_ltCube.fits"
        self.Mapname = self.folder + '/' + self.srcname + self.inttag + "_ExpMap.fits"
        self.BinnedMapfile = self.folder + '/' + self.srcname + self.inttag + "_BinnedMap.fits"
        self.cmapfile = self.folder + '/' + self.srcname + self.inttag + "_CountMap.fits"
        self.lcfile = self.folder + '/' + self.srcname + self.inttag + "_applc.fits"
        self.ccube = self.folder + '/' + self.srcname + self.inttag + "_CCUBE.fits"
        self.srcMap = self.folder + '/' + self.srcname + self.inttag + "_" + self.modelname + "_srcMap.fits"
        self.ModelMapFile = self.folder + '/' + self.srcname + self.inttag + "_" + self.modelname + "_ModelMap.fits"
        self.BinDef = self.folder + '/' + self.srcname + self.inttag + "_BinDef.fits"
        self.Probfile = self.folder + '/' + self.srcname + self.inttag + "_" + self.modelname + "_prob.fits"
        self.psf = self.folder + '/' + self.srcname + self.inttag + "_" + self.modelname + "_psf.fits"
        self.rel_diff_file = self.folder + '/' + self.srcname + self.inttag + "_" + self.modelname + "_ResidualMap.fits"
        self.abs_diff_file = self.folder + '/' + self.srcname + self.inttag + "_" + self.modelname + "_SubtractMap.fits"

        #Variables
        if ('MJD' in self.Configuration['time']['type']):
            get_met = lambda t: utils.MJD_to_met(float(t))
        elif ('JD' in self.Configuration['time']['type']):
            get_met = lambda t: utils.JD_to_met(float(t))
        else:
            get_met = lambda t: float(t)

        #use energy dispersion corrections? This will extend Emin and Emax
        self.use_edisp = bool(
            self.Configuration['analysis']['EnergyDispersion'] == 'yes'
            and self.Configuration["analysis"]["likelihood"] == "binned")

        self.t1 = get_met(self.Configuration['time']['tmin'])
        self.t2 = get_met(self.Configuration['time']['tmax'])
        self.Emin = float(self.Configuration['energy']['emin'])
        self.Emax = float(self.Configuration['energy']['emax'])
        if (self.use_edisp):
            self.Emin_ext = 10**(log10(self.Emin) - 0.3)
            self.Emax_ext = 10**(log10(self.Emax) + 0.3)
        else:
            self.Emin_ext = self.Emin
            self.Emax_ext = self.Emax

        self.ra = float(self.Configuration['space']['xref'])
        self.dec = float(self.Configuration['space']['yref'])
        self.roi = float(self.Configuration['space']['rad'])
        self.irfs, _ = utils.GetIRFS(self.Configuration['event']['evclass'],
                                     self.Configuration['event']['evtype'])
        #self.irfs      = self.irfs
        self.likelihood = self.Configuration['analysis']['likelihood']

        #Apply cuts in event selections?
        # (roicuts should not be applied twice, it makes ST crash)
        self.roicuts = bool(
            self.Configuration['analysis']['evtroicuts'] == 'yes')
        self.timecuts = bool(
            self.Configuration['analysis']['evttimecuts'] == 'yes')

        #diffuse Response
        self.diffrspflag = self.folder + '/' + self.srcname + self.inttag + "_diffrsp.flag"

        #Maps binning
        self.binsz = self.Configuration['space']['binsz']
        self.npix = int(2 * self.roi / self.binsz)
        self.npixCntMp = int(sqrt(2.) * self.roi / self.binsz)

        #tool options
        self.clobber = self.Configuration['clobber']