Example #1
0
def draw_everything(optics, trace, xrange, yrange, three_d=None):

    g = graphite.Graph()
    g.top = 10
    g.left = 100
    g.right = g.left + 700
    g.bottom = g.top + 300
    g.axes[graphite.X].range = xrange
    g.axes[graphite.Y].range = yrange
    g.formats = []
    if three_d:
        g.axes[graphite.Z].range = (-0.5, 0.5)
        g.lookAt = (-.25, -1.0, 0)
        g.eyePosition = (-.75, -2, 0.25)

    draw_layout(g, optics)
    draw_trace(g, trace)

    g.axes[graphite.Y].tickMarks[0].labels = "%+.1f"
    g.axes[graphite.Y].label.text = "meters"
    g.axes[graphite.Y].tickMarks[0].inextent = 0.02
    g.axes[graphite.Y].tickMarks[0].labelStyle = graphite.TextStyle(
        hjust=graphite.RIGHT,
        vjust=graphite.CENTER,
        font=graphite.Font(10, 0, 0, 0, None),
        color=graphite.Color(0.00, 0.00, 0.00))
    g.axes[graphite.Y].tickMarks[0].labeldist = -0.01

    g.axes[graphite.X].tickMarks[0].labels = "%+.1f"
    g.axes[graphite.X].label.text = "meters"
    g.axes[graphite.X].tickMarks[0].inextent = 0.02
    g.axes[graphite.X].tickMarks[0].labelStyle = graphite.TextStyle(
        hjust=graphite.CENTER,
        vjust=graphite.TOP,
        font=graphite.Font(10, 0, 0, 0, None),
        color=graphite.Color(0.00, 0.00, 0.00))
    g.axes[graphite.X].tickMarks[0].labeldist = -0.01

    return g
Example #2
0
def test1():
    try:
        scope.lock()
        scope.write("*rst")
        #vxi_11.vxi_11_connection.abort(scope)
        print scope.core.port, scope.abort_channel.port, scope.idn

        grablen = 512
        loops = 1
        averages = 16
        mode = "real"
        timerange = 1e-5

        if mode == "rep":
            scope.average_mode(averages)
        else:
            scope.realtime_mode(grablen)

        if 1:  #do setup, which should always be done if the scope has been unlocked, since someone else might have used it.
            scope.set_edge_trigger(2,
                                   level=0,
                                   slope=-1,
                                   auto_trigger=1,
                                   coupling=scope.ac)
            scope.set_timebase(range=timerange)
            scope.set_channel(2,
                              range=5,
                              offset=2.5,
                              coupling=scope.dc,
                              lowpass=0,
                              impedance=None)
            scope.set_channel(3,
                              range=0.1,
                              offset=0,
                              coupling=scope.dc,
                              lowpass=0,
                              impedance=None)

        sum = None

        for i in range(loops):
            scope.digitize((2, 3))
            scope.wait_for_done(sleep=0.1, max_loops=100)
            waveform = Numeric.array(scope.get_current_data((2, 3)))

            if sum is None:
                sum = waveform
            else:
                sum += waveform

            print i

        sum *= (1.0 / loops)

        scope.unlock()

        g = graphite.Graph()
        g.formats = [dots(graphite.green), dots(graphite.red)]

        axis = g.axes[graphite.X]
        tick = axis.tickMarks[0]
        tick.labels = "%.2g"
        axis.label.text = "μSeconds"
        #tick.spacing = 0.05
        #axis.range=[-tick.spacing,plottime]
        axis.label.points[0] = (0., -0.1, 0.)  #move label closer to axis

        axis = g.axes[graphite.Y]
        tick = axis.tickMarks[0]
        tick.labels = "%+.3f"
        axis.label.text = "Volts"
        tick.inextent = 0.02
        tick.labelStyle = graphite.TextStyle(
            hjust=graphite.RIGHT,
            vjust=graphite.CENTER,
            font=graphite.Font(10, 0, 0, 0, None),
            color=graphite.Color(0.00, 0.00, 0.00))
        tick.labeldist = -0.01
        axis.label.points[0] = (-0.07, 0, 0.)  #move label closer to axis

        g.top = 25
        g.bottom = g.top + 400
        g.left = 100
        g.right = g.left + 600

        d = graphite.Dataset()
        d.x = scope.xaxis * 1e6
        d.y = sum[0]
        g.datasets.append(d)

        d = graphite.Dataset()
        d.x = scope.xaxis * 1e6
        d.y = sum[1]
        g.datasets.append(d)

        graphite.genOutput(g, 'QD', canvasname="Scope data", size=(800, 500))
        #graphite.genOutput(g,'PDF',canvasname="Scope_data", size=(800,500))
    except:
        scope.unlock_completely()
        scope.abort()
        traceback.print_exc()
