Exemplo n.º 1
0
    def test_correct_orbit(self):
        ap.hlalib._reset_trims()

        # a list of horizontal corrector
        hcor = ap.getElements("HCOR")
        hcor_v0 = [e.x for e in hcor]
        # a list of vertical corrector
        vcor = ap.getElements("VCOR")
        vcor_v0 = [e.y for e in vcor]

        bpm = ap.getElements("BPM")
        bpm_v0 = np.array([(e.x, e.y) for e in bpm], "d")

        norm0 = (np.linalg.norm(bpm_v0[:, 0]), np.linalg.norm(bpm_v0[:, 1]))

        ih = np.random.randint(0, len(hcor), 4)
        for i in ih:
            hcor[i].x = np.random.rand() * 1e-5

        iv = np.random.randint(0, len(vcor), 4)
        for i in iv:
            vcor[i].y = np.random.rand() * 1e-5

        # raw_input("Press Enter to correct orbit...")
        time.sleep(4)

        cor = []
        # cor.extend([e.name for e in hcor])
        # cor.extend([e.name for e in vcor])
        cor.extend([hcor[i].name for i in ih])
        cor.extend([vcor[i].name for i in iv])

        bpm_v1 = np.array([(e.x, e.y) for e in bpm], "d")
        norm1 = (np.linalg.norm(bpm_v1[:, 0]), np.linalg.norm(bpm_v1[:, 1]))

        self.assertGreater(norm1[0], norm0[0])

        ap.correctOrbit([e.name for e in bpm], cor)
        ap.correctOrbit(bpm, cor)

        # raw_input("Press Enter to recover orbit...")
        bpm_v2 = np.array([(e.x, e.y) for e in bpm], "d")
        # print "Euclidian norm:",
        norm2 = (np.linalg.norm(bpm_v2[:, 0]), np.linalg.norm(bpm_v2[:, 1]))
        self.assertLess(norm2[0], norm1[0])
        self.assertLess(norm2[1], norm1[1])

        for i in ih:
            hcor[i].x = hcor_v0[i]

        for i in iv:
            vcor[i].y = vcor_v0[i]

        time.sleep(4)
        # raw_input("Press Enter ...")
        bpm_v3 = np.array([(e.x, e.y) for e in bpm], "d")
        # print "Euclidian norm:",
        norm3 = (np.linalg.norm(bpm_v3[:, 0]), np.linalg.norm(bpm_v3[:, 1]))
        self.assertLess(norm3[0], norm1[0])
        self.assertLess(norm3[0], norm1[0])
Exemplo n.º 2
0
    def test_correct_orbit(self):
        ap.hlalib._reset_trims()

        # a list of horizontal corrector
        hcor = ap.getElements('HCOR')
        hcor_v0 = [e.x for e in hcor]
        # a list of vertical corrector
        vcor = ap.getElements('VCOR')
        vcor_v0 = [e.y for e in vcor]

        bpm = ap.getElements('BPM')
        bpm_v0 = np.array([(e.x, e.y) for e in bpm], 'd')

        norm0 = (np.linalg.norm(bpm_v0[:,0]), np.linalg.norm(bpm_v0[:,1]))

        ih = np.random.randint(0, len(hcor), 4)
        for i in ih:
            hcor[i].x = np.random.rand() * 1e-5

        iv = np.random.randint(0, len(vcor), 4)
        for i in iv:
            vcor[i].y = np.random.rand() * 1e-5

        #raw_input("Press Enter to correct orbit...")
        time.sleep(6)

        cor = []
        #cor.extend([e.name for e in hcor])
        #cor.extend([e.name for e in vcor])
        cor.extend([hcor[i].name for i in ih])
        cor.extend([vcor[i].name for i in iv])

        bpm_v1 = np.array([(e.x, e.y) for e in bpm], 'd')
        norm1 = (np.linalg.norm(bpm_v1[:,0]), np.linalg.norm(bpm_v1[:,1]))

        self.assertGreater(norm1[0], norm0[0])

        ap.correctOrbit([e.name for e in bpm], cor)
        ap.correctOrbit(bpm, cor)

        #raw_input("Press Enter to recover orbit...")
        bpm_v2 = np.array([(e.x, e.y) for e in bpm], 'd')
        #print "Euclidian norm:", 
        norm2 = (np.linalg.norm(bpm_v2[:,0]), np.linalg.norm(bpm_v2[:,1]))
        self.assertLess(norm2[0], norm1[0])
        self.assertLess(norm2[1], norm1[1])

        for i in ih:
            hcor[i].x = hcor_v0[i]

        for i in iv:
            vcor[i].y = vcor_v0[i]

        time.sleep(4)
        #raw_input("Press Enter ...")
        bpm_v3 = np.array([(e.x, e.y) for e in bpm], 'd')
        #print "Euclidian norm:", 
        norm3 = (np.linalg.norm(bpm_v3[:,0]), np.linalg.norm(bpm_v3[:,1]))
        self.assertLess(norm3[0], norm1[0])
        self.assertLess(norm3[0], norm1[0])
