Example #1
0
    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)
Example #2
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
Example #3
0
            return 1
        indx = bisect.bisect(x, xval) - 1
        yval = ((xval - x[indx]) / (x[indx + 1] - x[indx]) *
                (y[indx + 1] - y[indx]) + y[indx])
        return yval


if __name__ == '__main__':
    seps = num.concatenate(
        (num.arange(12, 19), num.arange(19, 21, 0.3), num.arange(21, 25)))

    energies = (30, 100, 1000, 1e4)
    #    energies = (1e3, 3e3, 1e4, 3e4)
    incs = (0, 10, 30)

    nt = plot.newNTuple(([], [], []), ('energy', 'inc', 'ks prob'))
    plot.Scatter(nt, 'energy', 'ks prob')
    plot.Scatter(nt, 'inc', 'ks prob')

    def createPlots(irfs, seps, energies, inclinations):
        my_tests = PsfTests(irfs, seps)
        for energy in energies:
            for inclination in inclinations:
                my_tests.plotResults(energy, inclination, plot_residuals=True)
                nt.addRow(my_tests.plot_rspgenIntegral(energy, inclination))

#    irfs = ('testIrfs::Front',) # 'testIrfs::Back')
##            'Glast25::Front', 'Glast25::Back',
##            'DC1::Front', 'DC1::Back')

#    irfs = ('DC1A::Front', 'DC1A::Back')
Example #4
0
        time += dt
        arrTimes.append(time)
        energies.append(src.energy(time))
        try:
            l, b = src.dir(energies[-1])
        except AttributeError:
            l, b = 0, 0
        glons.append(l)
        glats.append(b)
    return (num.array(arrTimes), num.array(energies), num.array(glons),
            num.array(glats))


import hippoplotter as plot

nt = plot.newNTuple(generateData(my_src, 1e4),
                    ('time', 'energy', 'glon', 'glat'))

plot.Histogram(nt, 'time', xrange=(0, 1e4))
spectrum = plot.Histogram(nt, 'energy', xlog=1, ylog=1)
plot.XYHist(nt, 'glon', 'glat')


@FunctionBaseDecorator
def f(e, e1=300, a=1, b=2, k=1):
    return k * (e / e1)**(-(a + b * num.log(e / e1)))


spectrum.addFunction(f)

#nt2 = plot.newNTuple(generateData(grb_src, 3600),
#                     ('time', 'energy', 'glon', 'glat'))
Example #5
0
#

import sys
sys.path.reverse()
sys.path.append('../python')
sys.path.append('../python')
sys.path.reverse()

from setPath import *
import hippoplotter as plot
from random import gauss, uniform

#
# Create new NTuple with columns (x, y, x^2 + y^2, uniform deviate, index)
#
nt = plot.newNTuple( ([], [], [], [], []), ("x", "y", "z", "unif", "i") )

hist = plot.Histogram( nt, "x" )
xyhist = plot.XYHist( nt, "x", "y" )
profile = plot.Profile( nt, "x", "z" )

mean = 0.
sigma = 1.
npts = 25000

nt.setIntervalCount ( 1000 )
nt.setIntervalEnabled ( 1 )
for i in range(npts):
    x, y = gauss(mean, sigma), gauss(mean, sigma)
    z = x*x + y*y
    nt.addRow( (x, y, z, uniform(0,1), i) )