Example #3
0
        splint(xlist, ylist, y2, (1, 2, 2.5, 3, -5, 4, 5, 6, 7, 8, 9, 10, 11,
                                  12, 13, 14, 15, 16, 17, 18))
    except:
        traceback.print_exc()

    try:

        xx, yy, yy2 = spline_extrapolate(xlist,
                                         ylist,
                                         yp1=None,
                                         ypn=-2.5,
                                         xmin=xlist[0] - 2,
                                         xmax=xlist[-1] + 2)
        import graphite
        import numpy
        g = graphite.Graph()
        ds1 = graphite.Dataset()
        ds1.x = xx
        ds1.y = yy
        g.datasets.append(ds1)
        f1 = graphite.PointPlot()
        f1.lineStyle = None
        f1.symbol = graphite.CircleSymbol
        f1.symbolStyle = graphite.SymbolStyle(size=5,
                                              fillColor=graphite.red,
                                              edgeColor=graphite.red)
        g.formats = []
        g.formats.append(f1)
        finex = numpy.array(range(-20, 181), float) * 0.1
        finey = splint(xx, yy, yy2, finex)
        ds2 = graphite.Dataset()
def test1():
    try:
        scope.lock()
        # scope.write("*rst")
        # vxi_11.vxi_11_connection.abort(scope)
        print scope.core.port, scope.abort_channel.port, scope.idn

        #scope.set_edge_trigger(1, level=0.10, slope=1, auto_trigger=0, coupling=scope.dc)
        scope.set_edge_trigger(4,
                               level=0.9,
                               slope=1,
                               auto_trigger=0,
                               coupling=scope.dc)
        scope.set_channel(1,
                          range=1,
                          offset=0,
                          coupling=scope.ac,
                          atten=10.0,
                          lowpass=0,
                          impedance=None)
        scope.set_channel(2,
                          range=5,
                          offset=0,
                          coupling=scope.dc,
                          atten=1.0,
                          lowpass=0,
                          impedance=None)
        scope.set_channel(3,
                          range=1,
                          offset=1.2,
                          coupling=scope.dc,
                          atten=10.0,
                          lowpass=1,
                          impedance=None)
        scope.set_channel(4,
                          range=1,
                          offset=0.4,
                          coupling=scope.dc,
                          atten=1.0,
                          lowpass=0,
                          impedance=50)
        scope.end_sequential_mode()

        plotqd = 1
        plotpdf = 0
        xrange = None
        channels = (1, 2, 3)

        if 0:  # plot one really slow plot
            grablen = 8192
            timerange = 1e-2
            loops = 1
            plotskip = 1
            scope.realtime_mode(grablen)
            scope.set_timebase(range=timerange,
                               reference=scope.left,
                               delay=-2e-8)
            #timescale=1e6; timename="μSeconds"
            timescale = 1e3
            timename = "milliSeconds"
            #timescale=1e9; timename="nanoSeconds"
            # xrange=[-20,60]
            channels = (2, 3)
        if 1:
            timerange = 2e-7
            loops = 1
            plotskip = 1
            scope.sequential_mode(npoints=80, nsegments=50)
            scope.set_timebase(range=timerange,
                               reference=scope.left,
                               delay=770e-9)
            timescale = 1e9
            timename = "nanoSeconds"
            channels = (1, 2)
            plotqd = 1
            plotpdf = 1

        if 0:
            grablen = 512
            timerange = 1e-7
            loops = 1
            plotskip = 1
            scope.realtime_mode(grablen)
            scope.set_timebase(range=timerange,
                               reference=scope.left,
                               delay=-2e-7)
            #timescale=1e6; timename="μSeconds"
            timescale = 1e9
            timename = "nanoSeconds"
            # xrange=[-50,60]
            channels = (1, 2, 3, 4)
        if 0:
            timerange = 2e-7
            loops = 1
            plotskip = 1
            scope.sequential_mode(npoints=50, nsegments=1000)
            scope.set_timebase(range=timerange,
                               reference=scope.left,
                               delay=-2e-9)
            timescale = 1e9
            timename = "nanoSeconds"
            plotqd = 0
            plotpdf = 0

        if 0:
            timerange = 1e-7
            loops = 1
            plotskip = 1
            scope.set_timebase(range=timerange,
                               reference=scope.left,
                               delay=-2e-9)
            scope.average_mode(16)
            xrange = [-20, 60]
            timescale = 1e9
            timename = "nanoSeconds"

        sum = None

        for i in range(loops):
            scope.digitize(channels)
            scope.wait_for_done(sleep=0.1, max_loops=1000)
            waveform = Numeric.array(scope.get_current_data(channels))

            if sum is None:
                sum = waveform
            else:
                sum += waveform

        try:
            # if we have tags, print them as multiples of 1/480 second
            times = (scope.get_time_tags() * 480 + 0.5).astype(Numeric.Int)
            oops = Numeric.nonzero((times[1:] - times[:-1]) - 1)
            print oops
            print oops[1:] - oops[:-1]

            ranges = []
            np = scope.preamble["POINTS"]
            for i in oops:
                ranges += range((i - 5) * np, (i + 5) * np)
            sum = Numeric.take(sum, ranges, -1)
            scope.xaxis = Numeric.take(scope.xaxis, ranges, -1)

        except exceptions.AssertionError:
            pass

        sum *= (1.0 / loops)

        scope.unlock()

        if plotqd or plotpdf:

            g = graphite.Graph()

            axis = g.axes[graphite.X]
            tick = axis.tickMarks[0]
            tick.labels = "%.0f"
            scope.xaxis *= timescale
            axis.label.text = timename
            #tick.spacing = 0.05
            if xrange is not None:
                axis.range = xrange

            axis.label.points[0] = (0., -0.1, 0.)  # move label closer to axis

            axis = g.axes[graphite.Y]
            tick = axis.tickMarks[0]
            tick.labels = "%+.3f"
            axis.label.text = "Volts"
            tick.inextent = 0.02
            tick.labelStyle = graphite.TextStyle(
                hjust=graphite.RIGHT,
                vjust=graphite.CENTER,
                font=graphite.Font(10, 0, 0, 0, None),
                color=graphite.Color(0.00, 0.00, 0.00))
            tick.labeldist = -0.01
            axis.label.points[0] = (-0.07, 0, 0.)  # move label closer to axis

            g.top = 25
            g.bottom = g.top + 400
            g.left = 100
            g.right = g.left + 600

            for row in sum:
                d = graphite.Dataset()
                d.x = scope.xaxis[::plotskip]
                d.y = row[::plotskip]
                g.datasets.append(d)

            if plotqd:
                g.formats = [
                    dots(graphite.green),
                    dots(graphite.red),
                    dots(graphite.blue),
                    dots(graphite.orange)
                ]
                graphite.genOutput(g,
                                   'QD',
                                   canvasname="Scope data",
                                   size=(800, 500))
            if plotpdf:
                g.formats = [
                    lines(graphite.green),
                    lines(graphite.red),
                    lines(graphite.blue),
                    lines(graphite.orange)
                ]
                graphite.genOutput(g,
                                   'PDF',
                                   canvasname="Scope_data",
                                   size=(800, 500))

    except:
        scope.clear()
        scope.unlock_completely()
        scope.abort()
        traceback.print_exc()
