示例#1
0
    def __init__(self, cors, nmax, field, parent = None):
        super(BumpNCor, self).__init__(parent)
        self.corview = CorrectorViewer(cors, field, nmax=nmax)

        hbox3 = QtGui.QHBoxLayout()
        self.rdbxbump = QtGui.QRadioButton("X Bump")
        self.rdbybump = QtGui.QRadioButton("Y BUmp")
        self.rdbxbump.setChecked(True)
        hbox3.addWidget(self.rdbxbump)
        hbox3.addWidget(self.rdbybump)
        self.grpPlane = QtGui.QGroupBox("Plane")
        self.grpPlane.setLayout(hbox3)

        self.gboxBtn = QtGui.QGridLayout()
        btnClear  = QtGui.QPushButton("Clear")
        btnReset  = QtGui.QPushButton("Reset")
        btnZoomin = QtGui.QPushButton("Zoom In")
        btnApply  = QtGui.QPushButton("Apply")
        self.gboxBtn.addWidget(btnClear, 0, 1)
        self.gboxBtn.addWidget(btnReset, 1, 1)
        self.gboxBtn.addWidget(btnZoomin, 2, 1)
        self.gboxBtn.addWidget(btnApply, 3, 1)
        self.gboxBtn.setColumnStretch(1, 0)
        self.gboxBtn.setColumnStretch(0, 1)

        self.connect(self.rdbxbump, SIGNAL("clicked()"),
                     partial(self.changeField, "x"))
        self.connect(self.rdbybump, SIGNAL("clicked()"),
                     partial(self.changeField, "y"))
        self.connect(btnClear, SIGNAL("clicked()"), self.clear)
        self.connect(btnReset, SIGNAL("clicked()"),
                     self.corview.resetCorrectors)
        self.connect(btnApply, SIGNAL("clicked()"),
                     self.corview.applyKick)
        self.connect(btnZoomin, SIGNAL("clicked()"),
                     self._zoom_in)
        self._x0 = fget(cors, "x", handle="setpoint", unitsys=None)
        self._y0 = fget(cors, "y", handle="setpoint", unitsys=None)
示例#2
0
    def __init__(self, cors, nmax, field, parent = None):
        super(BumpNCor, self).__init__(parent)
        self.corview = CorrectorViewer(cors, field, nmax=nmax)

        hbox3 = QtGui.QHBoxLayout()
        self.rdbxbump = QtGui.QRadioButton("X Bump")
        self.rdbybump = QtGui.QRadioButton("Y BUmp")
        self.rdbxbump.setChecked(True)
        hbox3.addWidget(self.rdbxbump)
        hbox3.addWidget(self.rdbybump)
        self.grpPlane = QtGui.QGroupBox("Plane")
        self.grpPlane.setLayout(hbox3)

        self.gboxBtn = QtGui.QGridLayout()
        btnClear  = QtGui.QPushButton("Clear")
        btnReset  = QtGui.QPushButton("Reset")
        btnZoomin = QtGui.QPushButton("Zoom In")
        btnApply  = QtGui.QPushButton("Apply")
        self.gboxBtn.addWidget(btnClear, 0, 1)
        self.gboxBtn.addWidget(btnReset, 1, 1)
        self.gboxBtn.addWidget(btnZoomin, 2, 1)
        self.gboxBtn.addWidget(btnApply, 3, 1)
        self.gboxBtn.setColumnStretch(1, 0)
        self.gboxBtn.setColumnStretch(0, 1)

        self.connect(self.rdbxbump, SIGNAL("clicked()"),
                     partial(self.changeField, "x"))
        self.connect(self.rdbybump, SIGNAL("clicked()"),
                     partial(self.changeField, "y"))
        self.connect(btnClear, SIGNAL("clicked()"), self.clear)
        self.connect(btnReset, SIGNAL("clicked()"),
                     self.corview.resetCorrectors)
        self.connect(btnApply, SIGNAL("clicked()"),
                     self.corview.applyKick)
        self.connect(btnZoomin, SIGNAL("clicked()"),
                     self._zoom_in)
        self._x0 = fget(cors, "x", handle="setpoint", unitsys=None)
        self._y0 = fget(cors, "y", handle="setpoint", unitsys=None)
