Exemplo n.º 1
0
    def _plot_model(self,
                    source,
                    yrange=None,
                    lineStyle="Dot",
                    oplot=False,
                    color='black'):
        import hippoplotter as plot
        if oplot and self.disp is not None:
            plot.canvas.selectDisplay(self.disp)
        else:
            self.plotData(yrange)

        self.col = lambda x: num.array(self.data_nt.getColumn(x))

        energies = self.col('energy')
        try:
            model = self._srcCnts(source)
        except:
            model = source
        plot.scatter(energies,
                     model,
                     oplot=True,
                     pointRep='Line',
                     lineStyle=lineStyle,
                     color=color)
        return model
Exemplo n.º 2
0
 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]
Exemplo n.º 3
0
        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)
Exemplo n.º 4
0
        f1 = self.func(my_args)
        return (f1 - f0)/delta
    def dimensions(self):
        return self._dims
    def __setitem__(self, parname, value):
        values = list(self.getParameters())
        names = list(self.parmNames())
        try:
            values[names.index(parname)] = value
            self.setParameters(values)
        except ValueError:
            pass
    def clone(self):
        _clones.append(FunctionBaseDecorator(self.func))
        return _clones[-1]
    def register(self):
        from hippo import FunctionFactory
        FunctionFactory.instance().add(self)

if __name__ == '__main__':
    import hippoplotter as plot
    disp = plot.scatter([-2, 2], [-1, 2])
    f = FunctionBaseDecorator(lambda x, a=1, b=0: a*x + b)

    @FunctionBaseDecorator
    def g(x, a=1, b=0):
        return a*x**2 + b

    disp.addFunction(f)
    disp.addFunction(g)
Exemplo n.º 5
0
    for i in range(len(irfNames)):
        irfNames[i] += section
    lineStyles = ('Solid', 'DashDot', 'Dot', 'Dash')
    colors = ('black', 'red', 'green', 'blue')

    psf_plot = None
    aeff_plot = None
    for irfName, style, color in zip(irfNames, lineStyles, colors):
        psf = Psf(irfName, energy=5e2)

        if psf_plot is None:
            psf_plot = plot.scatter(sep,
                                    psf(sep),
                                    'separation',
                                    'Psf',
                                    xlog=1,
                                    ylog=1,
                                    xrange=(0.01, 30),
                                    color=color,
                                    pointRep='Line',
                                    lineStyle=style)
        else:
            plot.canvas.selectDisplay(psf_plot)
            plot.scatter(sep,
                         psf(sep),
                         pointRep='Line',
                         oplot=1,
                         lineStyle=style,
                         color=color)

        aeff = Aeff(irfName)
        if aeff_plot is None:
Exemplo n.º 6
0
    def __setitem__(self, parname, value):
        values = list(self.getParameters())
        names = list(self.parmNames())
        try:
            values[names.index(parname)] = value
            self.setParameters(values)
        except ValueError:
            pass

    def clone(self):
        _clones.append(FunctionBaseDecorator(self.func))
        return _clones[-1]

    def register(self):
        from hippo import FunctionFactory
        FunctionFactory.instance().add(self)


if __name__ == '__main__':
    import hippoplotter as plot
    disp = plot.scatter([-2, 2], [-1, 2])
    f = FunctionBaseDecorator(lambda x, a=1, b=0: a * x + b)

    @FunctionBaseDecorator
    def g(x, a=1, b=0):
        return a * x**2 + b

    disp.addFunction(f)
    disp.addFunction(g)