def test_meas_beta_l2(self): qs = ap.getGroupMembers(['C30', 'QUAD']) beta, k1, nu = ap.measBeta(qs, full=True) self.assertEqual(np.shape(beta), (len(qs), 3)) #self.assertEqual(np.shape(k1)[1], 3) self.assertEqual(np.shape(k1)[0], len(qs)) self.assertEqual(np.shape(nu)[0], len(qs)) self.assertEqual(np.shape(k1)[1], np.shape(nu)[1]) #self.assertEqual(np.shape(k1)[0], len(qs)) if PLOTTING: for i,q in enumerate(qs): plt.clf() plt.subplot(211) plt.plot(k1[i,:], nu[i,:,0], 'r-v') plt.subplot(212) plt.plot(k1[i,:], nu[i,:,1], 'r-v') plt.savefig(figname("meas_beta_nu_%s.png" % q.name)) plt.clf() plt.plot(beta[:,-1], beta[:,0], 'r-v') plt.plot(beta[:,-1], beta[:,1], 'b-o') plt.savefig(figname("meas_beta_beta.png"))
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.")