예제 #1
0
파일: base.py 프로젝트: lnls-sirius/hla
    def _create_formlayout_groupbox(self, title, props):
        grpbx = CustomGroupBox(title, self)
        fbl = QFormLayout(grpbx)
        grpbx.layoutf = fbl
        fbl.setLabelAlignment(Qt.AlignVCenter)
        for prop in props:
            if len(prop) == 2:
                pv1, txt = prop
                isdata = True
            elif len(prop) == 3:
                pv1, txt, isdata = prop
            hbl = QHBoxLayout()
            not_enum = pv1.endswith('-SP')
            pv2 = pv1.replace('-SP', '-RB').replace('-Sel', '-Sts')
            if pv2 != pv1:
                if not_enum:
                    chan1 = self.get_pvname(pv1, is_data=isdata)
                    wid = SiriusSpinbox(self, init_channel=chan1)
                    wid.setStyleSheet("min-width:5em;")
                    wid.showStepExponent = False
                    wid.limitsFromChannel = False
                    pvn = self.data_prefix + pv1
                    wid.setMinimum(self.bpmdb[pvn].get('low', -1e10))
                    wid.setMaximum(self.bpmdb[pvn].get('high', 1e10))
                else:
                    wid = PyDMEnumComboBox(
                        self,
                        init_channel=self.get_pvname(pv1, is_data=isdata))
                    wid.setStyleSheet("min-width:5em;")
                wid.setObjectName(pv1.replace('-', ''))
                hbl.addWidget(wid)

            lab = SiriusLabel(
                self, init_channel=self.get_pvname(pv2, is_data=isdata))
            lab.setObjectName(pv2.replace('-', ''))
            lab.showUnits = True
            lab.setStyleSheet("min-width:5em;")
            hbl.addWidget(lab)
            lab = QLabel(txt)
            lab.setObjectName(pv1.split('-')[0])
            lab.setStyleSheet("min-width:8em;")
            fbl.addRow(lab, hbl)
        return grpbx
예제 #2
0
 def create_pair(self, parent, pvname, device=None, is_vert=False):
     """."""
     device = device or self.device
     basename = _PVName(device).substitute(prefix=self.prefix,
                                           propty_name=pvname)
     wid = QWidget(parent)
     if is_vert:
         lay = QVBoxLayout(wid)
     else:
         lay = QHBoxLayout(wid)
     lay.setContentsMargins(0, 0, 0, 0)
     pdm_spbx = SiriusSpinbox(wid, basename.substitute(propty_suffix='SP'))
     pdm_spbx.showStepExponent = False
     pdm_lbl = PyDMLabel(wid, basename.substitute(propty_suffix='RB'))
     pdm_lbl.setAlignment(Qt.AlignCenter)
     lay.addWidget(pdm_spbx)
     lay.addWidget(pdm_lbl)
     wid.sp_wid = pdm_spbx
     wid.rb_wid = pdm_lbl
     return wid
