Beispiel #1
0
    def update(self):

        ts = self.ts
        vs = self.Vs
        ys = self.Ts
        self.curve.clear()

        self.ts = ts
        self.Vs = vs
        self.Ts = ys

        self.index -= 1
        a = pg.intColor(self.index,
                        hues=9,
                        values=1,
                        maxValue=255,
                        minValue=150,
                        maxHue=360,
                        minHue=0,
                        sat=255,
                        alpha=255)
        p = pg.colorStr(a)
        self.curve = pg.PlotCurveItem(symbol='o', pen=p)
        self.updatePlot()
        self.plot.addItem(self.curve)
Beispiel #2
0
 def setPen(self, pen):
     """
     Set the pen used for drawing text, axes, ticks, and grid lines.
     if pen == None, the default will be used (see :func:`setConfigOption 
     <pyqtgraph.setConfigOption>`)
     """
     self._pen = pen
     self.picture = None
     if pen is None:
         pen = pg.getConfigOption("foreground")
     self.labelStyle["color"] = "#" + pg.colorStr(pg.mkPen(pen).color())[:6]
     self.setLabel()
     self.update()
Beispiel #3
0
 def setPen(self, pen):
     """
     Set the pen used for drawing text, axes, ticks, and grid lines.
     if pen == None, the default will be used (see :func:`setConfigOption 
     <pyqtgraph.setConfigOption>`)
     """
     self._pen = pen
     self.picture = None
     if pen is None:
         pen = pg.getConfigOption('foreground')
     self.labelStyle['color'] = '#' + pg.colorStr(pg.mkPen(pen).color())[:6]
     self.setLabel()
     self.update()
def _marshallingQPainter(opts, prop_name, qPainter):
    if qPainter == 'pen':
        painter = pyqtgraph.mkPen(opts[prop_name])
        opts[prop_name + '_width'] = painter.width()
        opts[prop_name + '_dash'] = painter.dashPattern()
        opts[prop_name + '_cosmetic'] = painter.isCosmetic()
    elif qPainter == 'brush':
        painter = pyqtgraph.mkBrush(opts[prop_name])
    else:
        return

    color = pyqtgraph.colorStr(painter.color())
    opts[prop_name] = color
    opts[prop_name + '_style'] = painter.style()
Beispiel #5
0
def _marshallingQPainter(opts, prop_name, qPainter):
    if qPainter == "pen":
        painter = pyqtgraph.mkPen(opts[prop_name])
        opts[prop_name + "_width"] = painter.width()
        opts[prop_name + "_dash"] = painter.dashPattern()
        opts[prop_name + "_cosmetic"] = painter.isCosmetic()
    elif qPainter == "brush":
        painter = pyqtgraph.mkBrush(opts[prop_name])
    else:
        return

    color = pyqtgraph.colorStr(painter.color())
    opts[prop_name] = color
    opts[prop_name + "_style"] = painter.style()
Beispiel #6
0
 def createAxis(self, name='', color='k', logMode=False, verticalRange=None):
     axis = pg.AxisItem("left")
     labelStyle = {'color': '#'+pg.colorStr(pg.mkColor(color))[0:-2]}
     axis.setLabel(name,**labelStyle)
     viewbox = pg.ViewBox()
     axis.linkToView(viewbox)
     viewbox.setXLink(self.plot.vb)
     # viewbox.setYLink(self.plot.vb)
     axiszero = viewbox.menu.addAction('Set Axis to 0')
     axiszero.triggered.connect(lambda: self.setAxisToZero(viewbox))
     self.namedaxes[name] = [axis, viewbox]
     if not verticalRange == None:
         viewbox.setRange(yRange=verticalRange, disableAutoRange=True)
     col = self.findFirstEmptyColumnInGraphicsLayout()
     self.plotWidget.ci.addItem(axis, row = 0, col = col,  rowspan=1, colspan=1)
     self.plotWidget.ci.addItem(viewbox, row=0, col=50)
     axis.setLogMode(logMode)
     # self.newaxis.emit()
     return axis, viewbox
Beispiel #7
0
    def __init__(self, startPb, stopPb, dmmVisaCombo, thermometerCombo,
                 currentCombo, voltageSb, temperatureSb, yAxisCombo, plot, n,
                 errorDisplayTE, errorDisplayArray, zmqPublisher):

        self.startPb = startPb
        self.stopPb = stopPb
        self.dmmVisaCombo = dmmVisaCombo
        self.thermometerCombo = thermometerCombo
        self.currentCombo = currentCombo
        self.voltageSb = voltageSb
        self.temperatureSb = temperatureSb
        self.yAxisCombo = yAxisCombo
        self.plot = plot
        self.errorDisplayTE = errorDisplayTE
        self.errorDisplayArray = errorDisplayArray
        self.index = n
        self.publisher = zmqPublisher

        a = pg.intColor(self.index,
                        hues=9,
                        values=1,
                        maxValue=255,
                        minValue=150,
                        maxHue=360,
                        minHue=0,
                        sat=255,
                        alpha=255)
        p = pg.colorStr(a)
        self.curve = pg.PlotCurveItem(name='DC' + str(self.index + 1),
                                      symbol='o',
                                      pen=p)
        self.plot.addItem(self.curve)

        self.clearData()

        self.msmThread = None
        # self.restoreSettings()
        self.startPb.clicked.connect(self.startPbClicked)
        self.stopPb.clicked.connect(self.stopPbClicked)
        self.yAxisCombo.currentIndexChanged.connect(self.updatePlot)
