def mouseMoved(self, event): """ Handles any mouse movements inside the image. @param event: Event that signals the new mouse movement. This should be of type QPointF. Gets the mouse position, converts it to a position scaled to the image axis and than calculates and updated the position to the current POI. """ # converts the absolute mouse position to a position relative to the axis mouse_point = self._mw.roi_map_ViewWidget.getPlotItem().getViewBox( ).mapSceneToView(event.toPoint()) #self.log.debug("Mouse at x = {0:0.2e}, y = {1:0.2e}".format(mouse_point.x(), mouse_point.y())) # only calculate distance, if a POI is selected if self._poi_manager_logic.active_poi is not None: cur_poi_pos = self._poi_manager_logic.get_poi_position( poikey=self._poi_manager_logic.active_poi.get_key()) dx = ScaledFloat(mouse_point.x() - cur_poi_pos[0]) dy = ScaledFloat(mouse_point.y() - cur_poi_pos[1]) d_total = ScaledFloat( np.sqrt((mouse_point.x() - cur_poi_pos[0])**2 + (mouse_point.y() - cur_poi_pos[1])**2)) self._mw.poi_distance_label.setText( '{0:.2r}m ({1:.2r}m, {2:.2r}m)'.format(d_total, dx, dy))
def update_active_poi(self, name): # Deselect current marker for marker in self._markers.values(): if marker.selected: marker.deselect() break # Unselect POI if name is None or empty str self._mw.active_poi_ComboBox.blockSignals(True) if not name: self._mw.active_poi_ComboBox.setCurrentIndex(-1) else: self._mw.active_poi_ComboBox.setCurrentText(name) self._mw.active_poi_ComboBox.blockSignals(False) if name: active_poi_pos = self.poimanagerlogic().get_poi_position(name) else: active_poi_pos = np.zeros(3) self._mw.poi_coords_label.setText( '({0:.2r}m, {1:.2r}m, {2:.2r}m)'.format( ScaledFloat(active_poi_pos[0]), ScaledFloat(active_poi_pos[1]), ScaledFloat(active_poi_pos[2]))) if name in self._markers: self._markers[name].set_radius( self.poimanagerlogic().optimise_xy_size / np.sqrt(2)) self._markers[name].select() return
def mouse_moved_callback(self, event): """ Handles any mouse movements inside the image. @param event: Event that signals the new mouse movement. This should be of type QPointF. Gets the mouse position, converts it to a position scaled to the image axis and than calculates and updated the position to the current POI. """ # converts the absolute mouse position to a position relative to the axis mouse_pos = self.roi_image.getViewBox().mapSceneToView(event[0]) # only calculate distance, if a POI is selected active_poi = self.poimanagerlogic().active_poi if active_poi: poi_pos = self.poimanagerlogic().get_poi_position(active_poi) dx = ScaledFloat(mouse_pos.x() - poi_pos[0]) dy = ScaledFloat(mouse_pos.y() - poi_pos[1]) d_total = ScaledFloat( np.sqrt((mouse_pos.x() - poi_pos[0])**2 + (mouse_pos.y() - poi_pos[1])**2)) self._mw.poi_distance_label.setText( '{0:.2r}m ({1:.2r}m, {2:.2r}m)'.format(d_total, dx, dy)) else: self._mw.poi_distance_label.setText('? (?, ?)') pass
def _update_pois(self, poi_dict): """ Populate the dropdown box for selecting a poi. """ self._mw.active_poi_ComboBox.blockSignals(True) self._mw.active_poi_ComboBox.clear() poi_names = natural_sort(poi_dict) self._mw.active_poi_ComboBox.addItems(poi_names) # Get two list of POI names. One of those to delete and one of those to add old_poi_names = set(self._markers) new_poi_names = set(poi_names) names_to_delete = list(old_poi_names.difference(new_poi_names)) names_to_add = list(new_poi_names.difference(old_poi_names)) # Delete markers accordingly for name in names_to_delete: self._remove_poi_marker(name) # Update positions of all remaining markers size = self.poimanagerlogic().optimise_xy_size * np.sqrt(2) for name, marker in self._markers.items(): marker.setSize((size, size)) marker.set_position(poi_dict[name]) # Add new markers for name in names_to_add: self._add_poi_marker(name=name, position=poi_dict[name]) # If there is no active POI, set the combobox to nothing (-1) active_poi = self.poimanagerlogic().active_poi if active_poi in poi_names: self._mw.active_poi_ComboBox.setCurrentText(active_poi) self._markers[active_poi].select() active_poi_pos = poi_dict[active_poi] self._mw.poi_coords_label.setText( '({0:.2r}m, {1:.2r}m, {2:.2r}m)'.format( ScaledFloat(active_poi_pos[0]), ScaledFloat(active_poi_pos[1]), ScaledFloat(active_poi_pos[2]))) else: self._mw.active_poi_ComboBox.setCurrentIndex(-1) self._mw.active_poi_ComboBox.blockSignals(False) return
def _redraw_poi_markers(self): self.log.debug('starting redraw_poi_markers {0}'.format(time.time())) for key in self._poi_manager_logic.get_all_pois(): if key is not 'crosshair' and key is not 'sample': position = self._poi_manager_logic.get_poi_position(poikey=key) position = position[:2] if key in self._markers.keys(): self._markers[key].set_position(position) self._markers[key].deselect() else: # Create Region of Interest as marker: marker = PoiMark(position, poi=self._poi_manager_logic.poi_list[key], click_action=self.select_poi_from_marker, movable=False, scaleSnap=False, snapSize=1.0e-6) # Add to the Map Widget marker.add_to_viewwidget(self._mw.roi_map_ViewWidget) self._markers[key] = marker if self._poi_manager_logic.active_poi is not None: active_poi_key = self._poi_manager_logic.active_poi.get_key() self._markers[active_poi_key].select() cur_poi_pos = self._poi_manager_logic.get_poi_position( poikey=active_poi_key) self._mw.poi_coords_label.setText( '({0:.2r}m, {1:.2r}m, {2:.2r}m)'.format( ScaledFloat(cur_poi_pos[0]), ScaledFloat(cur_poi_pos[1]), ScaledFloat(cur_poi_pos[2]))) self.log.debug('finished redraw at {0}'.format(time.time()))
def _manage_grating_buttons(self, index): for i in range(3): btn = self._grating_buttons[i] if i == index: btn.setChecked(True) btn.setDown(True) self.spectrumlogic().grating = i else: btn.setChecked(False) btn.setDown(False) self._mw.center_wavelength_current.setText("{:.2r}m".format( ScaledFloat(self.spectrumlogic().center_wavelength))) self._calibration_widget.setValue( self.spectrumlogic().wavelength_calibration)
def _update_settings(self): self._manage_grating_buttons(self.spectrumlogic()._grating) if len(self._input_ports) > 1: input_port_index = 0 if self.spectrumlogic( )._input_port == PortType.INPUT_FRONT else 1 self._manage_port_buttons(input_port_index) self._input_slit_width[input_port_index].setValue( self.spectrumlogic()._input_slit_width[input_port_index]) else: self._input_slit_width[0].setValue( self.spectrumlogic()._input_slit_width[0]) if len(self._output_ports) > 1: output_port_index = 0 if self.spectrumlogic( )._output_port == PortType.OUTPUT_FRONT else 1 self._manage_port_buttons(output_port_index + 2) self._output_slit_width[output_port_index].setValue( self.spectrumlogic()._output_slit_width[output_port_index]) else: self._output_slit_width[0].setValue( self.spectrumlogic()._output_slit_width[0]) self._calibration_widget.setValue( self.spectrumlogic()._wavelength_calibration[ self.spectrumlogic()._grating]) self._settings_tab.camera_gains.setCurrentText( str(int(self.spectrumlogic()._camera_gain))) self._settings_tab.trigger_modes.setCurrentText( self.spectrumlogic()._trigger_mode) self._temperature_widget.setValue( self.spectrumlogic()._temperature_setpoint - 273.15) cooler_on = self.spectrumlogic()._cooler_status if self._settings_tab.cooler_on.isDown() != cooler_on: self._settings_tab.cooler_on.setChecked(cooler_on) self._settings_tab.cooler_on.setDown(cooler_on) self._settings_tab.cooler_on.setText( "ON" if not cooler_on else "OFF") self._mw.cooler_on_label.setText( "Cooler {}".format("ON" if cooler_on else "OFF")) if self.spectrumlogic().camera_constraints.has_shutter: self._settings_tab.shutter_modes.setCurrentText( self.spectrumlogic()._shutter_state) self._mw.center_wavelength_current.setText("{:.2r}m".format( ScaledFloat(self.spectrumlogic()._center_wavelength)))
def set_settings_params(self): if self.spectrumlogic().module_state() == 'locked': return self.spectrumlogic( ).wavelength_calibration = self._calibration_widget.value() self.spectrumlogic( ).camera_gain = self._settings_tab.camera_gains.currentData() self.spectrumlogic( ).trigger_mode = self._settings_tab.trigger_modes.currentData() self.spectrumlogic( ).temperature_setpoint = self._temperature_widget.value() + 273.15 self.spectrumlogic( ).shutter_state = self._settings_tab.shutter_modes.currentText() self._mw.center_wavelength_current.setText("{:.2r}m".format( ScaledFloat(self.spectrumlogic().center_wavelength)))
def _draw_figure(self, data, timebase, y_unit): """ Draw figure to save with data file. @param: nparray data: a numpy array containing counts vs time for all detectors @return: fig fig: a matplotlib figure object to be saved to file. """ # Use qudi style plt.style.use(self._savelogic.mpl_qd_style) # Create figure and scale data max_abs_value = ScaledFloat(max(data.max(), np.abs(data.min()))) time_data = np.arange(data.shape[1]) / timebase fig, ax = plt.subplots() if max_abs_value.scale: ax.plot(time_data, data.transpose() / max_abs_value.scale_val, linestyle=':', linewidth=0.5) else: ax.plot(time_data, data.transpose(), linestyle=':', linewidth=0.5) ax.set_xlabel('Time (s)') ax.set_ylabel('Signal ({0}{1})'.format(max_abs_value.scale, y_unit)) return fig
def _manage_center_wavelength(self): self.spectrumlogic( ).center_wavelength = self._center_wavelength_widget.value() self._mw.center_wavelength_current.setText("{:.2r}m".format( ScaledFloat(self.spectrumlogic().center_wavelength)))
def _activate_spectrum_tab(self): """ Initialization method for the spectrum tab """ for read_mode in self.spectrumlogic().camera_constraints.read_modes: if read_mode.name[:5] != "IMAGE": self._spectrum_tab.read_modes.addItem(str(read_mode.name), read_mode.name) if read_mode == self._spectrum_read_mode: self._spectrum_tab.read_modes.setCurrentText( str(read_mode.name)) for acquisition_mode in AcquisitionMode.__members__: self._spectrum_tab.acquisition_modes.addItem( acquisition_mode, acquisition_mode) if acquisition_mode == self._spectrum_acquisition_mode: self._spectrum_tab.acquisition_modes.setCurrentText( acquisition_mode) self.spectrum_exposure_time_widget = ScienDSpinBox() self.spectrum_exposure_time_widget.setMinimum(0) self.spectrum_exposure_time_widget.setValue( self._spectrum_exposure_time) self.spectrum_exposure_time_widget.setSuffix('s') self._spectrum_tab.exposure_time_layout.addWidget( self.spectrum_exposure_time_widget) for readout_speed in self.spectrumlogic( ).camera_constraints.readout_speeds: self._spectrum_tab.readout_speed.addItem( "{:.2r}Hz".format(ScaledFloat(readout_speed)), readout_speed) if readout_speed == self._spectrum_readout_speed: self._spectrum_tab.readout_speed.setCurrentText( "{:.2r}Hz".format(ScaledFloat(readout_speed))) self._spectrum_scan_delay_widget = ScienDSpinBox() self._spectrum_scan_delay_widget.setMinimum(0) self._spectrum_scan_delay_widget.setValue( self.spectrumlogic().scan_delay) self._spectrum_scan_delay_widget.setSuffix('s') self._spectrum_tab.scan_delay.addWidget( self._spectrum_scan_delay_widget) self._spectrum_tab.scan_number_spin.setValue( self.spectrumlogic().number_of_scan) self._spectrum_tab.save.clicked.connect(partial(self.save_data, 1)) self._save_data_buttons.append(self._spectrum_tab.save) self._spectrum_tab.acquire_dark.clicked.connect( partial(self.start_dark_acquisition, 1)) self._acquire_dark_buttons.append(self._spectrum_tab.acquire_dark) self._spectrum_tab.start_acquisition.clicked.connect( partial(self.start_acquisition, 2)) self._start_acquisition_buttons.append( self._spectrum_tab.start_acquisition) self._spectrum_tab.stop_acquisition.clicked.connect( self.stop_acquisition) self._stop_acquisition_buttons.append( self._spectrum_tab.stop_acquisition) self._spectrum_tab.remove_dark.clicked.connect( partial(self.remove_dark, 1)) self._spectrum_tab.graph.setLabel('left', 'Photoluminescence', units='counts/s') self._spectrum_tab.graph.setLabel('bottom', 'wavelength', units='m') self._spectrum_tab.read_modes.currentTextChanged.connect( self.set_spectrum_params) self._spectrum_tab.acquisition_modes.currentTextChanged.connect( self.set_spectrum_params) self.spectrum_exposure_time_widget.editingFinished.connect( self.set_spectrum_params) self._spectrum_tab.read_modes.currentTextChanged.connect( self.set_spectrum_params) self._spectrum_scan_delay_widget.editingFinished.connect( self.set_spectrum_params) self._spectrum_tab.scan_number_spin.editingFinished.connect( self.set_spectrum_params)
def _activate_image_tab(self): """ Initialization method for the image tab """ camera_width = self.spectrumlogic().camera_constraints.width camera_height = self.spectrumlogic().camera_constraints.height for read_mode in self.spectrumlogic().camera_constraints.read_modes: if read_mode.name[:5] == "IMAGE": self._image_tab.read_modes.addItem(read_mode.name, read_mode.name) if read_mode == self._image_read_mode: self._image_tab.read_modes.setCurrentText(read_mode.name) for acquisition_mode in AcquisitionMode.__members__: if acquisition_mode != "MULTI_SCAN": self._image_tab.acquisition_modes.addItem( acquisition_mode, acquisition_mode) if acquisition_mode == self._image_acquisition_mode: self._image_tab.acquisition_modes.setCurrentText( acquisition_mode) self.image_exposure_time_widget = ScienDSpinBox() self.image_exposure_time_widget.setMinimum(0) self.image_exposure_time_widget.setValue(self._image_exposure_time) self.image_exposure_time_widget.setSuffix('s') self._image_tab.exposure_time_layout.addWidget( self.image_exposure_time_widget) for readout_speed in self.spectrumlogic( ).camera_constraints.readout_speeds: self._image_tab.readout_speed.addItem( "{:.2r}Hz".format(ScaledFloat(readout_speed)), readout_speed) if readout_speed == self._image_readout_speed: self._image_tab.readout_speed.setCurrentText("{:.2r}Hz".format( ScaledFloat(readout_speed))) self._image_tab.save.clicked.connect(partial(self.save_data, 0)) self._save_data_buttons.append(self._image_tab.save) self._image_tab.acquire_dark.clicked.connect( partial(self.start_dark_acquisition, 0)) self._acquire_dark_buttons.append(self._image_tab.acquire_dark) self._image_tab.start_acquisition.clicked.connect( partial(self.start_acquisition, 0)) self._start_acquisition_buttons.append( self._image_tab.start_acquisition) self._image_tab.stop_acquisition.clicked.connect(self.stop_acquisition) self._stop_acquisition_buttons.append(self._image_tab.stop_acquisition) self._image_tab.remove_dark.clicked.connect( partial(self.remove_dark, 0)) self.my_colors = ColorScaleInferno() self._image = pg.ImageItem(image=self._image_data, axisOrder='row-major') self._image.setLookupTable(self.my_colors.lut) self._image_tab.graph.addItem(self._image) self._colorbar = ColorbarWidget(self._image) self._image_tab.colorbar.addWidget(self._colorbar) self.track_colors = np.array( [palette.c5, palette.c2, palette.c6, palette.c4]) self.plot_colors = self.track_colors height = self.spectrumlogic().camera_constraints.height for i in range(4): self._track_buttons[i].setCheckable(True) self._track_buttons[i].clicked.connect( partial(self._manage_track_buttons, i)) tracks = self.spectrumlogic().active_tracks if 2 * i < len(tracks): top_pos = tracks[2 * i] bottom_pos = tracks[2 * i + 1] else: top_pos = 0 bottom_pos = 10 color = self.track_colors[i].getRgb() track_color = pg.mkBrush(color[0], color[1], color[2], 100) track = pg.LinearRegionItem( values=[top_pos, bottom_pos], orientation=pg.LinearRegionItem.Horizontal, brush=track_color) track.setBounds([0, height]) track.hide() self._track_selector.append(track) self._image_tab.graph.addItem(track) self._image_tab.image_advanced.setCheckable(True) self._image_tab.image_advanced.clicked.connect( self._manage_image_advanced_button) self._image_advanced_widget = pg.ROI( [0, 0], [camera_width, camera_height], maxBounds=QRectF(QPoint(0, 0), QPoint(camera_width, camera_height))) self._image_advanced_widget.addScaleHandle((1, 0), (0, 1)) self._image_advanced_widget.addScaleHandle((0, 1), (1, 0)) self._image_advanced_widget.hide() self._image_tab.graph.addItem(self._image_advanced_widget) self._image_tab.horizontal_binning.setRange(1, camera_width - 1) self._image_tab.vertical_binning.setRange(1, camera_height - 1) self._image_tab.horizontal_binning.editingFinished.connect( self.set_image_params) self._image_tab.vertical_binning.editingFinished.connect( self.set_image_params) self._image_tab.read_modes.currentTextChanged.connect( self.set_image_params) self._image_tab.acquisition_modes.currentTextChanged.connect( self.set_image_params) self.image_exposure_time_widget.editingFinished.connect( self.set_image_params) self._image_tab.readout_speed.currentTextChanged.connect( self.set_image_params)
def _activate_settings_tab(self): """ Initialization method for the setting tab """ spectro_constraints = self.spectrumlogic().spectro_constraints self._grating_buttons = [ self._settings_tab.grating_1, self._settings_tab.grating_2, self._settings_tab.grating_3 ] self._input_port_buttons = [ self._settings_tab.input_front, self._settings_tab.input_side ] self._input_slit_width = [] self._output_port_buttons = [ self._settings_tab.output_front, self._settings_tab.output_side ] self._output_slit_width = [] for i in range(3): self._grating_buttons[i].setText('{}rpm'.format( round( self.spectrumlogic().spectro_constraints.gratings[i].ruling / 1000))) self._grating_buttons[i].setCheckable(True) self._grating_buttons[i].clicked.connect( partial(self._manage_grating_buttons, i)) if i == self.spectrumlogic().grating: self._grating_buttons[i].setDown(True) self._input_ports = [ port for port in spectro_constraints.ports if port.type in [PortType.INPUT_FRONT, PortType.INPUT_SIDE] ] self._output_ports = [ port for port in spectro_constraints.ports if port.type in [PortType.OUTPUT_FRONT, PortType.OUTPUT_SIDE] ] for i in range(2): if i < len(self._input_ports): self._input_port_buttons[i].setText( self._input_ports[i].type.name[6:].lower()) self._input_port_buttons[i].setCheckable(True) if self._input_ports[i].type.name == self.spectrumlogic( ).input_port: self._input_port_buttons[i].setDown(True) input_widget = ScienDSpinBox() input_widget.setRange(self._input_ports[i].constraints.min, self._input_ports[i].constraints.max) input_widget.setValue( self.spectrumlogic().get_input_slit_width( self._input_ports[i].type.name)) input_widget.setSuffix('m') input_widget.editingFinished.connect( partial(self._manage_slit_width, i)) self._input_slit_width.append(input_widget) self._settings_tab.input_layout.addWidget(input_widget, i, 2) if len(self._input_ports) > 1: self._input_port_buttons[i].clicked.connect( partial(self._manage_port_buttons, i)) else: self._input_port_buttons[i].setEnabled(False) if i < len(self._output_ports): self._output_port_buttons[i].setText( self._output_ports[i].type.name[7:].lower()) self._output_port_buttons[i].setCheckable(True) if self._output_ports[i].type.name == self.spectrumlogic( ).output_port: self._output_port_buttons[i].setDown(True) output_widget = ScienDSpinBox() output_widget.setRange(self._output_ports[i].constraints.min, self._output_ports[i].constraints.max) output_widget.setValue( self.spectrumlogic().get_output_slit_width( self._output_ports[i].type.name)) output_widget.setSuffix('m') output_widget.editingFinished.connect( partial(self._manage_slit_width, i + 2)) self._output_slit_width.append(output_widget) self._settings_tab.output_layout.addWidget(output_widget, i, 2) if len(self._output_ports) > 1: self._output_port_buttons[i].clicked.connect( partial(self._manage_port_buttons, i + 2)) else: self._output_port_buttons[i].setEnabled(False) self._calibration_widget = ScienDSpinBox() self._calibration_widget.setValue( self.spectrumlogic().wavelength_calibration) self._calibration_widget.setSuffix('m') self._settings_tab.calibration_layout.addWidget( self._calibration_widget) for gain in self.spectrumlogic().camera_constraints.internal_gains: self._settings_tab.camera_gains.addItem(str(gain), gain) if gain == self.spectrumlogic().camera_gain: self._settings_tab.camera_gains.setCurrentText(str(gain)) for trigger_mode in self.spectrumlogic( ).camera_constraints.trigger_modes: self._settings_tab.trigger_modes.addItem(trigger_mode, trigger_mode) if trigger_mode == self.spectrumlogic().trigger_mode: self._settings_tab.trigger_modes.setCurrentText(trigger_mode) self._temperature_widget = ScienDSpinBox() self._temperature_widget.setRange(-273.15, 500) self._temperature_widget.setValue( self.spectrumlogic().temperature_setpoint - 273.15) self._temperature_widget.setSuffix('°C') self._settings_tab.camera_cooler_layout.addWidget( self._temperature_widget) self._settings_tab.cooler_on.clicked.connect( self._manage_cooler_button) if self.spectrumlogic().cooler_status: self._settings_tab.cooler_on.setDown(True) self._settings_tab.cooler_on.setText("OFF") self._mw.cooler_on_label.setText("Cooler ON") else: self._settings_tab.cooler_on.setText("ON") self._mw.cooler_on_label.setText("Cooler OFF") self._mw.camera_temperature.setText("{}°C".format( round(self.spectrumlogic().camera_temperature - 273.15, 2))) self._center_wavelength_widget = ScienDSpinBox() self._center_wavelength_widget.setMinimum(0) self._center_wavelength_widget.setValue( self.spectrumlogic().center_wavelength) self._center_wavelength_widget.setSuffix("m") self._mw.center_wavelength.addWidget(self._center_wavelength_widget, 1) self._mw.go_to_wavelength.clicked.connect( self._manage_center_wavelength) self._mw.center_wavelength_current.setText("{:.2r}m".format( ScaledFloat(self.spectrumlogic().center_wavelength))) self._calibration_widget.editingFinished.connect( self.set_settings_params) self._settings_tab.camera_gains.currentTextChanged.connect( self.set_settings_params) self._settings_tab.trigger_modes.currentTextChanged.connect( self.set_settings_params) self._temperature_widget.editingFinished.connect( self.set_settings_params) if not self.spectrumlogic().camera_constraints.has_shutter: self._settings_tab.shutter_modes.setEnabled(False) else: self._settings_tab.shutter_modes.setCurrentText( self.spectrumlogic().shutter_state) self._settings_tab.shutter_modes.currentTextChanged.connect( self.set_settings_params) self._update_temperature_timer = QtCore.QTimer() self._update_temperature_timer.timeout.connect( self._update_temperature) self._update_temperature_timer.start(1000) self.spectrumlogic().sigUpdateSettings.connect(self._update_settings)