예제 #3
0
    def _setupUi(self):
        gl = QGridLayout(self)
        fig = mplt.figure()
        wid = MatplotlibWidget(fig, parent=self)
        wid.setObjectName('fig_result')
        wid.setStyleSheet('#fig_result{min-width: 25em;}')
        self.fig_res = wid

        gs = mgs.GridSpec(3, 1)
        gs.update(left=0.18, right=0.98, top=0.97, bottom=0.08, hspace=0.25)

        axes = wid.figure.add_subplot(gs[0, 0])
        axes.set_xlabel('Index')
        axes.set_ylabel('Normalized Emit. [mm.mrad]')
        axes.grid(True)
        axes.set_aspect('auto')
        self.line_nemitx_tm = axes.plot(
            self.nemitx_tm, '-bo', lw=1, label='Hor. Trans. Mat.')[0]
        self.line_nemitx_parf = axes.plot(
            self.nemitx_parf, '--bd', lw=1, label='Hor. Parab. Fit')[0]
        self.line_nemity_tm = axes.plot(
            self.nemity_tm, '--ro', lw=1, label='Vert. Trans. Mat.')[0]
        self.line_nemity_parf = axes.plot(
            self.nemity_parf, '--rd', lw=1, label='Vert. Parab. Fit')[0]
        axes.legend(loc='best')

        axes = wid.figure.add_subplot(gs[1, 0])
        axes.set_xlabel('Index')
        axes.set_ylabel(r'$\beta$ [m]')
        self.line_betax_tm = axes.plot(
            self.betax_tm, '-bo', lw=1, label='Hor. Trans. Mat.')[0]
        self.line_betax_parf = axes.plot(
            self.betax_parf, '--bd', lw=1, label='Hor. Parab. Fit')[0]
        self.line_betay_tm = axes.plot(
            self.betay_tm, '--ro', lw=1, label='Vert. Trans. Mat.')[0]
        self.line_betay_parf = axes.plot(
            self.betay_parf, '--rd', lw=1, label='Vert. Parab. Fit')[0]

        axes = wid.figure.add_subplot(gs[2, 0])
        axes.set_xlabel('Index')
        axes.set_ylabel(r'$\alpha$')
        self.line_alphax_tm = axes.plot(
            self.alphax_tm, '-bo', lw=1, label='Hor. Trans. Mat.')[0]
        self.line_alphax_parf = axes.plot(
            self.alphax_parf, '--bd', lw=1, label='Hor. Parab. Fit')[0]
        self.line_alphay_tm = axes.plot(
            self.alphay_tm, '--ro', lw=1, label='Vert. Trans. Mat.')[0]
        self.line_alphay_parf = axes.plot(
            self.alphay_parf, '--rd', lw=1, label='Vert. Parab. Fit')[0]

        measlay = QVBoxLayout()

        gb = QGroupBox('QF3 Current [A]', self)
        measlay.addWidget(gb)
        gb.setLayout(QHBoxLayout())
        spnbox = SiriusSpinbox(
            gb, _PVName('LI-01:PS-QF3:Current-SP').substitute(
                prefix=self._prefix))
        lbl = SiriusLabel(
            gb, _PVName('LI-01:PS-QF3:Current-Mon').substitute(
                prefix=self._prefix))
        spnbox.showStepExponent = False
        gb.layout().addWidget(spnbox)
        gb.layout().addWidget(lbl)
        gb.layout().setAlignment(Qt.AlignTop)

        gb = QGroupBox('Data Acquisition Configs.', self)
        fl = QFormLayout(gb)
        measlay.addWidget(gb)
        self.pb_start = QPushButton('Start', gb)
        self.pb_start.clicked.connect(self.pb_start_clicked)
        self.pb_stop = QPushButton('Stop', gb)
        self.pb_stop.clicked.connect(self.pb_stop_clicked)
        self.pb_stop.setEnabled(False)
        hbox_bts = QHBoxLayout()
        hbox_bts.addWidget(self.pb_start)
        hbox_bts.addWidget(self.pb_stop)
        fl.addRow(hbox_bts)
        self.cbbox_plane = QComboBox(gb)
        self.cbbox_plane.addItem('Horizontal')
        self.cbbox_plane.addItem('Vertical')
        fl.addRow(QLabel('Plane', gb), self.cbbox_plane)
        self.spbox_steps = QSpinBoxPlus(gb)
        self.spbox_steps.setValue(11)
        fl.addRow(QLabel('Nr Steps', gb), self.spbox_steps)
        self.spbox_samples = QSpinBoxPlus(gb)
        self.spbox_samples.setMinimum(1)
        self.spbox_samples.setValue(16)
        fl.addRow(QLabel('Nr Samples per step', gb), self.spbox_samples)
        self.spbox_outliers = QSpinBoxPlus(gb)
        self.spbox_outliers.setMinimum(0)
        self.spbox_outliers.setValue(12)
        fl.addRow(QLabel('Nr Outliers', gb), self.spbox_outliers)
        self.spbox_I_ini = QDoubleSpinBoxPlus(gb)
        self.spbox_I_ini.setMinimum(-4)
        self.spbox_I_ini.setMaximum(4)
        self.spbox_I_ini.setValue(-0.7)
        self.spbox_I_ini.setDecimals(3)
        fl.addRow(QLabel('Initial Current [A]', gb), self.spbox_I_ini)
        self.spbox_I_end = QDoubleSpinBoxPlus(gb)
        self.spbox_I_end.setMinimum(-4)
        self.spbox_I_end.setMaximum(4)
        self.spbox_I_end.setValue(0.7)
        self.spbox_I_end.setDecimals(3)
        fl.addRow(QLabel('Final Current [A]', gb), self.spbox_I_end)
        self.spbox_threshold = QDoubleSpinBoxPlus(gb)
        self.spbox_threshold.setMinimum(0)
        self.spbox_threshold.setMaximum(20)
        self.spbox_threshold.setValue(4)
        self.spbox_threshold.setDecimals(2)
        fl.addRow(QLabel('Max. Size Accpbl. [mm]', gb), self.spbox_threshold)

        measlay.setStretch(0, 2)
        measlay.setStretch(1, 8)

        anllay = QVBoxLayout()

        gb = QGroupBox('Analysis Configs.', self)
        vl = QVBoxLayout(gb)
        anllay.addWidget(gb)
        self.spbox_energy = QDoubleSpinBoxPlus(gb)
        self.spbox_energy.setMinimum(0.511)
        self.spbox_energy.setMaximum(200)
        self.spbox_energy.setValue(150)
        self.spbox_energy.setDecimals(2)
        self.pb_analyse_data = QPushButton('Analyse', gb)
        self.pb_analyse_data.clicked.connect(self.pb_analyse_data_clicked)
        hl = QHBoxLayout()
        hl.addWidget(QLabel('Energy [MeV]', gb))
        hl.addWidget(self.spbox_energy)
        hl.addWidget(self.pb_analyse_data)
        vl.addLayout(hl)
        self.pb_save_data = QPushButton('Save Raw', gb)
        self.pb_save_data.clicked.connect(self.pb_save_data_clicked)
        self.pb_load_data = QPushButton('Load Raw', gb)
        self.pb_load_data.clicked.connect(self.pb_load_data_clicked)
        hl = QHBoxLayout()
        hl.addWidget(self.pb_save_data)
        hl.addWidget(self.pb_load_data)
        vl.addLayout(hl)
        self.logdisplay = PyDMLogDisplay(self, level=_log.INFO)
        vl.addWidget(self.logdisplay)

        resultsgb = QGroupBox('Results', self)
        gl2 = QGridLayout(resultsgb)
        gl2.addWidget(QLabel('Trans. Matrix', resultsgb), 0, 1, 1, 2)
        gl2.addWidget(QLabel('Parabola Fit', resultsgb), 0, 3, 1, 2)
        gl2.addWidget(QLabel('Hor.', resultsgb), 1, 1)
        gl2.addWidget(QLabel('Vert.', resultsgb), 1, 2)
        gl2.addWidget(QLabel('Hor.', resultsgb), 1, 3)
        gl2.addWidget(QLabel('Vert.', resultsgb), 1, 4)
        gl2.addWidget(QLabel('Norm. emitt.\n[mm.mrad]', resultsgb), 2, 0)
        gl2.addWidget(QLabel('beta [m]', resultsgb), 3, 0)
        gl2.addWidget(QLabel('alpha', resultsgb), 4, 0)
        for i, pref in enumerate(('nemit', 'beta', 'alpha')):
            for j, tp in enumerate(('x_tm', 'y_tm', 'x_parf', 'y_parf')):
                name = pref + tp
                lb = QLabel('----', resultsgb)
                setattr(self, 'lb_' + name, lb)
                gl2.addWidget(lb, i+2, j+1)

        wid = MatplotlibWidget(parent=self)
        axes = wid.figure.add_subplot(111)
        axes.set_xlabel('Quad. Current [A]')
        axes.set_ylabel('Beam Size [mm]')
        wid.figure.set_tight_layout(True)
        self.line_sigmax = axes.plot([], 'bo', lw=1, label='Horizontal')[0]
        self.line_sigmay = axes.plot([], 'ro', lw=1, label='Vertical')[0]
        self.line_fit = axes.plot([], '-k', lw=1)[0]
        wid.setObjectName('fig_sigma')
        wid.setStyleSheet('#fig_sigma{min-width: 25em;}')
        self.fig_sigma = wid

        gl.addWidget(self.plt_image, 0, 0, 2, 1)
        gl.addItem(measlay, 0, 1)
        gl.addWidget(self.fig_sigma, 1, 1)
        gl.addItem(anllay, 0, 2)
        gl.addWidget(resultsgb, 1, 2)
        gl.addWidget(self.fig_res, 0, 3, 2, 1)