Exemplo n.º 3
0
    def test_golden(self):
        f = open("golden.txt", "w")
        cors = ap.getElements('COR')
        for c in cors:
            c.x = 0.0
            c.y = 0.0
        time.sleep(2)
        obt0a = ap.getOrbit(spos=True)
        for scale in [1.0, 0.9, 0.8, 0.7, 0.6]:
            ap.correctOrbit(scale=scale, wait=3)
        time.sleep(6)
        obt0 = ap.getOrbit(spos=True)
        d0 = np.zeros((len(cors), 2), 'd')
        for i,c in enumerate(cors):
            d0[i,0] = c.x
            d0[i,1] = c.y
            c.setGolden('x', d0[i,0], unitsys=None)
            c.setGolden('y', d0[i,1], unitsys=None)
            f.write("{0} x {1}\n".format(c.name, d0[i,0]))
            f.write("{0} y {1}\n".format(c.name, d0[i,1]))
        f.close()
        # now reset the orbit
        time.sleep(5)
        for c in cors:
            c.x = 0.0
            c.y = 0.0
        for i,c in enumerate(cors):
            c.reset('x', data='golden')
            c.reset('y', data='golden')
        time.sleep(6)
        d1 = np.zeros((len(cors), 2), 'd')
        for i,c in enumerate(cors):
            d1[i,0] = c.x
            d1[i,1] = c.y
        obt1 = ap.getOrbit(spos=True)

        plt.subplot(311)
        plt.plot(obt0a[:,-1], obt0a[:,0], 'g-')
        plt.plot(obt0[:,-1], obt0[:,0], 'r-')
        plt.plot(obt1[:,-1], obt1[:,0], 'b--')
        plt.subplot(312)
        plt.plot(d1[:,0] - d0[:,0], 'r-')
        plt.plot(d1[:,1] - d0[:,1], 'b--')
        plt.subplot(313)
        plt.plot(obt0[:,-1], obt1[:,0] - obt0[:,0], 'r-x')
        plt.plot(obt1[:,-1], obt1[:,1] - obt0[:,1], 'b-o')
        plt.savefig(figname("test_golden.png"))
Exemplo n.º 4
0
    def test_corr_orbit_l2(self):
        self._random_kick(3)
        obt = ap.getOrbit()
        bpm = ap.getElements('BPM')[60:101]
        trim = ap.getGroupMembers(['*', '[HV]COR'], op='intersection')
        v0 = ap.getOrbit('p*', spos=True)
        ap.correctOrbit(bpm, trim, repeat=5, scale=0.9)
        time.sleep(4)
        v1 = ap.getOrbit('p*', spos=True)

        import matplotlib.pylab as plt
        plt.clf()
        ax = plt.subplot(211) 
        fig = plt.plot(v0[:,-1], v0[:,0], 'r-x', label='X(before)') 
        fig = plt.plot(v1[:,-1], v1[:,0], 'g-o', label='X(after)')
        plt.legend()
        ax = plt.subplot(212)
        fig = plt.plot(v0[:,-1], v0[:,1], 'r-x', label='Y(before)')
        fig = plt.plot(v1[:,-1], v1[:,1], 'g-o', label='Y(after)')
        plt.legend()
        plt.savefig(figname("test_nsls2_orbit_correct.png"))
Exemplo n.º 5
0
ap.initNSLS2V1()
bpms = ap.getElements('BPM')
#trims = ap.getGroupMembers(['*', '[HV]COR'], op='intersection')
trims = ap.getElements('HCOR')[:30] + ap.getElements('VCOR')[-30:]
print "Bpms x Trims: (%d, %d)" % (len(bpms), len(trims))

v0 = ap.getOrbit(spos=True)
k0 = []
for tr in trims:
    #print tr
    if u'x' in tr.fields(): k0.append([tr.sb, tr.x])
    if u'y' in tr.fields(): k0.append([tr.sb, tr.y])

n1, n2 = 10, 20
ap.correctOrbit([e.name for e in bpms[n1:n2]], [e.name for e in trims],
                scale=0.7,
                repeat=3)
#ap.correctOrbit(scale=0.7, repeat=9)
#Euclidian norm: ...
time.sleep(4)
v1 = ap.getOrbit(spos=True)
time.sleep(4)
v2 = ap.getOrbit(spos=True)
k1 = []
for tr in trims:
    #print tr
    if u'x' in tr.fields(): k1.append([tr.sb, tr.x])
    if u'y' in tr.fields(): k1.append([tr.sb, tr.y])

# plotting
plt.clf()
Exemplo n.º 6
0
print ap.__path__ 
ap.initNSLS2V1()
bpms = ap.getElements('BPM')
#trims = ap.getGroupMembers(['*', '[HV]COR'], op='intersection')
trims = ap.getElements('HCOR')[:30] + ap.getElements('VCOR')[-30:]
print "Bpms x Trims: (%d, %d)" % (len(bpms), len(trims) )

v0 = ap.getOrbit(spos=True)
k0 = []
for tr in trims:
    #print tr
    if u'x' in tr.fields(): k0.append([tr.sb, tr.x])
    if u'y' in tr.fields(): k0.append([tr.sb, tr.y])

n1, n2 = 10, 20
ap.correctOrbit([e.name for e in bpms[n1:n2]], [e.name for e in trims],
                scale=0.7, repeat=3) 
#ap.correctOrbit(scale=0.7, repeat=9)
#Euclidian norm: ...
time.sleep(4)
v1 = ap.getOrbit(spos=True)
time.sleep(4)
v2 = ap.getOrbit(spos=True)
k1 = []
for tr in trims:
    #print tr
    if u'x' in tr.fields(): k1.append([tr.sb, tr.x])
    if u'y' in tr.fields(): k1.append([tr.sb, tr.y])


# plotting
plt.clf()