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()
Exemple #2
0
		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=Numeric.array(range(-20,181),Float)*0.1
		finey=splint(xx, yy, yy2, finex)
		ds2=graphite.Dataset()
		ds2.x=finex
		ds2.y=finey
		g.datasets.append(ds2)
		f2 = graphite.PointPlot()
		f2.lineStyle = graphite.LineStyle(width=1, color=graphite.green, kind=graphite.SOLID)
		f2.symbol = None
		g.formats.append(f2)
		g.bottom=400
		g.right=700
		try:
			graphite.genOutput(g,'QD', size=(800,500))
		except:
			graphite.genOutput(g,'PDF', size=(800,500))
	except:
		import traceback
		traceback.print_exc()
		print "Graphite not available... plotted results not shown"
		
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:
            times = (scope.get_time_tags() * 480 + 0.5).astype(
                Numeric.Int
            )  # if we have tags, print them as multiples of 1/480 second
            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, -0.1, 0.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.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()
Exemple #4
0
        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()
        ds2.x = finex
        ds2.y = finey
        g.datasets.append(ds2)
        f2 = graphite.PointPlot()
        f2.lineStyle = graphite.LineStyle(width=1,
                                          color=graphite.green,
                                          kind=graphite.SOLID)
        f2.symbol = None
        g.formats.append(f2)
        g.bottom = 400
        g.right = 700
        try:
            graphite.genOutput(g, 'QD', size=(800, 500))
        except:
            graphite.genOutput(g, 'PDF', size=(800, 500))
    except:
        import traceback
        traceback.print_exc()
        print "Graphite not available... plotted results not shown"
