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 _srcCnts(self, srcName): cnts = num.array(self.logLike.modelCountsSpectrum(srcName)) return cnts
def _srcCnts(self, srcName, weighted=False): cnts = num.array(self.logLike.modelCountsSpectrum(srcName, weighted)) return cnts
def _srcCnts(self, srcName): source = self.logLike.getSource(srcName) cnts = [] for emin, emax in zip(self.energies[:-1], self.energies[1:]): cnts.append(source.Npred(emin, emax)) return num.array(cnts)
def _Nobs(self): return num.array(self.observation.eventCont().nobs(self.energies))