def __init__(self, actuators=[], detectors=[], msgbox=False): super().__init__() self.actuators = actuators self.detectors = detectors if msgbox: msgBox = QtWidgets.QMessageBox() msgBox.setText("Preset Manager?") msgBox.setInformativeText("What do you want to do?") cancel_button = msgBox.addButton(QtWidgets.QMessageBox.Cancel) new_button = msgBox.addButton("New", QtWidgets.QMessageBox.ActionRole) modify_button = msgBox.addButton('Modify', QtWidgets.QMessageBox.AcceptRole) msgBox.setDefaultButton(QtWidgets.QMessageBox.Cancel) ret = msgBox.exec() if msgBox.clickedButton() == new_button: self.set_new_remote() elif msgBox.clickedButton() == modify_button: path = select_file(start_path=remote_path, save=False, ext='xml') if path != '': self.set_file_remote(str(path)) else: # cancel pass params = [{'title': 'Activate all', 'name': 'activate_all', 'type': 'action'}, {'title': 'Deactivate all', 'name': 'deactivate_all', 'type': 'action'}, {'title:': 'Actions', 'name': 'action_group', 'type': 'group'}] self.remote_actions = dict(shortcuts=dict([]), joysticks=dict([])) self.remote_settings = Parameter.create(title='Remote Settings', name='remote', type='group', children=params) self.remote_settings.sigTreeStateChanged.connect(self.remote_settings_changed) self.remote_settings_tree = ParameterTree() self.remote_settings_tree.setParameters(self.remote_settings, showTop=False) self.remote_settings.child(('activate_all')).sigActivated.connect(lambda: self.activate_all(True)) self.remote_settings.child(('deactivate_all')).sigActivated.connect(lambda: self.activate_all(False))
def load_ROI(self, path=None, params=None): try: if params is None: if path is None: path = select_file(save=False, ext='xml') if path != '': params = Parameter.create( title='Settings', name='settings', type='group', children=custom_tree.XML_file_to_parameter(path)) if params is not None: self.clear_ROI() QtWidgets.QApplication.processEvents() for param in params: if 'roi_type' in custom_tree.iter_children(param, []): self.settings.child(('ROIs')).addNew( param.child(('roi_type')).value()) else: self.settings.child(('ROIs')).addNew() #self.settings.child(('ROIs')).addChildren(params) QtWidgets.QApplication.processEvents() # settings = Parameter.create(title='Settings', name='settings', type='group') # # for param in params: # settings.addChildren(custom_tree.XML_string_to_parameter(custom_tree.parameter_to_xml_string(param))) self.set_roi(self.settings.child(('ROIs')).children(), params) except Exception as e: pass
def __init__(self, msgbox=False, det_modules=[], actuators_modules=[]): self.overshoot_params = None self.det_modules = det_modules self.actuators_modules = actuators_modules if msgbox: msgBox = QtWidgets.QMessageBox() msgBox.setText("Overshoot Manager?") msgBox.setInformativeText("What do you want to do?") cancel_button = msgBox.addButton(QtWidgets.QMessageBox.Cancel) new_button = msgBox.addButton("New", QtWidgets.QMessageBox.ActionRole) modify_button = msgBox.addButton('Modify', QtWidgets.QMessageBox.AcceptRole) msgBox.setDefaultButton(QtWidgets.QMessageBox.Cancel) ret = msgBox.exec() if msgBox.clickedButton() == new_button: self.set_new_overshoot() elif msgBox.clickedButton() == modify_button: path = select_file(start_path=overshoot_path, save=False, ext='xml') if path != '': self.set_file_overshoot(str(path)) else: # cancel pass
def load_data(self): self.h5module_path = str( gutils.select_file(start_path=None, save=False, ext='h5')) if self.h5module_path != '': self.settings.child('settings', 'filepath').setValue(self.h5module_path) if self.h5module is not None: if self.h5module.isopen(): self.h5module.close_file() self.h5module.open_file(self.h5module_path, 'a') self.list_2Dscans()
def save_ROI(self): try: data = ioxml.parameter_to_xml_string(self.settings.child(('ROIs'))) path = select_file(start_path=Path.home(), ext='xml') if path != '': with open(path, 'wb') as f: f.write(data) except Exception as e: print(e)
def save_ROI(self): try: data = custom_tree.parameter_to_xml_string( self.settings.child(('ROIs'))) path = select_file(ext='xml') if path != '': with open(path, 'wb') as f: f.write(data) except Exception as e: print(e)
def load_layout_state(self, file=None): """ Load and restore a layout state from the select_file obtained pathname file. See Also -------- utils.select_file """ try: if file is None: file = select_file(save=False, ext='dock') if file is not None: with open(str(file), 'rb') as f: dockstate = pickle.load(f) self.dockarea.restoreState(dockstate) file = file.name self.settings.child('loaded_files', 'layout_file').setValue(file) except Exception as e: logger.exception(str(e))
def save_data(self): try: path = gutils.select_file(start_path=self.settings.child( 'main_settings', 'base_path').value(), save=True, ext='h5') if path is not None: # init the file object with an addhoc name given by the user h5saver = H5Saver(save_type='custom') h5saver.init_file(update_h5=True, addhoc_file_path=path) # save all metadata settings_str = ioxml.parameter_to_xml_string(self.settings) settings_str = b'<All_settings>' + settings_str settings_str += ioxml.parameter_to_xml_string( self.detector.settings) + ioxml.parameter_to_xml_string( h5saver.settings) + b'</All_settings>' data_group = h5saver.add_data_group( h5saver.raw_group, group_data_type='data0D', title='data from custom app', settings_as_xml=settings_str) for dat in self.raw_data: channel = h5saver.add_CH_group(data_group) data_dict = dict(data=np.array(dat), x_axis=dict(data=np.linspace( 0, len(dat) - 1, len(dat)), units='pxl')) h5saver.add_data(channel, data_dict=data_dict, scan_type='') st = 'file {:s} has been saved'.format(str(path)) self.add_log(st) self.settings.child('main_settings', 'info').setValue(st) h5saver.close_file() except Exception as e: self.add_log(getLineInfo() + str(e))
def save_layout_state(self, file=None): """ Save the current layout state in the select_file obtained pathname file. Once done dump the pickle. See Also -------- utils.select_file """ try: dockstate = self.dockarea.saveState() if 'float' in dockstate: dockstate['float'] = [] if file is None: file = select_file(start_path=None, save=True, ext='dock') if file is not None: with open(str(file), 'wb') as f: pickle.dump(dockstate, f, pickle.HIGHEST_PROTOCOL) except Exception as e: logger.exception(str(e))
def load_h5_file(self,path=None): """ | Load the specific h5 file calling the open_h5_file procedure ================ ============ ======================================= **Parameters** **Type** **Description** *path* string the current path to the file to load ================ ============ ======================================= See Also -------- open_h5_file, update_status, daq_utils.select_file """ try: filename = gutils.select_file(start_path=path, save=False,ext='h5') if filename is not "": self.open_h5_file(filename) except Exception as e: self.update_status(str(e),wait_time=self.wait_time)
def __init__(self, msgbox=False, det_modules=[]): self.roi_presets = None self.detector_modules = det_modules if msgbox: msgBox = QtWidgets.QMessageBox() msgBox.setText("Overshoot Manager?") msgBox.setInformativeText("What do you want to do?") cancel_button = msgBox.addButton(QtWidgets.QMessageBox.Cancel) modify_button = msgBox.addButton('Modify', QtWidgets.QMessageBox.AcceptRole) msgBox.setDefaultButton(QtWidgets.QMessageBox.Cancel) ret = msgBox.exec() if msgBox.clickedButton() == modify_button: path = select_file(start_path=roi_path, save=False, ext='xml') if path != '': self.set_file_roi(str(path)) else: # cancel pass
def __init__(self, msgbox=False, path=None, extra_params=[], param_options=[]): if path is None: path = preset_path else: assert isinstance(path, Path) self.extra_params = extra_params self.param_options = param_options self.preset_path = path self.preset_params = None self.pid_type = False if msgbox: msgBox = QtWidgets.QMessageBox() msgBox.setText("Preset Manager?") msgBox.setInformativeText("What do you want to do?") cancel_button = msgBox.addButton(QtWidgets.QMessageBox.Cancel) new_button = msgBox.addButton("New", QtWidgets.QMessageBox.ActionRole) modify_button = msgBox.addButton('Modify', QtWidgets.QMessageBox.AcceptRole) msgBox.setDefaultButton(QtWidgets.QMessageBox.Cancel) ret = msgBox.exec() if msgBox.clickedButton() == new_button: self.set_new_preset() elif msgBox.clickedButton() == modify_button: path = gui_utils.select_file(start_path=self.preset_path, save=False, ext='xml') if path != '': self.set_file_preset(str(path)) else: # cancel pass
def load_ROI(self, path=None, params=None): try: if params is None: if path is None: path = select_file(save=False, ext='xml') if path != '': params = custom_tree.XML_file_to_parameter(path) if params is not None: for roi in self.ROIs.values(): index = roi.index self.viewer_widget.plotitem.removeItem(roi) # self.settings.sigTreeStateChanged.disconnect() self.settings.child(*('ROIs', 'ROI_%02.0d' % index)).remove() # self.settings.sigTreeStateChanged.connect(self.roi_tree_changed) self.ROIs = OrderedDict([]) for param in params: if 'roi_type' in custom_tree.iter_children(param, []): self.settings.child(('ROIs')).addNew( param.child(('roi_type')).value()) else: self.settings.child(('ROIs')).addNew() #self.settings.child(('ROIs')).addChildren(params) QtWidgets.QApplication.processEvents() # settings = Parameter.create(title='Settings', name='settings', type='group') # # for param in params: # settings.addChildren(custom_tree.XML_string_to_parameter(custom_tree.parameter_to_xml_string(param))) self.set_roi(self.settings.child(('ROIs')).children(), params) except Exception as e: pass
def parameter_tree_changed(self, param, changes): for param, change, data in changes: path = self.settings.childPath(param) if path is not None: childName = '.'.join(path) else: childName = param.name() if change == 'childAdded': pass elif change == 'value': if param.name() == 'show_det': self.show_detector(data) elif param.name() == 'spectro_center_freq': unit = self.settings.child('acq_settings', 'units').value() if unit == 'nm': center_wavelength = data elif unit == 'cm-1': center_wavelength = Ecmrel2Enm( data, self.settings.child('config_settings', 'laser_wl').value()) elif unit == 'eV': center_wavelength = eV2nm(data) if int(self.spectro_wl * 100) != int( 100 * center_wavelength): #comprison at 1e-2 self.spectro_wl = center_wavelength self.update_axis() elif param.name() == 'units': if self.settings.child( 'acq_settings', 'spectro_center_freq').value() > 0.000000001: if data == 'nm': self.settings.child( 'acq_settings', 'spectro_center_freq').setValue( self._spectro_wl) elif data == 'cm-1': self.settings.child( 'acq_settings', 'spectro_center_freq').setValue( Enm2cmrel( self._spectro_wl, self.settings.child( 'config_settings', 'laser_wl').value())) elif data == 'eV': self.settings.child( 'acq_settings', 'spectro_center_freq').setValue( nm2eV(self._spectro_wl)) self.set_status_center( self.settings.child('acq_settings', 'spectro_center_freq').value(), self.settings.child('acq_settings', 'units').value()) elif param.name() == 'laser_wl_list': if data is not None: self.move_laser_wavelength(data) elif param.name() == 'laser_wl': if data is not None: self.move_laser_wavelength(data) if int(data) == 0: self.settings.child('acq_settings', 'units').setValue('nm') self.settings.child('acq_settings', 'units').setOpts(readonly=True) else: self.settings.child( 'acq_settings', 'units').setOpts(readonly=False) if data != 0: self.set_manual_laser_wl(data) elif param.name() == 'exposure_ms': self.set_exposure_ms(data) elif param.name() == 'do_calib': if len(self.raw_data) != 0: if data: self.calib_dock = Dock('Calibration module') self.dockarea.addDock(self.calib_dock) self.calibration = Calibration(self.dockarea) self.calib_dock.addWidget(self.calibration) self.calibration.coeffs_calib.connect( self.update_calibration) else: self.calib_dock.close() elif param.name() == 'save_calib': filename = select_file(start_path=self.save_file_pathname, save=True, ext='xml') if filename != '': custom_tree.parameter_to_xml_file( self.settings.child('calib_settings', 'calib_coeffs'), filename) elif param.name() == 'load_calib': filename = select_file(start_path=self.save_file_pathname, save=False, ext='xml') if filename != '': children = custom_tree.XML_file_to_parameter(filename) self.settings.child( 'calib_settings', 'calib_coeffs').restoreState( Parameter.create( title='Calibration coeffs:', name='calib_coeffs', type='group', children=children).saveState()) elif param.name() in custom_tree.iter_children(self.settings.child('calib_settings', 'calib_coeffs')) \ or param.name() == 'use_calib': if self.settings.child('calib_settings', 'use_calib').value(): calib_coeffs = [ self.settings.child('calib_settings', 'calib_coeffs', 'third_calib').value(), self.settings.child('calib_settings', 'calib_coeffs', 'second_calib').value(), self.settings.child('calib_settings', 'calib_coeffs', 'slope_calib').value(), self.settings.child('calib_settings', 'calib_coeffs', 'center_calib').value() ] self.update_center_frequency( self.settings.child('calib_settings', 'calib_coeffs', 'center_calib').value()) self.settings.child('acq_settings', 'spectro_center_freq').show() self.settings.child( 'acq_settings', 'spectro_center_freq').setOpts(readonly=True) self.status_center.setStyleSheet( "background-color: green") self.settings.child('acq_settings', 'spectro_center_freq_txt').hide() x_axis_pxls = np.linspace(0, self.raw_data[0].size - 1, self.raw_data[0].size) self.viewer_freq_axis['data'] = np.polyval( calib_coeffs, x_axis_pxls - np.max(x_axis_pxls) / 2) self.update_axis() else: self.settings.child('acq_settings', 'spectro_center_freq').hide() self.settings.child('acq_settings', 'spectro_center_freq_txt').show() self.status_center.setStyleSheet( "background-color: red") elif change == 'parent': pass
def ini_detector(self, controller=None): """ Initialisation procedure of the detector initializing the status dictionnary. See Also -------- daq_utils.ThreadCommand, get_xaxis, get_yaxis """ self.status.update( edict(initialized=False, info="", x_axis=None, y_axis=None, controller=None)) try: if self.settings.child(('controller_status')).value() == "Slave": if controller is None: raise Exception( 'no controller has been defined externally while this detector is a slave one' ) else: self.controller = controller else: if cti_paths == []: file = select_file(start_path=r'C:\Program Files', save=False, ext='cti') if file != '': cti_paths.append(str(file)) for path in cti_paths: self.harv.add_cti_file(path) self.harv.update_device_info_list() devices = self.harv.device_info_list devices_names = [device.model for device in devices] #device = QtWidgets.QInputDialog.getItem(None, 'Pick an item', 'List of discovered cameras:', devices_names, editable = False) self.settings.child(('cam_name')).setLimits(devices_names) self.settings.child( ('cam_name')).setValue(devices_names[0]) QtWidgets.QApplication.processEvents() self.controller = self.harv.create_image_acquirer( model=self.settings.child(('cam_name')).value()) self.controller.num_buffers = 2 self.controller.device.node_map.get_node('OffsetX').value = 0 self.controller.device.node_map.get_node('OffsetY').value = 0 self.controller.device.node_map.get_node( 'Width').value = self.controller.device.node_map.get_node( 'Width').max self.controller.device.node_map.get_node( 'Height').value = self.controller.device.node_map.get_node( 'Height').max self.get_features() self.controller.on_new_buffer_arrival = self.emit_data self.x_axis = self.get_xaxis() self.y_axis = self.get_yaxis() self.width_max = self.controller.device.node_map.get_node( 'Width').max self.width = self.controller.device.node_map.get_node( 'Width').value self.height_max = self.controller.device.node_map.get_node( 'Height').max self.height = self.controller.device.node_map.get_node( 'Height').value self.data = np.zeros((self.height, self.width)) # initialize viewers with the future type of data self.data_grabed_signal_temp.emit([ DataFromPlugins(name='GenICam', data=[self.data], dim='Data2D'), ]) self.status.x_axis = self.x_axis self.status.y_axis = self.y_axis self.status.initialized = True self.status.controller = self.controller return self.status except Exception as e: self.emit_status( ThreadCommand('Update_Status', [getLineInfo() + str(e), 'log'])) self.status.info = getLineInfo() + str(e) self.status.initialized = False return self.status
def move_Abs(self, position): """ Make the absolute move from the given position after thread command signal was received in DAQ_Move_main. =============== ========= ======================= **Parameters** **Type** **Description** *position* float The absolute position =============== ========= ======================= See Also -------- DAQ_Move_base.set_position_with_scaling, DAQ_Move_base.poll_moving """ try: position = self.check_bound(position) #position=self.set_position_with_scaling(position) #print(position) self.target_position = position if self.settings.child(('shaping_type')).value() == 'FullScreen': self.controller.showBlankscreen(grayValue=position) elif self.settings.child( ('shaping_type')).value() == 'SplitScreen': if self.settings.child('splitting', 'split_control').value( ) == 'Screen spliting': #,'GreyA','GreyB'] screenDivider = position else: screenDivider = self.settings.child( 'splitting', 'split_value').value() if self.settings.child('splitting', 'split_control').value() == 'GreyA': a_gray_value = int(position) else: a_gray_value = self.settings.child('splitting', 'greyA_value').value() if self.settings.child('splitting', 'split_control').value() == 'GreyB': b_gray_value = int(position) else: b_gray_value = self.settings.child('splitting', 'greyB_value').value() flipped = self.settings.child('splitting', 'split_flip').value() if self.settings.child('splitting', 'split_dir').value() == 'Vertical': self.controller.showDividedScreenVertical( a_gray_value, b_gray_value, screenDivider, flipped) else: self.controller.showDividedScreenHorizontal( a_gray_value, b_gray_value, screenDivider, flipped) elif self.settings.child(('shaping_type')).value() == 'File': fname = str(select_file(start_path=None, save=False, ext='h5')) data = h5browser.browse_data(fname) if self.settings.child('calibration', 'calib_apply').value( ) and self.calibration is not None: data = np.reshape( np.interp(data.reshape(np.prod(data.shape)), self.calibration, np.linspace(0, 255, 256)).astype('uint8'), data.shape) dataWidth = self.controller.width_px dataHeight = self.controller.height_px # Calculate the data: for indy in range(dataHeight): for indx in range(dataWidth): self.data_uchar[indy, indx] = data[indy, indx] if data is None: raise Exception('No data has been selected') else: self.controller.showData(self.data_uchar) self.current_position = position #+np.random.rand()-0.5 self.poll_moving() except Exception as e: self.emit_status( ThreadCommand('Update_Status', [getLineInfo() + str(e), 'log']))
def save_data(self, export=False): try: if export: ext = 'dat' else: ext = 'h5' path = select_file(start_path=self.save_file_pathname, save=True, ext=ext) if not (not (path)): if not export: h5saver = H5Saver(save_type='detector') h5saver.init_file(update_h5=True, custom_naming=False, addhoc_file_path=path) settings_str = b'<All_settings>' + custom_tree.parameter_to_xml_string( self.settings) if self.detector is not None: settings_str += custom_tree.parameter_to_xml_string( self.detector.settings) if hasattr(self.detector.ui.viewers[0], 'roi_manager'): settings_str += custom_tree.parameter_to_xml_string( self.detector.ui.viewers[0].roi_manager. settings) settings_str += custom_tree.parameter_to_xml_string( h5saver.settings) settings_str += b'</All_settings>' det_group = h5saver.add_det_group(h5saver.raw_group, "Data", settings_str) try: self.channel_arrays = OrderedDict([]) data_dim = 'data1D' if not h5saver.is_node_in_group(det_group, data_dim): self.channel_arrays['data1D'] = OrderedDict([]) data_group = h5saver.add_data_group( det_group, data_dim) for ind_channel, data in enumerate( self.raw_data): # list of numpy arrays channel = f'CH{ind_channel:03d}' channel_group = h5saver.add_CH_group( data_group, title=channel) self.channel_arrays[data_dim][ 'parent'] = channel_group self.channel_arrays[data_dim][ channel] = h5saver.add_data( channel_group, dict(data=data, x_axis=self.viewer_freq_axis), scan_type='', enlargeable=False) h5saver.close_file() except Exception as e: logger.exception(str(e)) else: data_to_save = [self.viewer_freq_axis['data']] data_to_save.extend([dat for dat in self.raw_data]) np.savetxt(path, data_to_save, delimiter='\t') except Exception as e: logger.exception(str(e))