Пример #1
0
    def __init__(self, config, parent_filename=""):
        super(BayesianBlocks, self).__init__(config, parent_filename)

        self.LCfolder = self.folder + "/BayesianBlocks/"
        utils.mkdir_p(self.LCfolder)

        # Convert time if necessary
        if self.config['time']['type'] == 'MJD':
            self.config['time']['tmin'] = utils.MJD_to_met(
                self.config['time']['tmin'])
            self.config['time']['tmax'] = utils.MJD_to_met(
                self.config['time']['tmax'])
            self.config['time']['type'] == 'MET'
        elif self.config['time']['type'] == 'JD':
            self.config['time']['tmin'] = utils.JD_to_met(
                self.config['time']['tmin'])
            self.config['time']['tmax'] = utils.JD_to_met(
                self.config['time']['tmax'])
            self.config['time']['type'] == 'MET'
        self.tmin = self.config['time']['tmin']
        self.tmax = self.config['time']['tmax']

        self.p0 = self.config['BayesianBlocks']['p0']
        self.config['Spectrum']['FitsGeneration'] = self.config[
            'BayesianBlocks']['FitsGeneration']
        self.config['Spectrum']['FrozenSpectralIndex'] = self.config[
            'BayesianBlocks']['SpectralIndex']
        self.config['UpperLimit']['TSlimit'] = self.config['BayesianBlocks'][
            'TSLightCurve']

        # Check apperture light curve have benn run first
        self._CheckAppertureLightCurveFile()
Пример #2
0
 def readApperturePhotometryPoint(self):
     apfile = str("%s/AppertureLightCurve/TimeExposureCount.txt" %
                  (self.folder))
     time, dTime, exposure, counts = np.loadtxt(apfile,
                                                skiprows=1,
                                                unpack=True)
     time, dTime, exposure, counts = resampleCount(time, dTime, exposure,
                                                   counts)
     errcounts = np.sqrt(counts)
     surfaceFermi = 10000  # in cm^2
     flux = counts * surfaceFermi / (exposure)
     errflux = errcounts * surfaceFermi / (exposure)
     time = utils.MJD_to_met(time)
     dTime = utils.MJD_to_met(dTime) - utils.MJD_to_met(0.)
     return time, dTime, flux, errflux
Пример #3
0
    def _MakeTimeBins(self):
        self.time_array = np.zeros(0)
        self.Nbin = 0
        self.gtifile = []
        if self.config['time']['file'] != '':
            print "use ",self.config['time']['file'] 
            self.gtifile.append(self.config['time']['file'])
            times = np.genfromtxt(self.gtifile[0],dtype="float",unpack=True)
            self.Nbin = times.size/2
            self.time_array=np.reshape(times,times.size,'F')
            if self.config['time']['type']=='MJD':
                 self.time_array = utils.MJD_to_met(self.time_array)
            elif self.config['time']['type']=='JD':
                 self.time_array = utils.JD_to_met(self.time_array)
        else:
            self.Nbin = self.config['LightCurve']['NLCbin']
            self.time_array = np.zeros(self.Nbin*2)
#            self.dt = (self.tmax - self.tmin) / self.Nbin
            t = np.arange(self.tmin,self.tmax+0.000001,(self.tmax - self.tmin) / self.Nbin)
            for i in xrange(self.Nbin):
                self.time_array[2*i] = t[i]
                self.time_array[2*i+1]= t[i+1]

        self.info("Running LC with "+str(self.Nbin)+" bins")
        for i in xrange(self.Nbin):
            print "Bin ",i," Start=",self.time_array[2*i]," Stop=",self.time_array[2*i+1]
        print 
Пример #4
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']