Exemple #5
0
	poles=20
	zfreq=0.21345
	pspoints=200
	damping=-20.0/datalen
	noise=1.0
	
	xvals=Numeric.array(range(datalen),Numeric.Float)
	data=Numeric.sin(xvals*(2.0*math.pi*zfreq)) * Numeric.exp(xvals*damping)
	import random
	r=random.Random(1234)
	data+= Numeric.array([r.random()-0.5 for i in range(datalen)])*noise
	
	d2=Numeric.dot(data,data)/datalen #mean-square power
	
	xms, d = memcof(data, poles)
	
	freqlist = [0.5*i/pspoints for i in range(pspoints)]
	pspect = [evlmem(f, d, xms) for f in freqlist]
	
	pssum=2.0*Numeric.sum(pspect)*(0.5/pspoints)
	
	print "input power = ", d2, "output power = ", pssum, "ratio =", pssum/d2
	import graphite
	g=graphite.Graph()
	d=graphite.Dataset()
	d.x=freqlist
	d.y=pspect
	g.datasets=d
	graphite.genOutput(g,'QD',canvasname="Power Spectrum")
	
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()
Exemple #7
0
def show_table():
    inch = 0.0254
    lambda0 = 1.054e-6
    spitfire_exit = Numeric.array((2 * inch, 5 * inch, -0.65))
    compressor_entrance = Numeric.array((45.5 * inch, 2.5 * inch, 46.5 * inch))

    optics = {}
    BLUELINE = 'bl'
    SPLIT = 'split'
    START = 'start'
    COMP = 'compressor'
    QUAD = 'quadrupler'
    IR = 'ir'
    IR_COMP = 'ir compressor'
    BE_TURN = 'be_turn'
    IZ_SCREEN = 'iz'

    optics[START] = null_optic("start", spitfire_exit)
    optics[BLUELINE] = blueline = blue_through_ylf()
    optics[SPLIT] = split1 = reflector("splitter1",
                                       center=(2 * inch, 5 * inch, 3 * inch))
    optics[IR] = irline = ir_line()

    comp = optics[COMP] = blue_compressor(38.5,
                                          1.28,
                                          lambda0,
                                          center=compressor_entrance,
                                          angle=270)
    mainbeam = beam(spitfire_exit, qtens(lambda0, spitfire.q0), lambda0)
    # print mainbeam.q
    split1.set_direction(spitfire_exit, blueline)
    blueline.set_entrance_direction(split1)
    blueline.set_exit_direction(comp)
    comp.rotate_to_axis(blueline)
    q = optics[QUAD] = quadrupler(center=(40 * inch, 2.5 * inch, 34.5 * inch),
                                  from_optic=comp[blue_compressor.TM1])
    comp.set_exit_direction(q)
    q.set_entrance_direction(comp)
    blue_sys = composite_optic("blue_sys", optics,
                               [START, SPLIT, BLUELINE, COMP, QUAD], (0, 0, 0),
                               (0, 0, 0), 0)
    irline.set_entrance_direction(spitfire_exit)

    # align compressor table to output of main IR line
    ir_sys = composite_optic("ir_sys", optics, [START, IR], (0, 0, 0),
                             (0, 0, 0), 0).clone()
    pointer = trace_path(ir_sys, mainbeam.clone())[-1]
    pointer.free_drift(1.0)
    optics[IR_COMP] = ircomp = ir_compressor(center=pointer.x0,
                                             angle=math.atan(0.2) / deg)
    ircomp.set_entrance_direction(irline)

    # now, align IZ
    ir_sys = composite_optic("ir_sys", optics, [START, IR, IR_COMP], (0, 0, 0),
                             (0, 0, 0), 0).clone()
    pointer = trace_path(ir_sys, mainbeam.clone())[-1]
    pointer.free_drift(1.0)
    bemir = optics[BE_TURN] = reflector("be turn mirror",
                                        center=pointer.x0,
                                        angle=45.0)
    bemir.transport_to_here(pointer).transform(pointer)
    pointer.free_drift(0.1)
    dz = pointer.q.next_waist()
    pointer.free_drift(dz)
    optics[IZ_SCREEN] = null_optic("IZ", pointer.x0)
    ir_sys = composite_optic("ir_sys", optics,
                             [START, IR, IR_COMP, BE_TURN, IZ_SCREEN],
                             (0, 0, 0), (0, 0, 0), 0)

    whole_table = composite_optic(
        "whole table", optics,
        [START, SPLIT, BLUELINE, COMP, QUAD, IR, IR_COMP, BE_TURN, IZ_SCREEN],
        (0, 0, 0), (0, 0, 0), 0)

    ir_trace = trace_path(ir_sys, mainbeam.clone())
    ir_trace.color = graphite.red
    blue_trace = trace_path(blue_sys, mainbeam.clone())
    blue_trace.color = graphite.blue

    if table_layout:
        g = draw_everything({"sys": whole_table},
                            ir_trace, (-.25, 5), (0, 2.5),
                            three_d=0)
        draw_trace(g, blue_trace)

        #g=draw_everything({"sys":sys}, trace, (0.5,1.1), (0.8,1.1), three_d=0)
        #g=draw_everything({"sys":sys}, trace, (0.7,1.3), (0.9,1.2), three_d=0)
        if show_qd:
            graphite.genOutput(g,
                               'QD',
                               canvasname="Compressor layout",
                               size=(900, 500))
        if show_pdf:
            graphite.genOutput(g,
                               'PDF',
                               canvasname="Tablelayout",
                               size=(900, 500))
    # print trace[0]
    plotq(blue_trace)

    if 0:
        glabel = ircomp.mark_label(ircomp.INPUT)
        m = ir_trace[(glabel, 0)]
        print("\n\n**start**\n\n")
        print(m.incoming_direction, m.direction())
        print(m.incoming_q)
        print(m.incoming_q.qi_moments()[1:3])
        print(m.incoming_q.q_moments()[1:3])
        print(m.incoming_q.qit, "\n")
        print(m.localize_transform_tensor)
        print(m.footprint_q)
        print(m.footprint_q.qi_moments()[1:3])
        print(m.footprint_q.q_moments()[1:3])
        print(m.footprint_q.qit, "\n")
        print(m.globalize_transform_tensor)
        print(m.q)
        print(m.q.qi_moments()[1:3])
        print(m.q.q_moments()[1:3])
        print(m.q.qit, "\n")

    glabel = ircomp.mark_label(ircomp.INPUT)
    # endpoint=ir_trace[(glabel,0)]  #get first hit on optic <glabel>
    endpoint = ir_trace[-1]
    q = endpoint.q

    t, qx0, qy0 = q.qi_moments()
    theta = math.atan2(t[0, 1].real, t[0, 0].real) / deg
    qxx, qyy = endpoint.transform_q_to_table(q)
    dzx, dzy = (1e6 / qxx).real, (1e6 / qyy).real
    print((
        "qxx = %.1f, dzx = %.0f, qyy=%.1f, dzy=%.0f, (in um), theta=%.1f deg" %
        (q.rw(qxx)[1] * 1e6, dzx, q.rw(qyy)[1] * 1e6, dzy, theta)))
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 = "&mu;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()
Exemple #9
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))
Exemple #10
0
def doit_bc(theta1, clen, lambda0, drawit=0):

    print("\n\n***start blue line trace***\n")
    grating_offset = -0.075
    exit_height = 0
    exit_z = -0.3
    eta1 = 0.0

    optics = {}

    END = 'end'
    optics[END] = null_optic("end", (0.15, exit_height, 0), 0)
    START = 'start'
    optics[START] = null_optic("start", (0, 0, -0.85))

    tracebeam = basebeam.clone()
    system_center = Numeric.array((-0.1, 0, -0.85))

    basebeam = beam(system_center, qtens(lambda0, q=spitfire.q0), lambda0)
    tracebeam.free_drift(-0.2)

    COMP = 'comp'
    comp = optics[COMP] = blue_compressor(theta1,
                                          clen,
                                          lambda0,
                                          center=system_center,
                                          angle=rotation)
    TM2 = 'turn2'
    optics[TM2] = reflector("output turn 2",
                            angle=0,
                            center=(0.15, exit_height, -0.6),
                            width=.025)

    optics[COMP].set_exit_direction(optics[TM2])
    optics[TM2].set_direction(optics[COMP], optics[END])

    sys_order = (START, COMP, TM2, DEMAG1, DEMAG2, END)

    GRATE = comp.mark_label(blue_compressor.GRATE)
    IR1 = comp.mark_label(blue_compressor.IR1)
    IR2 = comp.mark_label(blue_compressor.IR2)

    optic_sys = composite_optic("system",
                                optics,
                                sys_order,
                                center=optics[START].center)

    trace0 = trace_path(optic_sys, tracebeam.shift_lambda(0))
    trace0.color = graphite.green
    trace1 = trace_path(optic_sys, tracebeam.shift_lambda(-0.5e-9))
    trace1.color = graphite.blue
    trace2 = trace_path(optic_sys, tracebeam.shift_lambda(+0.5e-9))
    trace2.color = graphite.red

    try:  # if one of the traces failed, this may not work
        print("Theta1=%.3f eta=%.3f len=%.3f lambda=%.4f" %
              (theta1, eta1, clen, lambda0 * 1e6))
        d0 = trace0[-1]['total_drift']
        d1 = trace1[-1]['total_drift']
        d2 = trace2[-1]['total_drift']
        print((
            "d(lambda0-0.5nm)=%.3f m, d(lambda0+0.5nm)=%.3f m, dt/dl=%.0f ps/nm, "
            % (d1, d2, (d2 - d1) * 1e12 / clight)),
              end=' ')
        print("d2t/dl2 = %.2f ps/nm^2" % ((d2 + d1 - 2.0 * d0) *
                                          (1e12 / clight) * 4))
        spot1info = trace0[(GRATE, 0)]
        spot2info = trace0[(GRATE, 1)]
        ir1info = trace0[(IR1, 0)]
        ir2info = trace0[(IR2, 0)]
        spot_offset = spot2info['position'] - spot1info['position']
        retro_offset = ir2info['position'] - ir1info['position']
        print("Grating offset = %.3f, retro_offset=%.3f" %
              (vec_mag(spot_offset), vec_mag(retro_offset)))
        print("measured vertex length = %.3f" %
              vec_mag(comp[GRATE].center - comp[IR1].center))
        print("dispersion offset on grating = %.3f m / nm" %
              vec_mag(trace2[(GRATE, 1)]['position'] -
                      trace1[(GRATE, 1)]['position']))
        print("final q = ", trace0[-1]['q'])
    except:
        traceback.print_exc()
        pass

    if drawit:
        g = draw_everything({"sys": optic_sys},
                            trace0, (-.9, .1), (-.5, .5),
                            three_d=0)
        #g=draw_everything(optics, trace0, (-2, 2), (-2, 2))
        draw_trace(g, trace1)
        draw_trace(g, trace2)
        graphite.genOutput(g,
                           'QD',
                           canvasname="Compressor layout",
                           size=(600, 500))