예제 #4
0
    def _setupUi(self):
        pref = _PVName('LI-Glob:AP-MeasEnergy').substitute(prefix=self.prefix)
        self.plt_energy = SiriusTimePlot(
            self,
            init_y_channels=[pref.substitute(propty='Energy-Mon')],
            background=QColor('white'))
        self.plt_energy.setLabel('left', text='Energy [MeV]')
        self.plt_energy.setShowXGrid(True)
        self.plt_energy.setShowYGrid(True)
        c = self.plt_energy.curveAtIndex(0)
        c.color = QColor('blue')
        c.symbol = c.symbols['Circle']
        c.symbolSize = 10
        c.lineWidth = 3
        c.data_changed.connect(self._update_energy_stats)
        self.plt_energy.setTimeSpan(100)

        self.plt_spread = SiriusTimePlot(
            self,
            init_y_channels=[pref.substitute(propty='Spread-Mon')],
            background=QColor('white'))
        self.plt_spread.setLabel('left', text='Spread [%]')
        self.plt_spread.setShowXGrid(True)
        self.plt_spread.setShowYGrid(True)
        c = self.plt_spread.curveAtIndex(0)
        c.color = QColor('red')
        c.symbol = c.symbols['Circle']
        c.symbolSize = 10
        c.lineWidth = 3
        c.data_changed.connect(self._update_spread_stats)
        self.plt_spread.setTimeSpan(100)

        gb_ctrl = QGroupBox('Control', self)
        hl_ctrl = QHBoxLayout(gb_ctrl)

        vl = QVBoxLayout()
        wid = QWidget(gb_ctrl)
        wid.setLayout(QHBoxLayout())
        btn = PyDMStateButton(gb_ctrl,
                              pref.substitute(propty='MeasureCtrl-Sel'))
        led = SiriusLedState(gb_ctrl,
                             pref.substitute(propty='MeasureCtrl-Sts'))
        wid.layout().addWidget(btn)
        wid.layout().addWidget(led)
        vl.addWidget(QLabel('Start/Stop Acq.', gb_ctrl))
        vl.addWidget(wid)
        hl_ctrl.addLayout(vl)

        vl = QVBoxLayout()
        wid = QWidget(gb_ctrl)
        wid.setLayout(QHBoxLayout())
        spnbox = SiriusSpinbox(
            wid,
            _PVName('LI-01:PS-Spect:Current-SP').substitute(
                prefix=self.prefix))
        lbl = SiriusLabel(
            wid,
            _PVName('LI-01:PS-Spect:Current-Mon').substitute(
                prefix=self.prefix))
        spnbox.showStepExponent = False
        wid.layout().addWidget(spnbox)
        wid.layout().addWidget(lbl)
        vl.addWidget(QLabel('Spectrometer Current [A]', gb_ctrl))
        vl.addWidget(wid)
        hl_ctrl.addLayout(vl)

        gb_ener = QGroupBox('Properties', self)
        fl_ener = QFormLayout(gb_ener)

        wid = QWidget(gb_ener)
        wid.setLayout(QHBoxLayout())
        self.lb_ave_en = QLabel('0.000', wid)
        self.lb_std_en = QLabel('0.000', wid)
        wid.layout().addWidget(self.lb_ave_en)
        wid.layout().addWidget(
            QLabel('<html><head/><body><p>&#177;</p></body></html>', wid))
        wid.layout().addWidget(self.lb_std_en)
        fl_ener.addRow('Energy [MeV]', wid)

        wid = QWidget(gb_ener)
        wid.setLayout(QHBoxLayout())
        self.lb_ave_sp = QLabel('0.000', wid)
        self.lb_std_sp = QLabel('0.000', wid)
        wid.layout().addWidget(self.lb_ave_sp)
        wid.layout().addWidget(
            QLabel('<html><head/><body><p>&#177;</p></body></html>', wid))
        wid.layout().addWidget(self.lb_std_sp)
        fl_ener.addRow('Spread [%]', wid)

        hl_span = QHBoxLayout()
        hl_span.setSpacing(0)
        self.spbox_npoints = QSpinBoxPlus(self)
        self.spbox_npoints.setKeyboardTracking(False)
        self.spbox_npoints.setMinimum(10)
        self.spbox_npoints.setMaximum(200000)
        self.spbox_npoints.setValue(100)
        self.spbox_npoints.editingFinished.connect(self.nrpoints_edited)
        hl_span.addWidget(QLabel('Choose TimeSpan [s]:', self))
        hl_span.addWidget(self.spbox_npoints)
        self.pb_reset_data = QPushButton('Reset Data', self)
        self.pb_reset_data.clicked.connect(self.pb_reset_data_clicked)
        hl_span.addWidget(self.pb_reset_data)

        self.plt_image = SiriusProcessImage(self, device=pref)

        gb_trig = QGroupBox('Trigger', self)
        hbl = QHBoxLayout(gb_trig)
        hbl.addWidget(
            HLTriggerSimple(parent=self,
                            device='LI-Fam:TI-Scrn',
                            prefix=self.prefix))
        gb_trig.setLayout(hbl)

        gl = QGridLayout(self)
        gl.addLayout(hl_span, 0, 0, 1, 2)
        gl.addWidget(self.plt_image, 0, 2, 3, 1)
        gl.addWidget(self.plt_energy, 1, 0, 1, 2)
        gl.addWidget(self.plt_spread, 2, 0, 1, 2)
        gl.addWidget(gb_ctrl, 3, 0)
        gl.addWidget(gb_ener, 3, 1)
        gl.addWidget(gb_trig, 3, 2)
        gl.setColumnStretch(0, 3)
        gl.setColumnStretch(1, 2)
        gl.setColumnStretch(2, 3)