Beispiel #8
0
    def toggleLegend(self):
        '''
		Toggle display of the legend. When on, display traces in 
		different colors.
		'''
        if self.legend == None:
            self.legend = self.plotI.addLegend()
            i = 0
            for k, t in self.traces.items():
                cl = pg.intColor(i, len(self.traces))
                t.setPen(cl)
                self.colors[k] = '#' + pg.colorStr(cl)[:-2]
                self.legend.addItem(t, t.name())
                i = i + 1
        else:
            for k, t in self.traces.items():
                t.setPen('k')
                self.colors[k] = "#000000"
            self.vb.removeItem(self.legend)
            del (self.legend)
            self.legend = None
            self.plotI.legend = None
        self.update()
Beispiel #9
0
    def __init__(self,optrode,parent=None):
        #super(Raw_Data_Monitor, self).__init__()
        QtGui.QWidget.__init__(self,parent=parent)        
        self.optrode = optrode

        self.plots = []
        
        self.raw_data_plot = XY_Line_Plots(parent=self)
        self.raw_data_plot.setYRange(0,4096)
        self.raw_data_plot.setLimits(yMin=0,yMax=4096,maxYRange=4096,minYRange=0)
        self.plots.append(self.raw_data_plot)
        
        n_items = len(self.optrode.buffer.lasers)*len(self.optrode.buffer.ai_channels)
        initial_colors = iter([pg.colorStr(pg.intColor(i,values=n_items)) \
                               for i in range(n_items)])
        
        chkbox_columns = []
        for laser in self.optrode.buffer.lasers:
            chkbox_columns.append(Plot_Checkboxes_Column(initial_colors,col_label = str(laser)))
            for channel in self.optrode.buffer.ai_channels:
                self.raw_data_plot.add_data(Teensy_Plot_Raw_Data(self.raw_data_plot,\
                                                                 self.optrode.buffer,\
                                                                 laser, channel,\
                                                                 label = channel,\
                                                                 name = '_'.join([laser,channel])))
                chkbox_columns[-1].add_row(self.raw_data_plot.xydatas[-1])
            chkbox_columns[-1].finalize_layout()
            
        self.checkboxes = Plot_Checkboxes_2D(chkbox_columns)

        
        
        self.transfer_stats_plots = Transfer_Status_Plots(self.optrode.buffer,\
                    {'byte_count': {'x':0,'y':0,'title':'byte count per block',\
                                    'left': ('bytes')},\
                     'line_count': {'x':0, 'y':1, 'title':'sample count per block',\
                                    'left': ('samples')},\
                     'dt': {'x':0, 'y':2, 'title':'acquisition time per block',\
                                  'left': ('acq time','s')},\
                     'tx_rate': {'x':0, 'y':3, 'title':'data transfer rate',\
                                 'left':('Mbits/s')},\
                     'smpl_rate': {'x':0,'y':4, 'title':'data sampling rate',\
                                   'left':('kHz')}})
        
        self.plots.append(self.transfer_stats_plots)

        self.acq_control = Acquisition_Control(self.optrode,self.plots,parent=self)  
        
        self.raw_data_control = Save_Raw_Data_Control(self.optrode.raw_export.param_q,\
                                                      self.acq_control)
        self.snapshot_control = Save_Snapshot_Control(self.raw_data_plot,\
                                                      self.acq_control)
        
        right_side_layout = QtGui.QVBoxLayout()
        right_side_layout.addWidget(self.acq_control)
        right_side_layout.addWidget(self.checkboxes)
        right_side_layout.addWidget(self.raw_data_control)
        right_side_layout.addWidget(self.snapshot_control)
        
        raw_data_layout = QtGui.QHBoxLayout()
        raw_data_layout.addWidget(self.raw_data_plot,1)
        raw_data_layout.addLayout(right_side_layout)
        
        layout = QtGui.QVBoxLayout()
        layout.addLayout(raw_data_layout,2)
        layout.addWidget(self.transfer_stats_plots,1)
        self.setLayout(layout)
    
        self.t_optrode_data = QtCore.QTimer()
        self.t_optrode_data.timeout.connect(self.update_optrode_data)
        self.t_optrode_data.start(50) # ms
        
        self.t_optrode_stats = QtCore.QTimer()
        self.t_optrode_stats.timeout.connect(self.update_optrode_stats)
        self.t_optrode_stats.start(500) # ms

        self.t_optrode_tx_plots = QtCore.QTimer()
        self.t_optrode_tx_plots.timeout.connect(self.update_optrode_tx_plots)
        self.t_optrode_tx_plots.start(500) #ms

        self.t_optrode_data_plots = QtCore.QTimer()
        self.t_optrode_data_plots.timeout.connect(self.update_optrode_data_plots)
        self.t_optrode_data_plots.start(200) #ms
    def __init__(self, directory='.', **kwargs):
        super(astraPlotWidget, self).__init__(**kwargs)
        self.beam = raf.beam()
        self.twiss = rtf.twiss()
        self.directory = directory
        ''' twissPlotWidget '''
        self.twissPlotView = GraphicsView(useOpenGL=True)
        self.twissPlotWidget = GraphicsLayout()
        self.twissPlotView.setCentralItem(self.twissPlotWidget)

        self.latticePlotData = imageio.imread('lattice_plot.png')
        self.latticePlots = {}
        self.twissPlots = {}
        i = -1
        for entry in self.twissplotLayout:
            if entry == 'next_row':
                self.twissPlotWidget.nextRow()
            else:
                i += 1
                p = self.twissPlotWidget.addPlot(title=entry['name'])
                p.showGrid(x=True, y=True)
                vb = p.vb
                vb.setYRange(*entry['range'])
                latticePlot = ImageItem(self.latticePlotData)
                latticePlot.setOpts(axisOrder='row-major')
                vb.addItem(latticePlot)
                latticePlot.setZValue(-1)  # make sure this image is on top
                # latticePlot.setOpacity(0.5)
                self.twissPlots[entry['name']] = p.plot(
                    pen=mkPen('b', width=3))
                self.latticePlots[p.vb] = latticePlot
                p.vb.sigRangeChanged.connect(self.scaleLattice)
        ''' beamPlotWidget '''
        self.beamPlotWidget = QWidget()
        self.beamPlotLayout = QVBoxLayout()
        self.item = ImageItem()
        self.beamPlotWidget.setLayout(self.beamPlotLayout)
        self.beamPlotView = ImageView(imageItem=self.item)
        self.rainbow = rainbow()
        self.item.setLookupTable(self.rainbow)
        self.item.setLevels([0, 1])
        # self.beamPlotWidgetGraphicsLayout = GraphicsLayout()
        # p = self.beamPlotWidgetGraphicsLayout.addPlot(title='beam')
        # p.showGrid(x=True, y=True)
        # self.beamPlot = p.plot(pen=None, symbol='+')
        # self.beamPlotView.setCentralItem(self.beamPlotWidgetGraphicsLayout)
        self.beamPlotXAxisCombo = QComboBox()
        self.beamPlotXAxisCombo.addItems(
            ['x', 'y', 'zn', 'cpx', 'cpy', 'BetaGamma'])
        self.beamPlotYAxisCombo = QComboBox()
        self.beamPlotYAxisCombo.addItems(
            ['x', 'y', 'zn', 'cpx', 'cpy', 'BetaGamma'])
        self.beamPlotNumberBins = QSpinBox()
        self.beamPlotNumberBins.setRange(10, 500)
        self.beamPlotNumberBins.setSingleStep(10)
        self.histogramBins = 100
        self.beamPlotNumberBins.setValue(self.histogramBins)
        self.beamPlotAxisWidget = QWidget()
        self.beamPlotAxisLayout = QHBoxLayout()
        self.beamPlotAxisWidget.setLayout(self.beamPlotAxisLayout)
        self.beamPlotAxisLayout.addWidget(self.beamPlotXAxisCombo)
        self.beamPlotAxisLayout.addWidget(self.beamPlotYAxisCombo)
        self.beamPlotAxisLayout.addWidget(self.beamPlotNumberBins)
        self.beamPlotXAxisCombo.currentIndexChanged.connect(self.plotDataBeam)
        self.beamPlotYAxisCombo.currentIndexChanged.connect(self.plotDataBeam)
        self.beamPlotNumberBins.valueChanged.connect(self.plotDataBeam)
        # self.beamPlotXAxisCombo.setCurrentIndex(2)
        # self.beamPlotYAxisCombo.setCurrentIndex(5)
        self.beamPlotLayout.addWidget(self.beamPlotAxisWidget)
        self.beamPlotLayout.addWidget(self.beamPlotView)
        ''' slicePlotWidget '''
        self.sliceParams = [
            {
                'name': 'slice_normalized_horizontal_emittance',
                'units': 'm-rad',
                'text': 'enx'
            },
            {
                'name': 'slice_normalized_vertical_emittance',
                'units': 'm-rad',
                'text': 'eny'
            },
            {
                'name': 'slice_peak_current',
                'units': 'A',
                'text': 'PeakI'
            },
            {
                'name': 'slice_relative_momentum_spread',
                'units': '%',
                'text': 'sigma-p'
            },
        ]
        self.slicePlotWidget = QWidget()
        self.slicePlotLayout = QVBoxLayout()
        self.slicePlotWidget.setLayout(self.slicePlotLayout)
        # self.slicePlotView = GraphicsView(useOpenGL=True)
        self.slicePlotWidgetGraphicsLayout = GraphicsLayoutWidget()
        # self.slicePlots = {}
        self.slicePlotCheckbox = {}
        self.curve = {}
        self.sliceaxis = {}
        self.slicePlotCheckboxWidget = QWidget()
        self.slicePlotCheckboxLayout = QVBoxLayout()
        self.slicePlotCheckboxWidget.setLayout(self.slicePlotCheckboxLayout)
        self.slicePlot = self.slicePlotWidgetGraphicsLayout.addPlot(
            title='Slice', row=0, col=50)
        self.slicePlot.showAxis('left', False)
        self.slicePlot.showGrid(x=True, y=True)
        i = -1
        colors = ['b', 'r', 'g', 'k']
        for param in self.sliceParams:
            i += 1
            axis = AxisItem("left")
            labelStyle = {'color': '#' + colorStr(mkColor(colors[i]))[0:-2]}
            axis.setLabel(text=param['text'],
                          units=param['units'],
                          **labelStyle)
            viewbox = ViewBox()
            axis.linkToView(viewbox)
            viewbox.setXLink(self.slicePlot.vb)
            self.sliceaxis[param['name']] = [axis, viewbox]
            self.curve[param['name']] = PlotDataItem(pen=colors[i], symbol='+')
            viewbox.addItem(self.curve[param['name']])
            col = self.findFirstEmptyColumnInGraphicsLayout()
            self.slicePlotWidgetGraphicsLayout.ci.addItem(axis,
                                                          row=0,
                                                          col=col,
                                                          rowspan=1,
                                                          colspan=1)
            self.slicePlotWidgetGraphicsLayout.ci.addItem(viewbox,
                                                          row=0,
                                                          col=50)
            p.showGrid(x=True, y=True)
            # self.slicePlots[param] = self.slicePlot.plot(pen=colors[i], symbol='+')
            self.slicePlotCheckbox[param['name']] = QCheckBox(param['text'])
            self.slicePlotCheckboxLayout.addWidget(
                self.slicePlotCheckbox[param['name']])
            self.slicePlotCheckbox[param['name']].stateChanged.connect(
                self.plotDataSlice)
        # self.slicePlotView.setCentralItem(self.slicePlotWidgetGraphicsLayout)
        self.slicePlotSliceWidthWidget = QSpinBox()
        self.slicePlotSliceWidthWidget.setMaximum(1000)
        self.slicePlotSliceWidthWidget.setValue(100)
        self.slicePlotSliceWidthWidget.setSingleStep(10)
        self.slicePlotSliceWidthWidget.setSuffix("fs")
        self.slicePlotSliceWidthWidget.setSpecialValueText('Automatic')
        self.slicePlotAxisWidget = QWidget()
        self.slicePlotAxisLayout = QHBoxLayout()
        self.slicePlotAxisWidget.setLayout(self.slicePlotAxisLayout)
        self.slicePlotAxisLayout.addWidget(self.slicePlotCheckboxWidget)
        self.slicePlotAxisLayout.addWidget(self.slicePlotSliceWidthWidget)
        # self.slicePlotXAxisCombo.currentIndexChanged.connect(self.plotDataSlice)
        self.slicePlotSliceWidthWidget.valueChanged.connect(
            self.changeSliceLength)
        # self.beamPlotXAxisCombo.setCurrentIndex(2)
        # self.beamPlotYAxisCombo.setCurrentIndex(5)
        self.slicePlotLayout.addWidget(self.slicePlotAxisWidget)
        self.slicePlotLayout.addWidget(self.slicePlotWidgetGraphicsLayout)

        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.tabWidget = QTabWidget()

        self.folderButton = QPushButton('Select Directory')
        self.folderLineEdit = QLineEdit()
        self.folderLineEdit.setReadOnly(True)
        self.folderLineEdit.setText(self.directory)
        self.reloadButton = QPushButton()
        self.reloadButton.setIcon(qApp.style().standardIcon(
            QStyle.SP_BrowserReload))
        self.folderWidget = QGroupBox()
        self.folderLayout = QHBoxLayout()
        self.folderLayout.addWidget(self.folderButton)
        self.folderLayout.addWidget(self.folderLineEdit)
        self.folderLayout.addWidget(self.reloadButton)
        self.folderWidget.setLayout(self.folderLayout)
        self.folderWidget.setMaximumWidth(800)
        self.reloadButton.clicked.connect(
            lambda: self.changeDirectory(self.directory))
        self.folderButton.clicked.connect(self.changeDirectory)

        self.fileSelector = QComboBox()
        self.fileSelector.currentIndexChanged.connect(self.updateScreenCombo)
        self.screenSelector = QComboBox()
        self.screenSelector.currentIndexChanged.connect(self.changeScreen)
        self.beamWidget = QGroupBox()
        self.beamLayout = QHBoxLayout()
        self.beamLayout.addWidget(self.fileSelector)
        self.beamLayout.addWidget(self.screenSelector)
        self.beamWidget.setLayout(self.beamLayout)
        self.beamWidget.setMaximumWidth(800)
        self.beamWidget.setVisible(False)

        self.folderBeamWidget = QWidget()
        self.folderBeamLayout = QHBoxLayout()
        self.folderBeamLayout.setAlignment(Qt.AlignLeft)
        self.folderBeamWidget.setLayout(self.folderBeamLayout)
        self.folderBeamLayout.addWidget(self.folderWidget)
        self.folderBeamLayout.addWidget(self.beamWidget)

        self.tabWidget.addTab(self.twissPlotView, 'Twiss Plots')
        self.tabWidget.addTab(self.beamPlotWidget, 'Beam Plots')
        self.tabWidget.addTab(self.slicePlotWidget, 'Slice Beam Plots')
        self.tabWidget.currentChanged.connect(self.changeTab)
        self.layout.addWidget(self.folderBeamWidget)
        self.layout.addWidget(self.tabWidget)

        self.plotType = 'Twiss'
        self.changeDirectory(self.directory)
    def __init__(self, directory='.', **kwargs):
        super(astraPlotWidget, self).__init__(**kwargs)
        self.beam = raf.beam()
        self.twiss = rtf.twiss()
        self.directory = directory
        ''' twissPlotWidget '''
        self.twissPlotView = GraphicsView(useOpenGL=True)
        self.twissPlotWidget = GraphicsLayout()
        self.twissPlotView.setCentralItem(self.twissPlotWidget)

        self.latticePlotData = imageio.imread(
            os.path.dirname(os.path.abspath(__file__)) + '/lattice_plot.png')
        self.latticePlots = {}
        self.twissPlots = {}
        i = -1
        for entry in self.twissplotLayout:
            if entry == 'next_row':
                self.twissPlotWidget.nextRow()
            else:
                i += 1
                p = self.twissPlotWidget.addPlot(title=entry['name'])
                p.showGrid(x=True, y=True)
                vb = p.vb
                vb.setYRange(*entry['range'])
                latticePlot = ImageItem(self.latticePlotData)
                latticePlot.setOpts(axisOrder='row-major')
                vb.addItem(latticePlot)
                latticePlot.setZValue(-1)  # make sure this image is on top
                # latticePlot.setOpacity(0.5)
                self.twissPlots[entry['name']] = p.plot(
                    pen=mkPen('b', width=3))
                self.latticePlots[p.vb] = latticePlot
                p.vb.sigRangeChanged.connect(self.scaleLattice)
        ''' beamPlotWidget '''
        self.beamPlotWidget = QWidget()
        self.beamPlotLayout = QVBoxLayout()
        self.beamPlotWidget.setLayout(self.beamPlotLayout)

        #
        # self.beamPlotChoice =
        #

        self.beamPlotAxisWidget = QWidget()
        self.beamPlotAxisWidget.setMaximumHeight(100)
        Form = self.beamPlotAxisWidget

        self.beamPlotXAxisDict = OrderedDict()
        self.beamPlotXAxisDict['x'] = {'scale': 1e3, 'axis': 'x [mm]'}
        self.beamPlotXAxisDict['y'] = {'scale': 1e3, 'axis': 'y [mm]'}
        self.beamPlotXAxisDict['z'] = {
            'scale': 1e6,
            'axis': 'z [micron]',
            'norm': True
        }
        self.beamPlotXAxisDict['t'] = {
            'scale': 1e12,
            'axis': 't [ps]',
            'norm': True
        }
        self.beamPlotXAxisDict['cpx'] = {'scale': 1e3, 'axis': 'cpx [keV]'}
        self.beamPlotXAxisDict['cpy'] = {'scale': 1e3, 'axis': 'cpy [keV]'}
        self.beamPlotXAxisDict['BetaGamma'] = {
            'scale': 0.511,
            'axis': 'cp [MeV]'
        }

        # Form.setObjectName(("Form"))
        # Form.resize(874, 212)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
        Form.setSizePolicy(sizePolicy)
        self.horizontalLayout = QHBoxLayout(Form)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.beamPlotXAxisCombo = QComboBox(Form)
        self.beamPlotXAxisCombo.addItems(list(self.beamPlotXAxisDict.keys()))
        self.beamPlotXAxisCombo.setCurrentIndex(2)
        self.horizontalLayout.addWidget(self.beamPlotXAxisCombo)
        self.beamPlotYAxisCombo = QComboBox(Form)
        self.beamPlotYAxisCombo.addItems(list(self.beamPlotXAxisDict.keys()))
        self.beamPlotYAxisCombo.setCurrentIndex(6)
        self.horizontalLayout.addWidget(self.beamPlotYAxisCombo)
        self.groupBox = QGroupBox(Form)
        self.groupBox.setObjectName("groupBox")
        self.formLayout = QFormLayout(self.groupBox)
        self.formLayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
        self.formLayout.setObjectName("formLayout")
        self.chooseSliceWidth = QRadioButton(self.groupBox)
        self.chooseSliceWidth.setObjectName(("chooseSliceWidth"))
        self.formLayout.setWidget(0, QFormLayout.LabelRole,
                                  self.chooseSliceWidth)
        self.sliceWidth = QDoubleSpinBox(self.groupBox)
        self.sliceWidth.setDecimals(6)
        self.sliceWidth.setObjectName("sliceWidth")
        self.formLayout.setWidget(0, QFormLayout.FieldRole, self.sliceWidth)
        self.chooseSliceNumber = QRadioButton(self.groupBox)
        self.chooseSliceNumber.setChecked(True)
        self.chooseSliceNumber.setObjectName("chooseSliceNumber")
        self.formLayout.setWidget(1, QFormLayout.LabelRole,
                                  self.chooseSliceNumber)
        self.sliceNumber = QSpinBox(self.groupBox)
        self.sliceNumber.setObjectName(("sliceNumber"))
        self.formLayout.setWidget(1, QFormLayout.FieldRole, self.sliceNumber)
        self.horizontalLayout.addWidget(self.groupBox)
        self.chooseSliceWidth.setText(_translate("Form", "Slice Width", None))
        self.chooseSliceNumber.setText(
            _translate("Form", "Number of Slices", None))
        self.sliceWidth.setRange(1e-6, 1)
        self.sliceWidth.setSingleStep(0.00001)
        self.histogramWidth = 0.0005
        self.sliceWidth.setValue(self.histogramWidth)
        # self.sliceNumber = QSpinBox()
        self.sliceNumber.setRange(10, 10000)
        self.sliceNumber.setSingleStep(10)
        self.histogramBins = 100
        self.sliceNumber.setValue(self.histogramBins)

        # self.beamPlotXAxisCombo = QComboBox()

        # self.beamPlotAxisLayout = QHBoxLayout()
        # self.beamPlotAxisWidget.setLayout(self.beamPlotAxisLayout)

        # self.beamPlotAxisLayout.addWidget(self.beamPlotXAxisCombo)
        # self.beamPlotAxisLayout.addWidget(self.beamPlotYAxisCombo)
        # self.beamPlotAxisLayout.addWidget(self.beamPlotNumberBins)
        self.beamPlotXAxisCombo.currentIndexChanged.connect(self.plotDataBeam)
        self.beamPlotYAxisCombo.currentIndexChanged.connect(self.plotDataBeam)
        self.chooseSliceNumber.toggled.connect(self.plotDataBeam)
        self.sliceNumber.valueChanged.connect(self.plotDataBeam)
        self.sliceWidth.valueChanged.connect(self.plotDataBeam)
        # self.beamPlotXAxisCombo.setCurrentIndex(2)
        # self.beamPlotYAxisCombo.setCurrentIndex(5)
        self.canvasWidget = QWidget()
        l = QVBoxLayout(self.canvasWidget)
        self.sc = MyStaticMplCanvas(self.canvasWidget,
                                    width=1,
                                    height=1,
                                    dpi=150)
        l.addWidget(self.sc)
        self.beamPlotLayout.addWidget(self.beamPlotAxisWidget)
        self.beamPlotLayout.addWidget(self.canvasWidget)
        ''' slicePlotWidget '''
        self.sliceParams = [
            {
                'name': 'slice_normalized_horizontal_emittance',
                'units': 'm-rad',
                'text': 'enx'
            },
            {
                'name': 'slice_normalized_vertical_emittance',
                'units': 'm-rad',
                'text': 'eny'
            },
            {
                'name': 'slice_peak_current',
                'units': 'A',
                'text': 'PeakI'
            },
            {
                'name': 'slice_relative_momentum_spread',
                'units': '%',
                'text': 'sigma-p'
            },
            {
                'name': 'slice_beta_x',
                'units': 'm',
                'text': 'beta_x'
            },
            {
                'name': 'slice_beta_y',
                'units': 'm',
                'text': 'beta_y'
            },
        ]
        self.slicePlotWidget = QWidget()
        self.slicePlotLayout = QVBoxLayout()
        self.slicePlotWidget.setLayout(self.slicePlotLayout)
        # self.slicePlotView = GraphicsView(useOpenGL=True)
        self.slicePlotWidgetGraphicsLayout = GraphicsLayoutWidget()
        # self.slicePlots = {}
        self.slicePlotCheckbox = {}
        self.curve = {}
        self.sliceaxis = {}
        self.slicePlotCheckboxWidget = QWidget()
        self.slicePlotCheckboxLayout = QVBoxLayout()
        self.slicePlotCheckboxWidget.setLayout(self.slicePlotCheckboxLayout)
        self.slicePlot = self.slicePlotWidgetGraphicsLayout.addPlot(
            title='Slice', row=0, col=50)
        self.slicePlot.showAxis('left', False)
        self.slicePlot.showGrid(x=True, y=True)
        i = -1
        colors = ['b', 'r', 'g', 'k', 'y', 'm', 'c']
        for param in self.sliceParams:
            i += 1
            axis = AxisItem("left")
            labelStyle = {'color': '#' + colorStr(mkColor(colors[i]))[0:-2]}
            axis.setLabel(text=param['text'],
                          units=param['units'],
                          **labelStyle)
            viewbox = ViewBox()
            axis.linkToView(viewbox)
            viewbox.setXLink(self.slicePlot.vb)
            self.sliceaxis[param['name']] = [axis, viewbox]
            self.curve[param['name']] = PlotDataItem(pen=colors[i], symbol='+')
            viewbox.addItem(self.curve[param['name']])
            col = self.findFirstEmptyColumnInGraphicsLayout()
            self.slicePlotWidgetGraphicsLayout.ci.addItem(axis,
                                                          row=0,
                                                          col=col,
                                                          rowspan=1,
                                                          colspan=1)
            self.slicePlotWidgetGraphicsLayout.ci.addItem(viewbox,
                                                          row=0,
                                                          col=50)
            p.showGrid(x=True, y=True)
            # self.slicePlots[param] = self.slicePlot.plot(pen=colors[i], symbol='+')
            self.slicePlotCheckbox[param['name']] = QCheckBox(param['text'])
            self.slicePlotCheckboxLayout.addWidget(
                self.slicePlotCheckbox[param['name']])
            self.slicePlotCheckbox[param['name']].stateChanged.connect(
                self.plotDataSlice)
        # self.slicePlotView.setCentralItem(self.slicePlotWidgetGraphicsLayout)
        self.slicePlotSliceWidthWidget = QSpinBox()
        self.slicePlotSliceWidthWidget.setMaximum(500)
        self.slicePlotSliceWidthWidget.setValue(100)
        self.slicePlotSliceWidthWidget.setSingleStep(10)
        self.slicePlotSliceWidthWidget.setSuffix(" slices")
        self.slicePlotSliceWidthWidget.setSpecialValueText('Automatic')
        self.slicePlotAxisWidget = QWidget()
        self.slicePlotAxisLayout = QHBoxLayout()
        self.slicePlotAxisWidget.setLayout(self.slicePlotAxisLayout)
        self.slicePlotAxisLayout.addWidget(self.slicePlotCheckboxWidget)
        self.slicePlotAxisLayout.addWidget(self.slicePlotSliceWidthWidget)
        # self.slicePlotXAxisCombo.currentIndexChanged.connect(self.plotDataSlice)
        self.slicePlotSliceWidthWidget.valueChanged.connect(
            self.changeSliceLength)
        # self.beamPlotXAxisCombo.setCurrentIndex(2)
        # self.beamPlotYAxisCombo.setCurrentIndex(5)
        self.slicePlotLayout.addWidget(self.slicePlotAxisWidget)
        self.slicePlotLayout.addWidget(self.slicePlotWidgetGraphicsLayout)

        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.tabWidget = QTabWidget()

        self.folderButton = QPushButton('Select Directory')
        self.folderLineEdit = QLineEdit()
        self.folderLineEdit.setReadOnly(True)
        self.folderLineEdit.setText(self.directory)
        self.reloadButton = QPushButton()
        self.reloadButton.setIcon(qApp.style().standardIcon(
            QStyle.SP_BrowserReload))
        self.folderWidget = QGroupBox()
        self.folderLayout = QHBoxLayout()
        self.folderLayout.addWidget(self.folderButton)
        self.folderLayout.addWidget(self.folderLineEdit)
        self.folderLayout.addWidget(self.reloadButton)
        self.folderWidget.setLayout(self.folderLayout)
        self.folderWidget.setMaximumWidth(800)
        self.reloadButton.clicked.connect(
            lambda: self.changeDirectory(self.directory))
        self.folderButton.clicked.connect(self.changeDirectory)

        self.fileSelector = QComboBox()
        self.fileSelector.currentIndexChanged.connect(self.updateScreenCombo)
        self.screenSelector = QComboBox()
        self.screenSelector.currentIndexChanged.connect(self.changeScreen)
        self.beamWidget = QGroupBox()
        self.beamLayout = QHBoxLayout()
        self.beamLayout.addWidget(self.fileSelector)
        self.beamLayout.addWidget(self.screenSelector)
        self.beamWidget.setLayout(self.beamLayout)
        self.beamWidget.setMaximumWidth(800)
        self.beamWidget.setVisible(False)

        self.folderBeamWidget = QWidget()
        self.folderBeamLayout = QHBoxLayout()
        self.folderBeamLayout.setAlignment(Qt.AlignLeft)
        self.folderBeamWidget.setLayout(self.folderBeamLayout)
        self.folderBeamLayout.addWidget(self.folderWidget)
        self.folderBeamLayout.addWidget(self.beamWidget)

        self.tabWidget.addTab(self.twissPlotView, 'Twiss Plots')
        self.tabWidget.addTab(self.beamPlotWidget, 'Beam Plots')
        self.tabWidget.addTab(self.slicePlotWidget, 'Slice Beam Plots')
        # self.log = lw.loggerWidget()
        # self.log.addLogger(logger)
        # sys.stdout = lw.redirectLogger(self.log, 'stdout')
        # self.tabWidget.addTab(self.log,'Log')
        self.tabWidget.currentChanged.connect(self.changeTab)
        self.layout.addWidget(self.folderBeamWidget)
        self.layout.addWidget(self.tabWidget)

        self.plotType = 'Twiss'
        self.changeDirectory(self.directory)