def show_table():
	inch=0.0254
	lambda0=1.054e-6
	spitfire_exit=Numeric.array((2*inch, 5*inch, -0.65))
	compressor_entrance=Numeric.array((45.5*inch, 2.5*inch, 46.5*inch))
	
	optics={}
	BLUELINE='bl'
	SPLIT='split'
	START='start'
	COMP='compressor'
	QUAD='quadrupler'
	IR='ir'
	IR_COMP='ir compressor'
	BE_TURN='be_turn'
	IZ_SCREEN='iz'
	
	optics[START]=null_optic("start", spitfire_exit)
	optics[BLUELINE]=blueline=blue_through_ylf()	
	optics[SPLIT]=split1=reflector("splitter1", center=(2*inch, 5*inch, 3*inch))
	optics[IR]=irline=ir_line()
	
	comp=optics[COMP]=blue_compressor(38.5, 1.28, lambda0, center=compressor_entrance, angle=270)
	mainbeam=beam( spitfire_exit, qtens(lambda0, spitfire.q0), lambda0)
	#print mainbeam.q
	split1.set_direction(spitfire_exit, blueline)
	blueline.set_entrance_direction(split1)
	blueline.set_exit_direction(comp)
	comp.rotate_to_axis(blueline)
	q=optics[QUAD]=quadrupler(center=(40*inch, 2.5*inch, 34.5*inch), from_optic=comp[blue_compressor.TM1])
	comp.set_exit_direction(q)
	q.set_entrance_direction(comp)
	blue_sys=composite_optic("blue_sys", optics, [START, SPLIT, BLUELINE, COMP, QUAD], (0,0,0), (0,0,0), 0)
	irline.set_entrance_direction(spitfire_exit)
	
	#align compressor table to output of main IR line
	ir_sys=composite_optic("ir_sys", optics, [START, IR], (0,0,0), (0,0,0), 0).clone()
	pointer=trace_path(ir_sys, mainbeam.clone())[-1]
	pointer.free_drift(1.0)
	optics[IR_COMP]=ircomp=ir_compressor(center=pointer.x0, angle=math.atan(0.2)/deg)
	ircomp.set_entrance_direction(irline)

	#now, align IZ
	ir_sys=composite_optic("ir_sys", optics, [START, IR, IR_COMP], (0,0,0), (0,0,0), 0).clone()
	pointer=trace_path(ir_sys, mainbeam.clone())[-1]
	pointer.free_drift(1.0)
	bemir=optics[BE_TURN]=reflector("be turn mirror", center=pointer.x0, angle=45.0)
	bemir.transport_to_here(pointer).transform(pointer)
	pointer.free_drift(0.1)
	dz=pointer.q.next_waist()
	pointer.free_drift(dz)
	optics[IZ_SCREEN]=null_optic("IZ", pointer.x0)
	ir_sys=composite_optic("ir_sys", optics, [START, IR, IR_COMP, BE_TURN, IZ_SCREEN], (0,0,0), (0,0,0), 0)
	
	whole_table=composite_optic("whole table", optics, [START, SPLIT, BLUELINE, COMP, QUAD, IR, IR_COMP, BE_TURN, IZ_SCREEN], (0,0,0), (0,0,0), 0)
	
	
	ir_trace=trace_path(ir_sys, mainbeam.clone())
	ir_trace.color=graphite.red
	blue_trace=trace_path(blue_sys, mainbeam.clone())
	blue_trace.color=graphite.blue
	
	if table_layout:
		g=draw_everything({"sys":whole_table}, ir_trace, (-.25,5), (0,2.5), three_d=0)
		draw_trace(g, blue_trace)
		
		#g=draw_everything({"sys":sys}, trace, (0.5,1.1), (0.8,1.1), three_d=0)
		#g=draw_everything({"sys":sys}, trace, (0.7,1.3), (0.9,1.2), three_d=0)
		if show_qd:
			graphite.genOutput(g,'QD',canvasname="Compressor layout", size=(900,500))
		if show_pdf:
			graphite.genOutput(g,'PDF',canvasname="Tablelayout", size=(900,500))
	#print trace[0]
	plotq(blue_trace)
	
	if 0:
		glabel=ircomp.mark_label(ircomp.INPUT)
		m=ir_trace[(glabel,0)]
		print "\n\n**start**\n\n"
		print m.incoming_direction, m.direction()
		print m.incoming_q
		print m.incoming_q.qi_moments()[1:3]
		print m.incoming_q.q_moments()[1:3]
		print m.incoming_q.qit, "\n"
		print m.localize_transform_tensor
		print m.footprint_q
		print m.footprint_q.qi_moments()[1:3]
		print m.footprint_q.q_moments()[1:3]
		print m.footprint_q.qit, "\n"
		print m.globalize_transform_tensor
		print m.q
		print m.q.qi_moments()[1:3]
		print m.q.q_moments()[1:3]
		print m.q.qit, "\n"

	glabel=ircomp.mark_label(ircomp.INPUT)
	#endpoint=ir_trace[(glabel,0)]  #get first hit on optic <glabel>
	endpoint=ir_trace[-1]
	q=endpoint.q
	
	t, qx0, qy0=q.qi_moments()
	theta=math.atan2(t[0,1].real, t[0,0].real)/deg
	qxx, qyy = endpoint.transform_q_to_table(q)
	dzx, dzy = (1e6/qxx).real, (1e6/qyy).real
	print ("qxx = %.1f, dzx = %.0f, qyy=%.1f, dzy=%.0f, (in um), theta=%.1f deg" % 
			(q.rw(qxx)[1]*1e6, dzx, q.rw(qyy)[1]*1e6, dzy, theta ) )
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))
def doit_bc(theta1, clen, lambda0, drawit=0):
	
	print "\n\n***start blue line trace***\n"
	grating_offset=-0.075
	exit_height=0
	exit_z=-0.3
	eta1=0.0
	
	optics={}
	
	END='end'
	optics[END]=null_optic("end", (0.15,exit_height,0), 0)
	START='start'
	optics[START]=null_optic("start", (0,0,-0.85))

	
	tracebeam=basebeam.clone()
	system_center=Numeric.array((-0.1, 0, -0.85))
	
	basebeam=beam(system_center, qtens(lambda0, q=spitfire.q0), lambda0)
	tracebeam.free_drift(-0.2)
		
	COMP='comp'
	comp=optics[COMP]=blue_compressor(theta1, clen, lambda0, center=system_center, angle=rotation)
	TM2='turn2'
	optics[TM2]=reflector("output turn 2", angle=0, center=(0.15,exit_height,-0.6), width=.025)

	optics[COMP].set_exit_direction(optics[TM2])
	optics[TM2].set_direction(optics[COMP], optics[END])

	sys_order=(START, COMP, TM2, DEMAG1, DEMAG2, END)

	GRATE=comp.mark_label(blue_compressor.GRATE)
	IR1=comp.mark_label(blue_compressor.IR1)
	IR2=comp.mark_label(blue_compressor.IR2)
	
	optic_sys=composite_optic("system", optics, sys_order, center=optics[START].center)
	
	trace0=trace_path(optic_sys, tracebeam.shift_lambda(0))
	trace0.color=graphite.green
	trace1=trace_path(optic_sys, tracebeam.shift_lambda(-0.5e-9))
	trace1.color=graphite.blue
	trace2=trace_path(optic_sys, tracebeam.shift_lambda(+0.5e-9))
	trace2.color=graphite.red
			
	try: #if one of the traces failed, this may not work
		print "Theta1=%.3f eta=%.3f len=%.3f lambda=%.4f" % (theta1, eta1, clen, lambda0*1e6)
		d0=trace0[-1]['total_drift']
		d1=trace1[-1]['total_drift']
		d2=trace2[-1]['total_drift']
		print ("d(lambda0-0.5nm)=%.3f m, d(lambda0+0.5nm)=%.3f m, dt/dl=%.0f ps/nm, " % (d1, d2, (d2-d1)*1e12/clight)), 
		print "d2t/dl2 = %.2f ps/nm^2" % ((d2+d1-2.0*d0)*(1e12/clight)*4)
		spot1info=trace0[(GRATE,0)] 
		spot2info=trace0[(GRATE,1)] 
		ir1info=trace0[(IR1,0)]
		ir2info=trace0[(IR2,0)]
		spot_offset=spot2info['position']-spot1info['position']
		retro_offset=ir2info['position']-ir1info['position']
		print "Grating offset = %.3f, retro_offset=%.3f" % (vec_mag(spot_offset), vec_mag(retro_offset))
		print "measured vertex length = %.3f" % vec_mag(comp[GRATE].center-comp[IR1].center)
		print "dispersion offset on grating = %.3f m / nm" % vec_mag(trace2[(GRATE,1)]['position']-trace1[(GRATE,1)]['position'])
		print "final q = ", trace0[-1]['q']
	except:
		traceback.print_exc()
		pass
				
	if drawit:
		g=draw_everything({"sys":optic_sys}, trace0, (-.9, .1), (-.5, .5), three_d=0)
		#g=draw_everything(optics, trace0, (-2, 2), (-2, 2))
		draw_trace(g, trace1)
		draw_trace(g, trace2)
		graphite.genOutput(g,'QD',canvasname="Compressor layout", size=(600,500))