def plotSourceFit(self, srcName, color='black'): self._importPlotter() nobs = num.array(self.logLike.countsSpectrum(srcName, False)) errors = [] for ntilde, nsq in zip(nobs, num.sqrt(self.nobs)): if nsq == 0: errors.append(0) else: errors.append(ntilde/nsq) errors = num.array(errors) model = self._srcCnts(srcName) self.sourceFitPlots.append(self._plotData(nobs)) self._plotSource(srcName, color=color, display=self.sourceFitPlots[-1]) self.sourceFitPlots[-1].setTitle(srcName) resid = (nobs - model)/model resid_err = errors/model self.sourceFitResids.append(self.plotter(self.e_vals, resid, dy=resid_err, xtitle='Energy (MeV)', ytitle='(counts-model)/model', xlog=1, color=color, symbol='plus', xrange=self._xrange())) zeros = num.zeros(len(self.e_vals)) self.sourceFitResids[-1].overlay(self.e_vals, zeros, symbol='dotted') self.sourceFitResids[-1].setTitle(srcName)
def reset_ebounds(self, new_energies): eMin, eMax = self.observation.roiCuts().getEnergyCuts() if eMin != min(new_energies) or eMax != max(new_energies): self.logLike.set_ebounds(min(new_energies), max(new_energies)) elist = [x for x in new_energies] elist.sort() self.energies = num.array(elist) self.e_vals = num.sqrt(self.energies[:-1] * self.energies[1:]) self.nobs = self._Nobs()
def __init__(self, binnedData, srcModel=None, optimizer='Drmngb', use_bl2=False, verbosity=0, psfcorr=True, wmap=None, config=None, delete_local_fixed=False): AnalysisBase.__init__(self) if srcModel is None: srcModel, optimizer = self._srcDialog() self.binnedData = binnedData self.srcModel = srcModel self.optimizer = optimizer if wmap and wmap != "none": self.wmap = pyLike.WcsMapLibrary.instance().wcsmap(wmap, "") self.wmap.setInterpolation(False) self.wmap.setExtrapolation(True) else: self.wmap = None if use_bl2: raise ValueError("BinnedLikelihood2 is no longer supported") if config is None: config = BinnedConfig(applyPsfCorrections=psfcorr, delete_local_fixed=delete_local_fixed) self.logLike = pyLike.BinnedLikelihood(binnedData.countsMap, binnedData.observation, config, binnedData.srcMaps, self.wmap) self.verbosity = verbosity self.logLike.initOutputStreams() self.logLike.readXml(srcModel, _funcFactory, False, True, False) self.model = SourceModel(self.logLike, srcModel) self.energies = num.array(self.logLike.energies()) self.e_vals = num.sqrt(self.energies[:-1] * self.energies[1:]) self.nobs = self.logLike.countsSpectrum() self.nobs_wt = self.logLike.countsSpectrum(True) self.sourceFitPlots = [] self.sourceFitResids = []
def __init__(self, observation, srcModel=None, optimizer='Drmngb', nee=21): AnalysisBase.__init__(self) if srcModel is None: srcModel, optimizer = self._srcDialog() self.observation = observation self.srcModel = srcModel self.optimizer = optimizer self.logLike = pyLike.LogLike(self.observation.observation) self.logLike.initOutputStreams() self.logLike.readXml(srcModel, _funcFactory, True, True, False) self.logLike.computeEventResponses() self.model = SourceModel(self.logLike, srcModel) eMin, eMax = self.observation.roiCuts().getEnergyCuts() estep = num.log(eMax/eMin)/(nee-1) self.energies = eMin*num.exp(estep*num.arange(nee, dtype=num.float)) self.energies[-1] = eMax self.e_vals = num.sqrt(self.energies[:-1]*self.energies[1:]) self.nobs = self._Nobs() self.nobs_wt = self.nobs self.disp = None self.resids = None self.sourceFitPlots = [] self.sourceFitResids = []