Beispiel #1
0
def Image(nt, colname=None, x=None, y=None, xname='x', yname='y',
          zlog=0, aspect=0, transform=None, title=""):
    if colname is None:
        colname = nt.getLabel(0)
    image = hippo.Display("Image", nt, (colname, ))

    image.setLog( "z", zlog )
    image.setAspectRatio( aspect )
    if (transform):
        image.setTransform(transform)

    if x is not None:
        image.setNumberOfBins('x', len(x))
        xstep = x[1] - x[0]
        image.setBinWidth("x", xstep, 1)
        image.setOffset("x", x[0] - xstep)
        image.setRange('x', x[0], x[-1], 1)
        image.setLabel("x", xname)
        
    if y is not None:
        image.setNumberOfBins('y', len(y))
        ystep = y[1] - y[0]
        image.setBinWidth("y", ystep, 1)
        image.setOffset("y", y[0] - ystep)
        image.setRange('y', y[0], y[-1], 1)
        image.setLabel("y", yname)

    Canvas().addDisplay(image)
    return image
Beispiel #2
0
def image(zData, x=None, y=None, xname='x', yname='y', zname="z values",
          zlog=0, aspect=0, transform=None, title=""):
    import copy
    nt = newNTuple( (zData.flat, ), (zname, ) )
    
    disp = hippo.Display("Image", nt, (zname, ))
    
    disp.setLog( "z", zlog )
    disp.setAspectRatio( aspect )
    if (transform):
        disp.setTransform(transform)

    disp.setNumberOfBins('x', len(x))
    disp.setNumberOfBins('y', len(y))

    xstep = x[1]-x[0]
    ystep = y[1]-y[0]
    disp.setBinWidth("x", xstep, 1)
    disp.setBinWidth("y", ystep, 1)

    disp.setOffset("x", x[0] - xstep)
    disp.setOffset("y", y[0] - ystep)

    disp.setRange('x', x[0], x[-1], 1)
    disp.setRange('y', y[0], y[-1], 1)

    disp.setLabel("x", xname)
    disp.setLabel("y", yname)

    Canvas().addDisplay(disp)
    return disp
Beispiel #3
0
 def __init__(self, xrange=(-1, 1), xBinWidth = 0.1, title="", xlabel="",
              color=None):
     self.display = hippo.Display( "Static Histogram" )
     self.display.setTitle(title)
     self.display.setLabel("x", xlabel)
     self.display.setRange("x", xrange[0], xrange[1], 1)
     self.display.setBinWidth("x", xBinWidth, 1)
     Canvas().addDisplay( self.display )
     if color:
         rep = self.display.getDataRep()
         rep.setColor(color)
Beispiel #4
0
 def __init__(self, xrange=(-1, 1), yrange=(-1, 1),
              xBinWidth=0.1, yBinWidth=0.1,
              title="", xlabel="", ylabel=""):
     self.display = hippo.Display( "Static 2D Histogram" )
     self.display.setTitle(title)
     self.display.setLabel("x", xlabel)
     self.display.setLabel("y", ylabel)
     self.display.setRange("x", xrange[0], xrange[1], 1)
     self.display.setRange("y", yrange[0], yrange[1], 1)
     self.display.setBinWidth("x", xBinWidth, 1)
     self.display.setBinWidth("y", yBinWidth, 1)
     Canvas().addDisplay( self.display )
Beispiel #5
0
def ZPlot(nt):
    registerNTuple(nt)
    image = hippo.Display("Image", nt, (nt.getLabel(2), ))
    axes = ("x", "y")
    labels = nt.getLabels()
    for axis, label in zip(axes, labels):
        array = uniq( nt.getColumn(label) )
        image.setNumberOfBins(axis, len(array))
        image.setBinWidth(axis, array[1]-array[0], 1)
        image.setRange(axis, min(array), max(array), 1)
        image.setOffset(axis, min(array))
    Canvas().addDisplay( image )
    return image