示例#3
0
    def _aplocalbumpcreation(self, plane, ename, source, bumpsettings):
        """
        plane: 0: X plane, 1: Y plane;
        ename: selected insertion device element name;
        source: s position at source position
        bumpsettings: local bump settings: [shift, angle]

        return: delta correctors [H, V]
        """

        if plane == 0:
            fld = 'x'
            #xc = ((self.idobj.se - self.idobj.sb) / 2.0 - self.sourceposition) * \
            #    bumpsettings[1] + bumpsettings[0]
            #thetac = bumpsettings[1]
        elif plane == 1:
            fld = 'y'
        xc = ((self.idobj.se - self.idobj.sb) / 2.0 - self.sourceposition) * \
            bumpsettings[1] + bumpsettings[0]
        thetac = bumpsettings[1]

        if self.previoush is None:
            self.previoush = [0.0] * self.corscount
        for i, cor in enumerate(self.cors):
            self.previoush[i] = cor.get(fld, unitsys=None, handle="setpoint")

        niter = 10
        for i in range(niter):
            cothread.Yield(0.10)
            norm0, norm1, norm2, corvals = \
                ap.setIdBump(ename, xc, thetac, plane=fld)
            angle, position, _, _ = self._getliveangleandpos(self.bpms[self.bpmcounts/2-1], self.bpms[self.bpmcounts/2])
            # if the achieved angle and offset are very close to desired values, break
            # can not distinguish 10urad and 5um.
            if np.abs(angle - thetac) < 1e-2 and np.abs(xc - position) < 5e-3:
                break
            if corvals is None:
                msg = "{0}/{1} Minimum chi^2 achieved: {2} (predicted: {3})".format(i,niter,norm0, norm1)
            else:
                msg = "{0}/{1} chi^2 decreased {2} from {3} (predicted: {4})".format(
                    i, niter, norm2-norm0, norm0, norm1)
            ca.caput(self.pvmapping.__status__, msg[:255], datatype=DBR_CHAR_STR)

        delta = ap.fget(self.cors, fld, unitsys=None, handle="setpoint") - np.array(self.previoush, 'd')
        return delta
