def setUI(self): self.vlayout = QtWidgets.QVBoxLayout() self.parent.setLayout(self.vlayout) form = QtWidgets.QWidget() self.viewer1D = Viewer1DBasic(form) self.vlayout.addWidget(form) self.fftbutton1D = QtWidgets.QPushButton() self.fftbutton1D.setText("") icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/icons/Icon_Library/FFT.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.fftbutton1D.setIcon(icon) self.fftbutton1D.setCheckable(True) self.fftbutton1D.clicked.connect(self.update_plot) vbox = self.viewer1D.parent.layout() widg = QtWidgets.QWidget() hbox = QtWidgets.QHBoxLayout() widg.setLayout(hbox) vbox.insertWidget(0, widg) hbox.addWidget(self.fftbutton1D) hbox.addStretch() self.viewer1D.ROI = LinearRegionItem(values=[0, 100]) self.viewer1D.plotwidget.plotItem.addItem(self.viewer1D.ROI) self.data_filtered_plot = self.viewer1D.plotwidget.plotItem.plot() self.data_filtered_plot.setPen('w') self.viewer1D.ROI.sigRegionChangeFinished.connect(self.set_data) self.viewer1D.ROIfft = LinearRegionItem() self.viewer1D.plotwidget.plotItem.addItem(self.viewer1D.ROIfft) self.viewer1D.ROIfft.sigRegionChangeFinished.connect(self.update_filter) self.parent.show()
def set_data(self, datas_transposed, temp_data=False, restore_nav_axes=True, **kwargs): """ """ try: if restore_nav_axes: nav_axes = dict([]) for ind, ax in enumerate(self.nav_axes_dicts): nav_axes[f'nav_{ind}'] = ax self.restore_nav_axes(nav_axes) ########################################################################## #display the correct signal viewer if len(datas_transposed.axes_manager.signal_shape) == 0: #signal data are 0D self.ui.viewer1D.parent.setVisible(True) self.ui.viewer2D.parent.setVisible(False) elif len(datas_transposed.axes_manager.signal_shape) == 1: #signal data are 1D self.ui.viewer1D.parent.setVisible(True) self.ui.viewer2D.parent.setVisible(False) elif len(datas_transposed.axes_manager.signal_shape) == 2: #signal data are 2D self.ui.viewer1D.parent.setVisible(False) self.ui.viewer2D.parent.setVisible(True) self.x_axis = Axis() self.y_axis = Axis() if len(datas_transposed.axes_manager.signal_shape) == 1 or len(datas_transposed.axes_manager.signal_shape) == 2:#signal data are 1D if 'x_axis' in kwargs: if not isinstance(kwargs['x_axis'], dict): self.x_axis['data'] = kwargs['x_axis'][:] self.x_axis = kwargs['x_axis'] else: self.x_axis = copy.deepcopy(kwargs['x_axis']) else: self.x_axis['data'] = self.set_axis(datas_transposed.axes_manager.signal_shape[0]) if 'y_axis' in kwargs: self.ui.viewer1D.set_axis_label(axis_settings=dict(orientation='left', label=kwargs['y_axis']['label'], units=kwargs['y_axis']['units'])) if len(datas_transposed.axes_manager.signal_shape)==2:#signal data is 2D if 'y_axis' in kwargs: if not isinstance(kwargs['y_axis'], dict): self.y_axis['data'] = kwargs['y_axis'][:] self.y_axis = kwargs['y_axis'] else: self.y_axis = copy.deepcopy(kwargs['y_axis']) else: self.y_axis['data'] = self.set_axis(datas_transposed.axes_manager.signal_shape[1]) axes_nav = self.get_selected_axes_indexes() if len(axes_nav) == 0 or len(axes_nav) == 1: self.update_viewer_data(*self.ui.navigator1D.ui.crosshair.get_positions()) elif len(axes_nav) == 2: self.update_viewer_data(*self.ui.navigator2D.ui.crosshair.get_positions()) ##get ROI bounds from viewers if any ROI_bounds_1D=[] try: self.ROI1D.getRegion() indexes_values = utils.find_index(self.ui.viewer1D.x_axis, self.ROI1D.getRegion()) ROI_bounds_1D.append(QPointF(indexes_values[0][0], indexes_values[1][0])) except Exception as e: logger.warning(str(e)) ROI_bounds_2D = [] try: ROI_bounds_2D.append(QRectF(self.ROI2D.pos().x(), self.ROI2D.pos().y(), self.ROI2D.size().x(), self.ROI2D.size().y())) except Exception as e: logger.warning(str(e)) ############################################################# # display the correct navigator viewer and set some parameters if len(axes_nav) <= 2: for view in self.nav_axes_viewers: self.ui.nav_axes_widget.layout().removeWidget(view.parent) view.parent.close() self.nav_axes_viewers = [] nav_axes = self.get_selected_axes() if len(nav_axes) == 0: # no Navigator self.ui.navigator1D.parent.setVisible(False) self.ui.navigator2D.parent.setVisible(False) #self.navigator_label.setVisible(False) self.ui.nav_axes_widget.setVisible(False) self.ROI1D.setVisible(False) self.ROI2D.setVisible(False) navigator_data = [] elif len(nav_axes) == 1: # 1D Navigator self.ROI1D.setVisible(True) self.ROI2D.setVisible(True) self.ui.navigator1D.parent.setVisible(True) self.ui.navigator2D.parent.setVisible(False) self.ui.nav_axes_widget.setVisible(False) #self.navigator_label.setVisible(True) self.ui.navigator1D.remove_plots() self.ui.navigator1D.x_axis = nav_axes[0] labels = [] units = [] if self.scan_type.lower() == 'tabular' or self.is_spread: if 'datas' in self.nav_axes_dicts[0]: navigator_data = self.nav_axes_dicts[0]['datas'][:] if 'labels' in self.nav_axes_dicts[0]: labels = self.nav_axes_dicts[0]['labels'][:] if 'all_units' in self.nav_axes_dicts[0]: units = self.nav_axes_dicts[0]['all_units'][:] else: navigator_data = [self.nav_axes_dicts[0]['data']] if self.is_spread: if self.scan_type.lower() == 'tabular': data_spread = [] for ind_label, lab in enumerate(labels): if 'curvilinear' in lab.lower(): data_spread = [self.nav_axes_dicts[0]['datas'][ind]] else: data_spread = self.nav_axes_dicts[0]['datas'][:] data_spread.append(self.get_nav_data(datas_transposed, ROI_bounds_1D, ROI_bounds_2D)[0]) data_spread = np.vstack(data_spread).T else: navigator_data = self.get_nav_data(datas_transposed, ROI_bounds_1D, ROI_bounds_2D) if self.is_spread: self.ui.spread_viewer_2D.parent.setVisible(data_spread.shape[1] == 3) self.ui.spread_viewer_1D.parent.setVisible(data_spread.shape[1] == 2) if data_spread.shape[1] == 3: self.ui.spread_viewer_2D.setImage(data_spread=data_spread) if len(labels) > 1 and len(units) > 1: self.ui.spread_viewer_2D.set_axis_label(dict(orientation='bottom', label=labels[0], units=units[0])) self.ui.spread_viewer_2D.set_axis_label(dict(orientation='left', label=labels[1], units=units[1])) else: ind_sorted = np.argsort(data_spread[:, 0]) self.ui.spread_viewer_1D.show_data([data_spread[:, 1][ind_sorted]], labels=['data'], x_axis=data_spread[:, 0][ind_sorted]) self.ui.spread_viewer_1D.set_axis_label(dict(orientation='bottom', label='Curvilinear value', units='')) if temp_data: self.ui.navigator1D.show_data_temp(navigator_data) self.ui.navigator1D.update_labels(labels) else: self.ui.navigator1D.show_data(navigator_data) self.ui.navigator1D.update_labels(labels) elif len(nav_axes) == 2:#2D Navigator: self.ROI1D.setVisible(True) self.ROI2D.setVisible(True) self.ui.navigator1D.parent.setVisible(False) self.ui.navigator2D.parent.setVisible(True) self.ui.nav_axes_widget.setVisible(False) #self.navigator_label.setVisible(True) self.ui.navigator2D.x_axis = nav_axes[0] self.ui.navigator2D.y_axis = nav_axes[1] navigator_data = self.get_nav_data(datas_transposed, ROI_bounds_1D, ROI_bounds_2D) if temp_data: self.ui.navigator2D.setImageTemp(*navigator_data) else: self.ui.navigator2D.setImage(*navigator_data) else: #more than 2 nv axes, display all nav axes in 1D plots self.ui.navigator1D.parent.setVisible(False) self.ui.navigator2D.parent.setVisible(False) self.ui.nav_axes_widget.setVisible(True) if len(self.nav_axes_viewers) != len(axes_nav): for view in self.nav_axes_viewers: self.ui.nav_axes_widget.layout().removeWidget(view.parent) view.parent.close() widgets = [] self.nav_axes_viewers = [] for ind in range(len(axes_nav)): widgets.append(QtWidgets.QWidget()) self.ui.nav_axes_widget.layout().addWidget(widgets[-1]) self.nav_axes_viewers.append(Viewer1DBasic(widgets[-1], show_line=True)) for ind in range(len(axes_nav)): self.nav_axes_viewers[ind].roi_line_signal.connect(self.update_viewer_data) self.nav_axes_viewers[ind].show_data([nav_axes[ind]['data']]) self.nav_axes_viewers[ind].set_axis_label(dict(orientation='bottom', label=nav_axes[ind]['label'], units=nav_axes[ind]['units'])) self.update_viewer_data() except Exception as e: logger.exception(str(e)) self.update_status(utils.getLineInfo() + str(e), self.wait_time, 'log')
def setupUI(self): self.ui = QObject() self.parent.setLayout(QtWidgets.QVBoxLayout()) splitter_hor = QtWidgets.QSplitter(Qt.Horizontal) self.ui.statusbar = QtWidgets.QStatusBar() self.ui.statusbar.setMaximumHeight(15) self.parent.layout().addWidget(splitter_hor) self.parent.layout().addWidget(self.ui.statusbar) graph_widget = QtWidgets.QWidget() graph_widget.setLayout(QtWidgets.QVBoxLayout()) splitter_hor.addWidget(graph_widget) splitter_hor.addWidget(self.roi_manager.roiwidget) self.roi_manager.roiwidget.hide() self.ui.button_widget = QtWidgets.QWidget() self.ui.button_widget.setLayout(QtWidgets.QHBoxLayout()) self.ui.button_widget.setMaximumHeight(50) splitter_ver = QtWidgets.QSplitter(Qt.Vertical) graph_widget.layout().addWidget(self.ui.button_widget) graph_widget.layout().addWidget(splitter_ver) self.ui.Graph_Lineouts = pg.PlotWidget() widg = QtWidgets.QWidget() self.viewer = Viewer1DBasic(widg) splitter_ver.addWidget(widg) splitter_ver.addWidget(self.ui.Graph_Lineouts) self.ui.Graph1D = self.viewer #for backcompatibility self.roi_manager.viewer_widget = self.viewer.plotwidget self.setup_buttons(self.ui.button_widget) self.setup_zoom() self.legend = None self.axis_settings = dict(orientation='bottom', label='x axis', units='pxls') self.ui.xaxis_item = self.viewer.plotwidget.plotItem.getAxis('bottom') self.ui.Graph_Lineouts.hide() self.ui.aspect_ratio_pb.clicked.connect(self.lock_aspect_ratio) ##crosshair self.ui.crosshair = Crosshair(self.viewer.plotwidget.plotItem, orientation='vertical') self.ui.crosshair.crosshair_dragged.connect(self.update_crosshair_data) self.ui.crosshair_pb.clicked.connect(self.crosshairClicked) self.crosshairClicked() # self.ui.Measurement_widget=Dock("Measurement Module", size=(300, 100), closable=True) # self.dockarea.addDock(self.ui.Measurement_widget) self.ui.Measurement_widget = QtWidgets.QWidget() self.ui.Measurement_widget.setVisible(False) ##Connecting buttons: self.ui.Do_math_pb.clicked.connect(self.do_math_fun) self.ui.do_measurements_pb.clicked.connect( self.open_measurement_module) self.ui.zoom_pb.clicked.connect(self.enable_zoom) self.ui.scatter.clicked.connect(self.do_scatter)
def setupUI(self): self.ui = Ui_Form() self.ui.setupUi(self.parent) widg = QtWidgets.QWidget() self.viewer = Viewer1DBasic(widg) self.ui.verticalLayout.addWidget(widg) self.ui.Graph1D = self.viewer #for backcompatibility self.roi_manager.viewer_widget = self.viewer.plotwidget self.legend = None self.axis_settings = dict(orientation='bottom', label='x axis', units='pxls') # creating the settings widget of the viewer (ROI...) self.ui.splitter_2.replaceWidget(1, self.roi_manager.roiwidget) self.ui.statusbar = QtWidgets.QStatusBar(self.parent) self.ui.statusbar.setMaximumHeight(15) self.ui.StatusBarLayout.addWidget(self.ui.statusbar) # create and set the zoom widget # self.ui.zoom_widget=Dock("1DViewer zoom", size=(300, 100), closable=True) self.ui.zoom_widget = QtWidgets.QWidget() layout = QtWidgets.QHBoxLayout() self.ui.Graph_zoom = pg.PlotWidget() layout.addWidget(self.ui.Graph_zoom) self.ui.zoom_widget.setLayout(layout) self.ui.zoom_region = pg.LinearRegionItem() self.ui.zoom_region.setZValue(-10) self.ui.zoom_region.setBrush('r') self.ui.zoom_region.setOpacity(0.2) self.ui.Graph_zoom.addItem(self.ui.zoom_region) self.zoom_plot = [] # self.dockarea.addDock(self.ui.zoom_widget) self.ui.zoom_widget.setVisible(False) self.ui.xaxis_item = self.viewer.plotwidget.plotItem.getAxis('bottom') self.ui.Graph_Lineouts.hide() self.ui.aspect_ratio_pb.clicked.connect(self.lock_aspect_ratio) ##crosshair self.ui.crosshair = Crosshair(self.viewer.plotwidget.plotItem, orientation='vertical') self.ui.crosshair.crosshair_dragged.connect(self.update_crosshair_data) self.ui.crosshair_pb.clicked.connect(self.crosshairClicked) self.crosshairClicked() # self.ui.Measurement_widget=Dock("Measurement Module", size=(300, 100), closable=True) # self.dockarea.addDock(self.ui.Measurement_widget) self.ui.Measurement_widget = QtWidgets.QWidget() self.ui.Measurement_widget.setVisible(False) ##Connecting buttons: self.ui.Do_math_pb.clicked.connect(self.do_math_fun) self.ui.do_measurements_pb.clicked.connect( self.open_measurement_module) self.ui.zoom_pb.clicked.connect(self.enable_zoom)
def __init__(self, parent=None): QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates)) super(Viewer1D, self).__init__() if parent is None: parent=QtWidgets.QWidget() self.parent=parent self.ui=Ui_Form() self.ui.setupUi(parent) if DAQ_Measurement is None: self.ui.do_measurements_pb.setVisible(False) self.viewer_type='Data1D' self.legend = None #creating the settings widget of the viewer (ROI...) self.ui.settings_layout=QtWidgets.QVBoxLayout() horlayout=QtWidgets.QHBoxLayout() self.ui.load_ROI_pb=QtWidgets.QPushButton('Load') self.ui.save_ROI_pb=QtWidgets.QPushButton('Save') horlayout.addWidget(self.ui.save_ROI_pb) horlayout.addWidget(self.ui.load_ROI_pb) self.ui.settings_layout.addLayout(horlayout) self.ui.ROIs_widget.setLayout(self.ui.settings_layout) self.ui.ROIs_widget.setVisible(False) widg = QtWidgets.QWidget() self.viewer = Viewer1DBasic(widg) self.ui.verticalLayout.addWidget(widg) self.ui.Graph1D = self.viewer #for backcompatibility self.ui.statusbar=QtWidgets.QStatusBar(parent) self.ui.statusbar.setMaximumHeight(15) self.ui.StatusBarLayout.addWidget(self.ui.statusbar) #create and set the zoom widget #self.ui.zoom_widget=Dock("1DViewer zoom", size=(300, 100), closable=True) self.ui.zoom_widget=QtWidgets.QWidget() layout=QtWidgets.QHBoxLayout() self.ui.Graph_zoom=pg.PlotWidget() layout.addWidget(self.ui.Graph_zoom) self.ui.zoom_widget.setLayout(layout) self.ui.zoom_region=pg.LinearRegionItem() self.ui.zoom_region.setZValue(-10) self.ui.zoom_region.setBrush('r') self.ui.zoom_region.setOpacity(0.2) self.ui.Graph_zoom.addItem(self.ui.zoom_region) self.zoom_plot=[] #self.dockarea.addDock(self.ui.zoom_widget) self.ui.zoom_widget.setVisible(False) self.ui.xaxis_item=self.viewer.plotwidget.plotItem.getAxis('bottom') self.ui.Graph_Lineouts.hide() self.wait_time=3000 self.measurement_module=None ##crosshair self.ui.crosshair = Crosshair(self.viewer.plotwidget.plotItem,orientation='vertical') self.ui.crosshair.crosshair_dragged.connect(self.update_crosshair_data) self.ui.crosshair_pb.clicked.connect(self.crosshairClicked) self.crosshairClicked() self._labels = [] self.plot_channels = None self.plot_colors = utils.plot_colors self.color_list = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (14, 207, 189), (207, 14, 166), (207, 204, 14)] self.linear_regions = [] self.lo_items = [] self.lo_data = [] self.ROI_bounds = [] self._x_axis = None self.datas = [] # datas on each channel. list of 1D arrays self.data_to_export = OrderedDict(data0D=OrderedDict(), data1D=OrderedDict(), data2D=None) self.measurement_dict = OrderedDict(x_axis=None, data=None, ROI_bounds=None, operation=None) # OrderedDict to be send to the daq_measurement module self.measure_data_dict = OrderedDict() # dictionnary with data to be put in the table on the form: key="Meas.{}:".format(ind) # and value is the result of a given lineout or measurement # self.ui.Measurement_widget=Dock("Measurement Module", size=(300, 100), closable=True) # self.dockarea.addDock(self.ui.Measurement_widget) self.ui.Measurement_widget = QtWidgets.QWidget() self.ui.Measurement_widget.setVisible(False) # create viewer parameter tree self.ui.settings_tree = ParameterTree() self.ui.settings_layout.addWidget(self.ui.settings_tree) self.ui.settings_tree.setMinimumWidth(250) params = [ {'title': 'Math Settings', 'name': 'math_settings', 'type': 'group', 'children': [ {'title': 'Do math on CH:', 'name': 'channel_combo', 'type': 'list'}, {'title': 'Math type:', 'name': 'math_function', 'type': 'list', 'values': ['Sum', 'Mean', 'half-life', 'expotime'], 'value': 'Sum'}, {'title': 'N Lineouts:', 'name': 'Nlineouts_sb', 'type': 'int', 'value': 0, 'default': 0, 'min': 0}, {'title': 'Spread ROI', 'name': 'spreadROI_pb', 'type': 'action'}, {'title': 'Clear Lineouts', 'name': 'clear_lo_pb', 'type': 'action'} ]}, {'name': 'Measurements', 'type': 'table', 'value': OrderedDict([]), 'Ncol': 2, 'header': ["LO", "Value"]}, {'name': 'ROIs', 'type': 'group'} ] self.roi_settings = Parameter.create(title='Viewer Settings',name='Viewer1D_Settings', type='group', children=params) #connecting from tree self.roi_settings.child('math_settings', 'spreadROI_pb').sigActivated.connect(self.spread_lineouts) self.roi_settings.child('math_settings', 'clear_lo_pb').sigActivated.connect(self.clear_lo) self.ui.settings_tree.setParameters(self.roi_settings, showTop=False) self.roi_settings.sigTreeStateChanged.connect(self.roi_tree_changed) ##Connecting buttons: self.ui.Do_math_pb.clicked.connect(self.do_math_fun) self.ui.do_measurements_pb.clicked.connect(self.open_measurement_module) self.ui.zoom_pb.clicked.connect(self.enable_zoom) self.ui.save_ROI_pb.clicked.connect(self.save_ROI) self.ui.load_ROI_pb.clicked.connect(self.load_ROI)