Beispiel #6
0
def simpleLightCurve(ntuple, column, numberbins=1024):
    hist = hippo.Display("Histogram", ntuple, (column, ))
    ticks = ntuple.getColumn(column)

    hist.setRange('x', ticks[0], ticks[-1])

    width = (ticks[-1] - ticks[0]) / numberbins
    hist.setBinWidth('x', width)

    hdata = hist.createNTuple()
    bintimes = num.array(hdata.getColumn(1))
    widths = hdata.getColumn(2)
    bintimes *= widths
    bintimes *= 2.0
    return hist, bintimes
Beispiel #7
0
    def display_with_hippo():
        import hippo
        if not 'app' in dir():
            app = hippo.HDApp()
            canvas = app.canvas()

        def create_data_rep(dist):
            print hippo.DataRep.names()
            ds = hippo.ListTuple()
            ds.addColumn('p(binding)', dist.keys())
            ds.addColumn('count', dist.values())
            return hippo.DataRep('XY Plot', ds, ['p(binding)', 'count', 'nil'])

        # show a graph
        # print score_dists[ pssm_acc ]
        xy = hippo.Display("XY Plot")
        xy.addDataRep(create_data_rep(dists['all']))
        canvas.addDisplay(xy)
Beispiel #8
0
def displayHandler( displayType, nt, columns, logScales, axisLimits,
                    pointRep, title="", oplot=0, color=None, lineStyle=None,
                    addToCanvas=1, autoscale=0, select=1 ):
    """
    Wrapper for hippo.Display and the QtDisplay class set methods.
    """
    Canvas()
    if not oplot:
        #
        # Create a new display and set the various options.
        #
        display = hippo.Display( displayType, nt, columns )
        if addToCanvas:
            Canvas().addDisplay( display )
        Axes = ('x', 'y', 'z')
        for logScale, axis in zip(logScales, Axes):
            if logScale:
                display.setLog( axis, 1 )
        for limits, axis in zip(axisLimits, Axes):
            if len(limits) == 2:
                display.setRange( axis, limits[0], limits[1], 1 )
        display.setPointRep( prf.create(pointRep) )
        if title != "":
            display.setTitle(title)
        if color:
            rep = display.getDataRep()
            rep.setColor(color)
        if lineStyle:
            rep = display.getDataRep()
            rep.setLineStyle(lineStyle)
        if select:
            Canvas().selectDisplay(display)
        return display
    else:
        #
        # Add to the currently selected display if possible.
        #
        currentDisplay = Canvas().getDisplay()
        if currentDisplay:
            if not autoscale:
                #
                # Save the current axis ranges.
                #
                xr = currentDisplay.getRange('x')
                yr = currentDisplay.getRange('y')
            #
            # Create a new DataRep
            #
            rep = hippo.DataRep( displayType, nt, columns )
            rep.setPointRep( prf.create( pointRep ) )
            currentDisplay.addDataRep( rep )
            if color:
                rep.setColor(color)
            if lineStyle:
                rep.setLineStyle(lineStyle)
            if not autoscale:
                #
                # Restore the axis ranges
                #
                currentDisplay.setRange('x', xr[0], xr[1])
                currentDisplay.setRange('y', yr[0], yr[1])
            return rep
Beispiel #9
0
canvas.addDisplay ( lightcurve )

#
# Calculate the power spectrum by giving hippo the range and unit of
# time
#
range = lightcurve.getRange ( 'x' )
onetick = 1. / 20.0e6
spectrum = hippofft.powerSpectrum ( bintimes, range, onetick )

#
# The spectrum return is ntuple of two columns which can be used
# directly to plot it as an XY plot
#
labels = spectrum.getLabels()
xyplot = hippo.Display ( 'XY Plot', spectrum, labels )
canvas.addDisplay ( xyplot )

#
# Check that the power distribution is correct by first histogramming
# it
#
hist = hippo.Display ( 'Histogram', spectrum, (labels[1], ) )
hist.setLog ( 'y', True )
canvas.addDisplay ( hist )

#
# and then fitting it to an exponential
#
datarep = hist.getDataRep()
exp = hippo.Function ( 'Exponential', datarep )