示例#4
0
    def __init__(self, cors, field, parent=None, nmax=4):
        super(CorrectorViewer, self).__init__(parent)
        self._nmax  = nmax
        self._field = field
        self._cors  = cors
        self._corlst1 = QtGui.QTreeWidget()
        self._header = dict([("Element", 0), ("Family", 1), ("s [m]", 2),
                             ("Alpha X", 3), ("Alpha Y", 4), ("Beta X", 5),
                             ("Beta Y", 6), ("Phi X", 7), ("Phi Y", 8),
                             ("Eta X", 9)])
        self._twiss = np.zeros((len(self._cors), 8), 'd')
        self._tunes = getTunes(source="database")
        self._corlst1.setColumnCount(len(self._header))
        self._corlst1.setHeaderLabels(
            sorted(self._header, key=self._header.get))
        self._corlst1.header().setStretchLastSection(False)
        prevcell = None
        for i,c in enumerate(self._cors):
            if c.cell and (prevcell is None or c.cell != prevcell.text(0)):
                # a new parent
                prevcell = QtGui.QTreeWidgetItem()
                prevcell.setText(0, c.cell)
                self._corlst1.addTopLevelItem(prevcell)
            it = QtGui.QTreeWidgetItem()
            it.setData(0, Qt.UserRole, i)
            it.setText(self._header["Element"], c.name)
            it.setText(self._header["Family"], c.family)
            it.setText(self._header["s [m]"], "%.3f" % c.sb)
            try:
                tw = getTwiss(c.name,
                              ["s", "alphax", "alphay", "betax", "betay",
                               "phix", "phiy", "etax"])
                self._twiss[i,:] = tw[0,:]
                it.setText(self._header["Alpha X"], "%.4f" % self._twiss[i,1])
                it.setText(self._header["Alpha Y"], "%.4f" % self._twiss[i,2])
                it.setText(self._header["Beta X"],  "%.4f" % self._twiss[i,3])
                it.setText(self._header["Beta Y"],  "%.4f" % self._twiss[i,4])
                it.setText(self._header["Phi X"],   "%.4f" % self._twiss[i,5])
                it.setText(self._header["Phi Y"],   "%.4f" % self._twiss[i,6])
                it.setText(self._header["Eta X"],   "%.4f" % self._twiss[i,7])
            except:
                it.setDisabled(True)
                pass

            if c.cell:
                prevcell.addChild(it)
            else:
                self._corlst1.addTopLevelItem(it)
                prevcell = it
            for j in range(2, len(self._header)):
                it.setTextAlignment(j, Qt.AlignRight)
        self._corlst1.expandAll()
        for i in range(len(self._header)):
            self._corlst1.resizeColumnToContents(i)
        #self._corlst1.setColumnWidth(0, 150)

        #self.elemlst.setSelectionMode(QAbstractItemView.MultiSelection)
        columns = ['Corrector', 's', 'Alpha', 'Beta',
                   'Phi', "dPhi", "Initial Bump", "Cur. Sp", "dBump",
                   "Final Rb"]
        self.table4 = QTableWidget(0, len(columns))
        #self.table4.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        hdview = QHeaderView(Qt.Horizontal)
        self.table4.setHorizontalHeaderLabels(columns)
        #for i in range(4):
        #    for j in range(len(columns)):
        #        it = QTableWidgetItem()
        #        if j > 0: it.setTextAlignment(
        #            Qt.AlignRight | Qt.AlignVCenter)
        #        if columns[j] != "dKick":
        #            it.setFlags(it.flags() & (~Qt.ItemIsEditable))
        #        self.table4.setItem(i, j, it)
        #self.table4.resizeColumnsToContents()
        #self.table4.horizontalHeader().setStretchLastSection(True)
        #hrow = self.table4.rowHeight(0)
        #htbl = (hrow * 4) + self.table4.horizontalHeader().height() +\
        #    2*self.table4.frameWidth()
        #self.table4.setMinimumHeight(htbl + 10)
        #self.table4.setMaximumHeight(htbl + 15)
        #self.table4.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        #print "Size:", htbl + 10
        self.table4.resize(self.table4.width(), 150)

        splitter = QtGui.QSplitter(Qt.Vertical)
        splitter.addWidget(self._corlst1)
        splitter.addWidget(self.table4)
        vbox1 = QtGui.QVBoxLayout()
        vbox1.addWidget(splitter)
        self.setLayout(vbox1)

        self.connect(self._corlst1, SIGNAL("doubleClicked(QModelIndex)"),
                     self.addCorrector)
        #self.connect(self.src, SIGNAL("returnPressed()"),
        #             self._calc_source)
        #self.connect(self.table4, SIGNAL("cellChanged(int, int)"),
        #             self.updateTable)

        #self.connect(self.table4, SIGNAL("doubleClicked(QModelIndex)"),
        #             self.delCorrector)
        self._x0 = fget(self._cors, "x", handle="setpoint", unitsys=None)
        self._y0 = fget(self._cors, "y", handle="setpoint", unitsys=None)
