ap.initNSLS2V1() ap.initNSLS2V1SRTwiss() ap.hlalib._reset_trims() hclist = ['cyh1g2c10a', 'cyh2g2c10a', #'cxm1g4c10a', #'cxm1g4c10b', 'cyl1g6c10b', 'cyl2g6c10b'] hcor = ap.getElements(hclist) for h in hcor: print h beta = ap.getBeta(hclist) phi = ap.getPhase(hclist) for h in hcor: h.y = 0 time.sleep(6) x0 = ap.getOrbit(spos=True) #print type(beta), type(phi), type(x) #dphi = (phi - phi[0,:])*(2*np.pi) # the plane, x or y ic = 1 theta = [5e-6, -5e-6, 0, 0] b0, b1, b2, b3 = np.sqrt(beta[:,ic]) sp30 = np.sin((phi[3,ic] - phi[0,ic])*2*np.pi) sp31 = np.sin((phi[3,ic] - phi[1,ic])*2*np.pi)
def measBeta(self): p = ApMdiSubPlot(live=False) p.setAttribute(Qt.WA_DeleteOnClose) curves = [ p.aplot.curve1, p.aplot.addCurve(), # x and xref p.aplot.addCurve(), p.aplot.addCurve() # y and yref ] for curv in curves: curv.setStyle(Qwt.QwtPlotCurve.Lines) curves[0].setPen(QPen(Qt.red, 1.3, Qt.DashLine)) curves[0].setZ(curves[1].z() + 2) curves[1].setPen(QPen(Qt.red, 1.5)) curves[2].setPen(QPen(Qt.blue, 1.3, Qt.DashLine)) curves[2].setZ(curves[3].z() + 2) curves[2].setSymbol( Qwt.QwtSymbol(Qwt.QwtSymbol.Triangle, QBrush(Qt.blue), QPen(Qt.black, 1), QSize(8, 8))) curves[3].setPen(QPen(Qt.blue, 1.5)) #p.aplot.curve1.setStyle(Qwt.QwtPlotCurve.) #p.setWindowTitle("[%s.%s] %s %s" % (mach, lat, title, fld)) self.mdiarea.addSubWindow(p) #print "Show" p.show() #plots.append(p) qs = ap.getGroupMembers(['C20', 'QUAD']) + \ ap.getGroupMembers(['C21', 'QUAD']) xl = min([q.sb for q in qs]) xr = max([q.se for q in qs]) s, btx, bty = [], [], [] try: betaref = ap.getBeta([q.name for q in qs], spos=True) curves[1].setData(betaref[:, -1], betaref[:, 0], None) curves[3].setData(betaref[:, -1], betaref[:, 1], None) fullmagprof = ap.machines.getLattice().getBeamlineProfile() magprof = [v for v in fullmagprof if max(v[0]) > xl \ and min(v[0]) < xr] p.aplot.setMagnetProfile(magprof) p.wid.autoScaleXY() p.aplot.replot() for q in qs[:3]: tbeta, tk1, tnu = ap.measBeta(q, full=True) #print tk1, tnu, tbeta QApplication.processEvents() s.append(tbeta[0, -1]) btx.append(tbeta[0, 0]) bty.append(tbeta[0, 1]) curves[0].setData(s, btx, None) curves[2].setData(s, bty, None) p.wid.autoScaleXY() p.aplot.replot() _logger.info("beta measured for {0} " \ "(s={1}, btx={2}, bty={3})".format( q.name, s[-1], btx[-1], bty[-1])) except: _logger.error("error at measBeta") raise _logger.info("finished beta measurement.")
def measBeta(self): p = ApMdiSubPlot(live=False) p.setAttribute(Qt.WA_DeleteOnClose) curves = [p.aplot.curve1, p.aplot.addCurve(), # x and xref p.aplot.addCurve(), p.aplot.addCurve() # y and yref ] for curv in curves: curv.setStyle(Qwt.QwtPlotCurve.Lines) curves[0].setPen(QPen(Qt.red, 1.3, Qt.DashLine)) curves[0].setZ(curves[1].z() + 2) curves[1].setPen(QPen(Qt.red, 1.5)) curves[2].setPen(QPen(Qt.blue, 1.3, Qt.DashLine)) curves[2].setZ(curves[3].z() + 2) curves[2].setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Triangle, QBrush(Qt.blue), QPen(Qt.black, 1), QSize(8, 8))) curves[3].setPen(QPen(Qt.blue, 1.5)) #p.aplot.curve1.setStyle(Qwt.QwtPlotCurve.) #p.setWindowTitle("[%s.%s] %s %s" % (mach, lat, title, fld)) self.mdiarea.addSubWindow(p) #print "Show" p.show() #plots.append(p) qs = ap.getGroupMembers(['C20', 'QUAD']) + \ ap.getGroupMembers(['C21', 'QUAD']) xl = min([q.sb for q in qs]) xr = max([q.se for q in qs]) s, btx, bty = [], [], [] try: betaref = ap.getBeta([q.name for q in qs], spos=True) curves[1].setData(betaref[:,-1], betaref[:,0], None) curves[3].setData(betaref[:,-1], betaref[:,1], None) fullmagprof = ap.machines.getLattice().getBeamlineProfile() magprof = [v for v in fullmagprof if max(v[0]) > xl \ and min(v[0]) < xr] p.aplot.setMagnetProfile(magprof) p.wid.autoScaleXY() p.aplot.replot() for q in qs[:3]: tbeta, tk1, tnu = ap.measBeta(q, full=True) #print tk1, tnu, tbeta QApplication.processEvents() s.append(tbeta[0,-1]) btx.append(tbeta[0,0]) bty.append(tbeta[0,1]) curves[0].setData(s, btx, None) curves[2].setData(s, bty, None) p.wid.autoScaleXY() p.aplot.replot() _logger.info("beta measured for {0} " \ "(s={1}, btx={2}, bty={3})".format( q.name, s[-1], btx[-1], bty[-1])) except: _logger.error("error at measBeta") raise _logger.info("finished beta measurement.")
ap.hlalib._reset_trims() hclist = [ 'cyh1g2c10a', 'cyh2g2c10a', #'cxm1g4c10a', #'cxm1g4c10b', 'cyl1g6c10b', 'cyl2g6c10b' ] hcor = ap.getElements(hclist) for h in hcor: print h beta = ap.getBeta(hclist) phi = ap.getPhase(hclist) for h in hcor: h.y = 0 time.sleep(6) x0 = ap.getOrbit(spos=True) #print type(beta), type(phi), type(x) #dphi = (phi - phi[0,:])*(2*np.pi) # the plane, x or y ic = 1 theta = [5e-6, -5e-6, 0, 0] b0, b1, b2, b3 = np.sqrt(beta[:, ic]) sp30 = np.sin((phi[3, ic] - phi[0, ic]) * 2 * np.pi)