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 set_file_remote(self, filename, show=True): """ """ children = custom_tree.XML_file_to_parameter(filename) self.remote_params = Parameter.create(title='Shortcuts:', name='shortcuts', type='group', children=children) if show: self.show_remote()
def set_file_overshoot(self, filename, show=True): """ """ children = custom_tree.XML_file_to_parameter(filename) self.overshoot_params = Parameter.create(title='Overshoot', name='Overshoot', type='group', children=children) if show: self.show_overshoot()
def set_file_preset(self, filename, show=True): """ """ self.pid_type = False children = custom_tree.XML_file_to_parameter(filename) self.preset_params = Parameter.create(title='Preset', name='Preset', type='group', children=children) if show: self.show_preset()
def set_file_roi(self, filename, show=True): """ """ children = custom_tree.XML_file_to_parameter(filename) self.roi_presets = Parameter.create(title='roi', name='rois', type='group', children=children) det_children = [ child for child in self.roi_presets.children() if 'det' in child.opts['name'] ] det_names = [ child.child(('detname')).value() for child in self.roi_presets.children() if 'det' in child.opts['name'] ] det_module_names = [det.title for det in self.detector_modules] for ind_det, det_roi in enumerate(det_children): det_module = self.detector_modules[det_module_names.index( det_names[ind_det])] viewer_children = [ child for child in det_roi.children() if 'viewer' in child.opts['name'] ] for ind_viewer, viewer in enumerate(det_module.ui.viewers): rois_params = [ child for child in viewer_children[ind_viewer].children() if 'ROI' in child.opts['name'] ] if hasattr(viewer, 'roi_manager'): # if hasattr(viewer.ui, 'roiBtn'): # viewer.ui.roiBtn.click() # elif hasattr(viewer.ui, 'Do_math_pb'): # viewer.ui.Do_math_pb.click() viewer.roi_manager.load_ROI(params=rois_params) QtWidgets.QApplication.processEvents() if show: self.show_rois()
def load_ROI(self, path=None): try: if path is None: path = select_file(save=False, ext='roi') if path != '': 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([]) params = custom_tree.XML_file_to_parameter(path) self.settings.child(('ROIs')).addChildren(params) except Exception as e: 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 set_PID_preset(self, pid_model): self.pid_type = True filename = os.path.join(get_set_pid_path(), pid_model + '.xml') if os.path.isfile(filename): children = custom_tree.XML_file_to_parameter(filename) self.preset_params = Parameter.create(title='Preset', name='Preset', type='group', children=children) else: model_mod = importlib.import_module('pymodaq_pid_models') model = importlib.import_module('.' + pid_model, model_mod.__name__ + '.models') model_class = getattr(model, pid_model) actuators = model_class.actuators actuators_name = model_class.actuators_name detectors_type = model_class.detectors_type detectors_name = model_class.detectors_name detectors = model_class.detectors param = [ { 'title': 'Filename:', 'name': 'filename', 'type': 'str', 'value': pid_model, 'readonly': True }, ] params_move = [{ 'title': 'Moves:', 'name': 'Moves', 'type': 'groupmove' }] # PresetScalableGroupMove(name="Moves")] params_det = [{ 'title': 'Detectors:', 'name': 'Detectors', 'type': 'groupdet' }] # [PresetScalableGroupDet(name="Detectors")] self.preset_params = Parameter.create(title='Preset', name='Preset', type='group', children=param + params_move + params_det) QtWidgets.QApplication.processEvents() for ind_act, act in enumerate(actuators): self.preset_params.child(('Moves')).addNew(act) self.preset_params.child( 'Moves', 'move{:02.0f}'.format(ind_act), 'name').setValue(actuators_name[ind_act]) QtWidgets.QApplication.processEvents() for ind_det, det in enumerate(detectors): self.preset_params.child( ('Detectors')).addNew(detectors_type[ind_det] + '/' + det) self.preset_params.child( 'Detectors', 'det{:02.0f}'.format(ind_det), 'name').setValue(detectors_name[ind_det]) QtWidgets.QApplication.processEvents() self.show_preset()
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