示例#5
0
    def __init__(self, cors, field, parent=None, nmax=4):
        super(CorrectorViewer, self).__init__(parent)
        self._nmax  = nmax
        self._field = field
        self._cors  = cors
        self._corlst1 = QtGui.QTreeWidget()
        self._header = dict([("Element", 0), ("Family", 1), ("s [m]", 2),
                             ("Alpha X", 3), ("Alpha Y", 4), ("Beta X", 5),
                             ("Beta Y", 6), ("Phi X", 7), ("Phi Y", 8),
                             ("Eta X", 9)])
        self._twiss = np.zeros((len(self._cors), 8), 'd')
        self._tunes = getTunes(source="database")
        self._corlst1.setColumnCount(len(self._header))
        self._corlst1.setHeaderLabels(
            sorted(self._header, key=self._header.get))
        self._corlst1.header().setStretchLastSection(False)
        prevcell = None
        for i,c in enumerate(self._cors):
            if c.cell and (prevcell is None or c.cell != prevcell.text(0)):
                # a new parent
                prevcell = QtGui.QTreeWidgetItem()
                prevcell.setText(0, c.cell)
                self._corlst1.addTopLevelItem(prevcell)
            it = QtGui.QTreeWidgetItem()
            it.setData(0, Qt.UserRole, i)
            it.setText(self._header["Element"], c.name)
            it.setText(self._header["Family"], c.family)
            it.setText(self._header["s [m]"], "%.3f" % c.sb)
            try:
                tw = getTwiss(c.name, 
                              ["s", "alphax", "alphay", "betax", "betay",
                               "phix", "phiy", "etax"])
                self._twiss[i,:] = tw[0,:]
                it.setText(self._header["Alpha X"], "%.4f" % self._twiss[i,1])
                it.setText(self._header["Alpha Y"], "%.4f" % self._twiss[i,2])
                it.setText(self._header["Beta X"],  "%.4f" % self._twiss[i,3])
                it.setText(self._header["Beta Y"],  "%.4f" % self._twiss[i,4])
                it.setText(self._header["Phi X"],   "%.4f" % self._twiss[i,5])
                it.setText(self._header["Phi Y"],   "%.4f" % self._twiss[i,6])
                it.setText(self._header["Eta X"],   "%.4f" % self._twiss[i,7])
            except:
                it.setDisabled(True)
                pass

            if c.cell:
                prevcell.addChild(it)
            else:
                self._corlst1.addTopLevelItem(it)
                prevcell = it
            for j in range(2, len(self._header)):
                it.setTextAlignment(j, Qt.AlignRight)
        self._corlst1.expandAll()
        for i in range(len(self._header)):
            self._corlst1.resizeColumnToContents(i)
        #self._corlst1.setColumnWidth(0, 150)

        #self.elemlst.setSelectionMode(QAbstractItemView.MultiSelection)
        columns = ['Corrector', 's', 'Alpha', 'Beta',
                   'Phi', "dPhi", "Initial Bump", "Cur. Sp", "dBump",
                   "Final Rb"]
        self.table4 = QTableWidget(0, len(columns))
        #self.table4.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        hdview = QHeaderView(Qt.Horizontal)
        self.table4.setHorizontalHeaderLabels(columns)
        #for i in range(4):
        #    for j in range(len(columns)):
        #        it = QTableWidgetItem()
        #        if j > 0: it.setTextAlignment(
        #            Qt.AlignRight | Qt.AlignVCenter)
        #        if columns[j] != "dKick":
        #            it.setFlags(it.flags() & (~Qt.ItemIsEditable))
        #        self.table4.setItem(i, j, it)
        #self.table4.resizeColumnsToContents()
        #self.table4.horizontalHeader().setStretchLastSection(True)
        #hrow = self.table4.rowHeight(0)
        #htbl = (hrow * 4) + self.table4.horizontalHeader().height() +\
        #    2*self.table4.frameWidth()
        #self.table4.setMinimumHeight(htbl + 10)
        #self.table4.setMaximumHeight(htbl + 15)
        #self.table4.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        #print "Size:", htbl + 10
        self.table4.resize(self.table4.width(), 150)

        splitter = QtGui.QSplitter(Qt.Vertical)
        splitter.addWidget(self._corlst1)
        splitter.addWidget(self.table4)
        vbox1 = QtGui.QVBoxLayout()
        vbox1.addWidget(splitter)
        self.setLayout(vbox1)

        self.connect(self._corlst1, SIGNAL("doubleClicked(QModelIndex)"),
                     self.addCorrector)
        #self.connect(self.src, SIGNAL("returnPressed()"),
        #             self._calc_source)
        #self.connect(self.table4, SIGNAL("cellChanged(int, int)"),
        #             self.updateTable)

        #self.connect(self.table4, SIGNAL("doubleClicked(QModelIndex)"),
        #             self.delCorrector)
        self._x0 = fget(self._cors, "x", handle="setpoint", unitsys=None)
        self._y0 = fget(self._cors, "y", handle="setpoint", unitsys=None)