def _plot_residuals(self, model, oplot=None, color='black'): import hippoplotter as plot resid = (self.col('nobs') - model) / model resid_err = self.col('nobs_err') / model energies = self.col('energy') nt = plot.newNTuple((energies, resid, resid_err), ('energy', 'residuals', 'resid_err')) if oplot and self.resids is not None: plot.canvas.selectDisplay(self.resids) rep = plot.XYPlot(nt, 'energy', 'residuals', yerr='resid_err', xlog=1, oplot=1, color=color) rep.setSymbol('filled_square', 2) else: self.resids = plot.XYPlot(nt, 'energy', 'residuals', yerr='resid_err', xlog=1, color=color, yrange=(-1, 1)) self.resids.getDataRep().setSymbol('filled_square', 2) plot.hline(0)
def plotResults(self, energy, inclination, ntrials=20, nsamp=100, plot_residuals=False): self._setPsf(energy, inclination) self._setRoi(roiRadius=20) nobs = [] nobserr = [] npreds = [] colnames = ('separation', 'Npred', 'Nobs', 'Nobserr', 'Nobs - Npred') nt = plot.newNTuple( [[]]*len(colnames), colnames) display = plot.Scatter(nt, 'separation', 'Npred', pointRep='Line') display.setRange('y', 0, 1.1) plot.XYPlot(nt, 'separation', 'Nobs', yerr='Nobserr', color='red', oplot=1) display.setRange('x', min(seps), max(seps)) display.setTitle("%s: %i MeV, %.1f deg" % (self.irfs, self.energy, self.inc)) if plot_residuals: resid_display = plot.XYPlot(nt, 'separation', 'Nobs - Npred', yerr='Nobserr') resid_display.setRange('x', min(seps), max(seps)) resid_display.setTitle("%s: %i MeV, %.1f deg" % (self.irfs, self.energy, self.inc)) plot.hline(0) resid_display.setAutoRanging('y', True) for sep in self.seps: nobs, nerr = self._SampleDist(sep) npred = self._Npred(sep) nt.addRow( (sep, npred, nobs, nerr, nobs-npred) ) return nt, display
def plot_rspgenIntegral(self, energy, inclination, phi=0, nsamp=2000): rmin = 1e-2 rmax = 30. npts = 20 rstep = num.log(rmax / rmin) / (npts - 1) radii = rmin * num.exp(rstep * num.arange(npts)) self._setPsf(energy, inclination, phi) seps = [] srcDir = SkyDir(180, 0) for i in range(nsamp): appDir = self.psf.appDir(energy, srcDir, self.scZAxis, self.scXAxis) seps.append(appDir.difference(srcDir) * 180. / num.pi) seps.sort() fraction = num.arange(nsamp, type=num.Float) / nsamp disp = plot.scatter(seps, fraction, xlog=1, xname='ROI radius', yname='enclosed Psf fraction', pointRep='Line', color='red') disp.setTitle("%s: %i MeV, %.1f deg" % (self.irfs, energy, inclination)) npred = [] resids = [] for radius in radii: npred.append( self.psf.angularIntegral(energy, inclination, phi, radius)) resids.append( num.abs( (self._interpolate(seps, fraction, radius) - npred[-1]) / npred[-1])) plot.scatter(radii, npred, pointRep='Line', oplot=1) residplot = plot.scatter(radii, resids, 'ROI radius', yname='abs(sim - npred)/npred', xlog=1, ylog=1) # Npred = Interpolator(radii, npred) ks_prob = ks2(npred, seps) plot.hline(0) residplot.setTitle("%s: %i MeV, %.1f deg\n ks prob=%.2e" % (self.irfs, energy, inclination, ks_prob[1])) return energy, inclination, ks_prob[1]
def eblPlot(model=pySources.Primack05): atten = pySources.EblAtten(model) tau = [] for z in zvalues: foo = FunctionWrapper(lambda energy: atten(energy, z)) tau.append(foo(energies)) tau = num.array(tau) disp = plot.image(tau, num.log10(energies) - 3, num.log10(zvalues), xname='log10(E/GeV)', yname='log10(z)', zname='tau', aspect=1) disp.setPointRep(plot.prf.create('Contour')) disp.setContourLevels((0.5, 1, 2, 3, 5)) disp.setRange('z', 0, 6) plot.canvas.selectDisplay(disp) for id in blazars: plot.hline(num.log10(blazars[id])) plot.vline(num.log10(20. / 2e3)) plot.vline(num.log10(2e5 / 2e3)) return disp
srcNames = self.like.sourceNames() freeNpred = 0 totalNpred = 0 for src in srcNames: npred = self.like.NpredValue(src) totalNpred += npred if self.like.normPar(src).isFree(): freeNpred += npred return freeNpred, totalNpred class UpperLimits(dict): def __init__(self, like): dict.__init__(self) self.like = like for srcName in like.sourceNames(): self[srcName] = UpperLimit(like, srcName) if __name__ == '__main__': import hippoplotter as plot from analysis import like ul = UpperLimits(like) print ul['point source 0'].compute(renorm=True) results = ul['point source 0'].results[0] plot.scatter(results.parvalues, results.dlogLike, xname='par value', yname='dlogLike') plot.hline(2.71 / 2)