Beispiel #12
0
    def __init__(self, **kwargs):
        super(multiAxisPlotWidget, self).__init__(**kwargs)
        ''' These are for reading data files from ASTRA and Elegant '''
        self.multiaxisPlotWidget = QWidget()
        self.multiaxisPlotLayout = QVBoxLayout()
        self.multiaxisPlotWidget.setLayout(self.multiaxisPlotLayout)
        self.multiaxisPlotWidgetGraphicsLayout = pg.GraphicsLayoutWidget()
        self.multiaxisPlotCheckbox = {}
        self.viewboxes = {}
        self.curves = {}
        self.multiaxisaxis = {}
        self.multiaxisPlotCheckboxWidget = QWidget()
        self.multiaxisPlotCheckboxLayout = QGridLayout()
        self.multiaxisPlotCheckboxWidget.setLayout(
            self.multiaxisPlotCheckboxLayout)
        self.multiaxisPlot = self.multiaxisPlotWidgetGraphicsLayout.addPlot(
            title='Slice',
            row=2,
            col=len(self.plotParams) + 1,
            rowspan=1,
            colspan=1)
        self.multiaxisPlot.showAxis('left', False)
        self.multiaxisPlot.showGrid(x=True, y=True)
        self.multiaxisPlot.vb.sigResized.connect(self.updateViews)
        self.shadowCurves = []
        i = 0
        for param in self.plotParams:
            axis = pg.AxisItem("left")
            labelStyle = {
                'color': '#' + pg.colorStr(pg.mkColor(self.colors[i]))[0:-2]
            }
            axis.setLabel(text=param['name'],
                          units=param['units'],
                          **labelStyle)
            axis.setZValue(-10000)
            viewbox = pg.ViewBox()
            self.viewboxes[param['label']] = viewbox
            axis.linkToView(viewbox)
            viewbox.setXLink(self.multiaxisPlot.vb)
            self.multiaxisaxis[param['label']] = [axis, viewbox]
            self.multiaxisPlotWidgetGraphicsLayout.addItem(
                axis,
                row=2,
                col=(len(self.plotParams) - i),
                rowspan=1,
                colspan=1)
            self.multiaxisPlot.scene().addItem(viewbox)
            viewbox.setLimits(yMin=0)
            self.multiaxisPlotCheckbox[param['label']] = QCheckBox(
                param['label'])
            self.multiaxisPlotCheckbox[param['label']].setChecked(False)

            self.multiaxisPlotCheckboxLayout.addWidget(
                self.multiaxisPlotCheckbox[param['label']], i % 3, int(i / 3))
            self.multiaxisPlotCheckbox[param['label']].stateChanged.connect(
                self.updateMultiAxisPlot)
            i += 1

        self.multiaxisPlotAxisWidget = QWidget()
        self.multiaxisPlotAxisLayout = QHBoxLayout()
        self.multiaxisPlotAxisWidget.setLayout(self.multiaxisPlotAxisLayout)
        self.multiaxisPlotAxisLayout.addWidget(
            self.multiaxisPlotCheckboxWidget)
        self.multiaxisPlotLayout.addWidget(self.multiaxisPlotAxisWidget)
        self.multiaxisPlotLayout.addWidget(
            self.multiaxisPlotWidgetGraphicsLayout)

        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.layout.addWidget(self.multiaxisPlotWidget)
        ''' used for style cycling '''
        self.plotColor = 0
Beispiel #13
0
def color_iter(n_items):
    return iter([pg.colorStr(pg.intColor(i,values=n_items)) \
                               for i in range(n_items)])