Example #5
0
def plotq(trace):
    qxl = []
    qyl = []
    zl = []
    for i in trace:
        zl.append(i.total_drift)
        qi = i.incoming_q
        qix, qiy = i.transform_q_to_table(qi)
        #xform, qix, qiy=qi.qi_moments()
        qxl.append(qi.rw(qix)[1])
        qyl.append(qi.rw(qiy)[1])
        zl.append(i.total_drift)
        qi = i.q
        qix, qiy = i.transform_q_to_table(qi)
        #xform, qix, qiy=qi.qi_moments()
        qxl.append(qi.rw(qix)[1])
        qyl.append(qi.rw(qiy)[1])

    g = graphite.Graph()
    g.top = 10
    g.left = 100
    g.right = g.left + 700
    g.bottom = g.top + 300
    # g.axes[graphite.X].range=xrange
    # g.axes[graphite.Y].range=yrange
    g.formats = []

    dsx = graphite.Dataset()
    dsx.x = zl
    dsx.y = qxl
    g.datasets.append(dsx)
    colorline = graphite.PointPlot()
    colorline.lineStyle = graphite.LineStyle(width=1,
                                             color=graphite.red,
                                             kind=graphite.SOLID)
    colorline.symbol = None
    g.formats.append(colorline)

    dsy = graphite.Dataset()
    dsy.x = zl
    dsy.y = qyl
    g.datasets.append(dsy)
    colorline = graphite.PointPlot()
    colorline.lineStyle = graphite.LineStyle(width=1,
                                             color=graphite.blue,
                                             kind=graphite.SOLID)
    colorline.symbol = None
    g.formats.append(colorline)

    g.axes[graphite.Y].tickMarks[0].labels = "%+.3f"
    g.axes[graphite.Y].label.text = "meters"
    g.axes[graphite.Y].tickMarks[0].inextent = 0.02
    g.axes[graphite.Y].tickMarks[0].labelStyle = graphite.TextStyle(
        hjust=graphite.RIGHT,
        vjust=graphite.CENTER,
        font=graphite.Font(10, 0, 0, 0, None),
        color=graphite.Color(0.00, 0.00, 0.00))
    g.axes[graphite.Y].tickMarks[0].labeldist = -0.01

    g.axes[graphite.X].tickMarks[0].labels = "%+.0f"
    g.axes[graphite.X].label.text = "meters"
    g.axes[graphite.X].tickMarks[0].inextent = 0.02
    g.axes[graphite.X].tickMarks[0].labelStyle = graphite.TextStyle(
        hjust=graphite.CENTER,
        vjust=graphite.TOP,
        font=graphite.Font(10, 0, 0, 0, None),
        color=graphite.Color(0.00, 0.00, 0.00))
    g.axes[graphite.X].tickMarks[0].labeldist = -0.01

    if show_qd:
        graphite.genOutput(g, 'QD', canvasname="Beam size", size=(900, 500))
    if show_pdf:
        graphite.genOutput(g, 'PDF', canvasname="Q_plot", size=(900, 500))