Beispiel #1
0
    def populate_widget(self, tree_view_item, data_collection):
        self._tree_view_item = tree_view_item
        self._data_collection = data_collection

        # if isinstance(tree_view_item, queue_item.XrayCenteringQueueItem):
        #    self._data_collection = tree_view_item.get_model().reference_image_collection
        # else:
        #    self._data_collection = tree_view_item.get_model()
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)

        self._acquisition_mib = DataModelInputBinder(
            self._data_collection.acquisitions[0].acquisition_parameters)

        # The acq_widget sends a signal to the path_widget, and it relies
        # on that both models upto date, we need to refactor this part
        # so that both models are set before taking ceratin actions.
        # This workaround, works for the time beeing.
        self._data_path_widget.update_data_model(
            self._data_collection.acquisitions[0].path_template)

        self._acq_widget.update_data_model(
            self._data_collection.acquisitions[0].acquisition_parameters,
            self._data_collection.acquisitions[0].path_template,
        )
        # self._acq_widget.use_osc_start(False)

        self._acq_widget.acq_widget_layout.num_images_ledit.setDisabled(
            data_collection.is_mesh())
        invalid = self._acquisition_mib.validate_all()
        if invalid:
            msg = (
                "This data collection has one or more incorrect parameters," +
                " correct the fields marked in red to solve the problem.")
            logging.getLogger("GUI").warning(msg)
Beispiel #2
0
    def __init__(self, parent=None, name=None, fl=0, data_model=None):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        if data_model is None:
            self._model = queue_model_objects.ProcessingParameters()
        else:
            self._model = data_model

        self._model_mib = DataModelInputBinder(self._model)

        self.processing_widget = qt_import.load_ui_file(
            "processing_widget_vertical_layout.ui")

        self.main_layout = qt_import.QVBoxLayout(self)
        self.main_layout.addWidget(self.processing_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)

        self.processing_widget.space_group_combo.addItems(
            queue_model_enumerables.XTAL_SPACEGROUPS)

        self._model_mib.bind_value_update("cell_a",
                                          self.processing_widget.a_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_alpha",
                                          self.processing_widget.alpha_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_b",
                                          self.processing_widget.b_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_beta",
                                          self.processing_widget.beta_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_c",
                                          self.processing_widget.c_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_gamma",
                                          self.processing_widget.gamma_ledit,
                                          float, None)

        self._model_mib.bind_value_update(
            "num_residues", self.processing_widget.num_residues_ledit, float,
            None)

        self._model_mib.bind_value_update(
            "resolution_cutoff",
            self.processing_widget.resolution_cutoff_ledit, float, None)

        self._model_mib.bind_value_update(
            "pdb_file", self.processing_widget.pdb_file_ledit, str, None)

        self.processing_widget.space_group_combo.activated.connect(
            self._space_group_change)
        self.processing_widget.run_offline_processing_cbox.stateChanged.connect(
            self._run_offline_processing_toggled)
        self.processing_widget.run_online_processing_cbox.stateChanged.connect(
            self._run_online_processing_toggled)
        self.processing_widget.pdb_file_browse_button.clicked.connect(
            self._browse_clicked)

        self.processing_widget.resolution_cutoff_label.setHidden(True)
        self.processing_widget.resolution_cutoff_ledit.setHidden(True)
        self.processing_widget.pdb_file_label.setHidden(True)
        self.processing_widget.pdb_file_ledit.setHidden(True)
        self.processing_widget.pdb_file_browse_button.setHidden(True)

        if HWR.beamline.offline_processing_methods:
            cbox_text = "Run offline processing ("
            for method in HWR.beamline.offline_processing_methods:
                cbox_text += "%s, " % method
            cbox_text = cbox_text[:-2] + ")"
            self.processing_widget.run_offline_processing_cbox.setText(
                cbox_text)
            self.processing_widget.run_offline_processing_cbox.setChecked(
                HWR.beamline.run_offline_processing)
        else:
            self.processing_widget.run_offline_processing_cbox.setChecked(
                False)
            self.processing_widget.run_offline_processing_cbox.setEnabled(
                False)

        if HWR.beamline.online_processing_methods:
            cbox_text = "Run online processing ("
            for method in HWR.beamline.online_processing_methods:
                cbox_text += "%s, " % method
            cbox_text = cbox_text[:-2] + ")"
            self.processing_widget.run_online_processing_cbox.setText(
                cbox_text)
            self.processing_widget.run_online_processing_cbox.setChecked(
                HWR.beamline.run_online_processing)
        else:
            self.processing_widget.run_online_processing_cbox.setChecked(False)
            self.processing_widget.run_online_processing_cbox.setEnabled(False)
Beispiel #3
0
class ProcessingWidget(qt_import.QWidget):

    enableProcessingSignal = qt_import.pyqtSignal(bool, bool)

    def __init__(self, parent=None, name=None, fl=0, data_model=None):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        if data_model is None:
            self._model = queue_model_objects.ProcessingParameters()
        else:
            self._model = data_model

        self._model_mib = DataModelInputBinder(self._model)

        self.processing_widget = qt_import.load_ui_file(
            "processing_widget_vertical_layout.ui")

        self.main_layout = qt_import.QVBoxLayout(self)
        self.main_layout.addWidget(self.processing_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)

        self.processing_widget.space_group_combo.addItems(
            queue_model_enumerables.XTAL_SPACEGROUPS)

        self._model_mib.bind_value_update("cell_a",
                                          self.processing_widget.a_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_alpha",
                                          self.processing_widget.alpha_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_b",
                                          self.processing_widget.b_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_beta",
                                          self.processing_widget.beta_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_c",
                                          self.processing_widget.c_ledit,
                                          float, None)

        self._model_mib.bind_value_update("cell_gamma",
                                          self.processing_widget.gamma_ledit,
                                          float, None)

        self._model_mib.bind_value_update(
            "num_residues", self.processing_widget.num_residues_ledit, float,
            None)

        self._model_mib.bind_value_update(
            "resolution_cutoff",
            self.processing_widget.resolution_cutoff_ledit, float, None)

        self._model_mib.bind_value_update(
            "pdb_file", self.processing_widget.pdb_file_ledit, str, None)

        self.processing_widget.space_group_combo.activated.connect(
            self._space_group_change)
        self.processing_widget.run_offline_processing_cbox.stateChanged.connect(
            self._run_offline_processing_toggled)
        self.processing_widget.run_online_processing_cbox.stateChanged.connect(
            self._run_online_processing_toggled)
        self.processing_widget.pdb_file_browse_button.clicked.connect(
            self._browse_clicked)

        self.processing_widget.resolution_cutoff_label.setHidden(True)
        self.processing_widget.resolution_cutoff_ledit.setHidden(True)
        self.processing_widget.pdb_file_label.setHidden(True)
        self.processing_widget.pdb_file_ledit.setHidden(True)
        self.processing_widget.pdb_file_browse_button.setHidden(True)

        if HWR.beamline.offline_processing_methods:
            cbox_text = "Run offline processing ("
            for method in HWR.beamline.offline_processing_methods:
                cbox_text += "%s, " % method
            cbox_text = cbox_text[:-2] + ")"
            self.processing_widget.run_offline_processing_cbox.setText(
                cbox_text)
            self.processing_widget.run_offline_processing_cbox.setChecked(
                HWR.beamline.run_offline_processing)
        else:
            self.processing_widget.run_offline_processing_cbox.setChecked(
                False)
            self.processing_widget.run_offline_processing_cbox.setEnabled(
                False)

        if HWR.beamline.online_processing_methods:
            cbox_text = "Run online processing ("
            for method in HWR.beamline.online_processing_methods:
                cbox_text += "%s, " % method
            cbox_text = cbox_text[:-2] + ")"
            self.processing_widget.run_online_processing_cbox.setText(
                cbox_text)
            self.processing_widget.run_online_processing_cbox.setChecked(
                HWR.beamline.run_online_processing)
        else:
            self.processing_widget.run_online_processing_cbox.setChecked(False)
            self.processing_widget.run_online_processing_cbox.setEnabled(False)

    def _space_group_change(self, index):
        self._model.space_group = queue_model_enumerables.XTAL_SPACEGROUPS[
            index]

    def _set_space_group(self, space_group):
        index = 0

        if space_group in queue_model_enumerables.XTAL_SPACEGROUPS:
            index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group)

        self._space_group_change(index)
        self.processing_widget.space_group_combo.setCurrentIndex(index)

    def update_data_model(self, model):
        self._model = model
        self._model_mib.set_model(model)
        self._set_space_group(model.space_group)

    def _run_offline_processing_toggled(self, state):
        self.enableProcessingSignal.emit(
            self.processing_widget.run_offline_processing_cbox.isChecked(),
            self.processing_widget.run_online_processing_cbox.isChecked(),
        )

    def _run_online_processing_toggled(self, state):
        self.enableProcessingSignal.emit(
            self.processing_widget.run_offline_processing_cbox.isChecked(),
            self.processing_widget.run_online_processing_cbox.isChecked(),
        )

    def _browse_clicked(self):
        file_dialog = qt_import.QFileDialog(self)

        pdb_filename = str(
            file_dialog.getOpenFileName(self, "Select a PDB file",
                                        expanduser("~")))
        self._model.pdb_file = pdb_filename
        self.processing_widget.pdb_file_ledit.setText(pdb_filename)

    def get_processing_state(self):
        return self.processing_widget.run_offline_processing_cbox.isChecked(), \
               self.processing_widget.run_online_processing_cbox.isChecked()
    def __init__(
        self,
        parent=None,
        name=None,
        fl=0,
        acq_params=None,
        path_template=None,
        layout=None,
    ):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Internal variables --------------------------------------------------
        self.value_changed_list = []

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters(
            )
        else:
            self._acquisition_parameters = acq_params
        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)
        self.acq_widget_layout = qt_import.load_ui_file(
            "acquisition_widget_vertical_simple_layout.ui")

        # Layout --------------------------------------------------------------
        main_layout = qt_import.QVBoxLayout(self)
        main_layout.addWidget(self.acq_widget_layout)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(
            self.use_osc_start)
        self.acq_widget_layout.num_images_cbox.activated.connect(
            self.update_num_images)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(
            self.detector_roi_mode_changed)

        # Other ---------------------------------------------------------------
        self.osc_start_validator = qt_import.QDoubleValidator(
            -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit)
        self.osc_range_validator = qt_import.QDoubleValidator(
            -10000, 10000, 4, self.acq_widget_layout.osc_range_ledit)
        self.kappa_validator = qt_import.QDoubleValidator(
            0, 360, 4, self.acq_widget_layout.kappa_ledit)
        self.kappa_phi_validator = qt_import.QDoubleValidator(
            0, 360, 4, self.acq_widget_layout.kappa_phi_ledit)
        self.energy_validator = qt_import.QDoubleValidator(
            0, 25, 5, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = qt_import.QDoubleValidator(
            0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = qt_import.QDoubleValidator(
            0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = qt_import.QDoubleValidator(
            0, 10000, 6, self.acq_widget_layout.exp_time_ledit)
        self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)

        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

        self.set_tunable_energy(HWR.beamline.tunable_wavelength)

        if HWR.beamline.diffractometer.in_plate_mode():
            self.acq_widget_layout.num_images_cbox.clear()
            self.acq_widget_layout.num_images_cbox.addItem("1")
            self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)

        self.init_detector_roi_modes()
        self.init_limits()
class AcquisitionWidgetSimple(qt_import.QWidget):

    acqParametersChangedSignal = qt_import.pyqtSignal(list)
    madEnergySelectedSignal = qt_import.pyqtSignal(str, float, bool)

    def __init__(
        self,
        parent=None,
        name=None,
        fl=0,
        acq_params=None,
        path_template=None,
        layout=None,
    ):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Internal variables --------------------------------------------------
        self.value_changed_list = []

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters(
            )
        else:
            self._acquisition_parameters = acq_params
        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)
        self.acq_widget_layout = qt_import.load_ui_file(
            "acquisition_widget_vertical_simple_layout.ui")

        # Layout --------------------------------------------------------------
        main_layout = qt_import.QVBoxLayout(self)
        main_layout.addWidget(self.acq_widget_layout)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(
            self.use_osc_start)
        self.acq_widget_layout.num_images_cbox.activated.connect(
            self.update_num_images)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(
            self.detector_roi_mode_changed)

        # Other ---------------------------------------------------------------
        self.osc_start_validator = qt_import.QDoubleValidator(
            -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit)
        self.osc_range_validator = qt_import.QDoubleValidator(
            -10000, 10000, 4, self.acq_widget_layout.osc_range_ledit)
        self.kappa_validator = qt_import.QDoubleValidator(
            0, 360, 4, self.acq_widget_layout.kappa_ledit)
        self.kappa_phi_validator = qt_import.QDoubleValidator(
            0, 360, 4, self.acq_widget_layout.kappa_phi_ledit)
        self.energy_validator = qt_import.QDoubleValidator(
            0, 25, 5, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = qt_import.QDoubleValidator(
            0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = qt_import.QDoubleValidator(
            0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = qt_import.QDoubleValidator(
            0, 10000, 6, self.acq_widget_layout.exp_time_ledit)
        self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)

        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

        self.set_tunable_energy(HWR.beamline.tunable_wavelength)

        if HWR.beamline.diffractometer.in_plate_mode():
            self.acq_widget_layout.num_images_cbox.clear()
            self.acq_widget_layout.num_images_cbox.addItem("1")
            self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)

        self.init_detector_roi_modes()
        self.init_limits()

    def update_osc_total_range(self):
        pass

    def set_osc_start_limits(self, limits):
        if not None in limits:
            self.osc_start_validator.setRange(limits[0], limits[1], 4)

    def update_osc_start(self, new_value):
        if not self.acq_widget_layout.osc_start_cbox.hasFocus():
            self.acq_widget_layout.osc_start_ledit.setText(str(new_value))

    def update_kappa(self, new_value):
        if not self.acq_widget_layout.kappa_ledit.hasFocus():
            self.acq_widget_layout.kappa_ledit.setText(str(new_value))

    def update_kappa_phi(self, new_value):
        if not self.acq_widget_layout.kappa_phi_ledit.hasFocus():
            self.acq_widget_layout.kappa_phi_ledit.setText(str(new_value))

    def use_kappa(self, state):
        if HWR.beamline.diffractometer.in_plate_mode():
            state = False
        self.acq_widget_layout.kappa_label.setEnabled(state)
        self.acq_widget_layout.kappa_ledit.setEnabled(state)
        self.acq_widget_layout.kappa_phi_label.setEnabled(state)
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)

    def use_max_osc_range(self, state):
        pass

    def update_num_images(self, index=None, num_images=None):
        if index is not None:
            if index is 0:
                self._acquisition_parameters.num_images = 1
                self._path_template.num_files = 1
            elif index is 1:
                self._acquisition_parameters.num_images = 2
                self._path_template.num_files = 2
            elif index is 2:
                self._acquisition_parameters.num_images = 4
                self._path_template.num_files = 4

        if num_images:
            if self.acq_widget_layout.num_images_cbox.count() > 3:
                self.acq_widget_layout.num_images_cbox.removeItem(4)

            if num_images is 1:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)
            elif num_images is 2:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)
            elif num_images is 4:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(2)
            else:
                self.acq_widget_layout.num_images_cbox.addItem(str(num_images))
                self.acq_widget_layout.num_images_cbox.setCurrenIndex(3)

            self._path_template.num_files = num_images

    def use_mad(self, state):
        pass

    def get_mad_energy(self):
        pass

    def set_energies(self, energy_scan_result):
        pass

    def energy_selected(self, index):
        pass

    def init_limits(self):
        limits_dict = HWR.beamline.acquisition_limit_values

        tpl = limits_dict.get("osc_range")
        if tpl:
            self.osc_start_validator.setRange(tpl[0], tpl[1], 4)
            self.osc_range_validator.setRange(tpl[0], tpl[1], 4)

        self._acquisition_mib.bind_value_update(
            "osc_start",
            self.acq_widget_layout.osc_start_ledit,
            float,
            self.osc_start_validator,
        )

        self._acquisition_mib.bind_value_update(
            "osc_range",
            self.acq_widget_layout.osc_range_ledit,
            float,
            self.osc_range_validator,
        )

        tpl = limits_dict.get("kappa")
        if tpl:
            self.kappa_validator.setRange(tpl[0], tpl[1], 4)
        self._acquisition_mib.bind_value_update(
            "kappa", self.acq_widget_layout.kappa_ledit, float,
            self.kappa_validator)

        tpl = limits_dict.get("kappa_phi")
        if tpl:
            self.kappa_phi_validator.setRange(tpl[0], tpl[1], 4)
        self._acquisition_mib.bind_value_update(
            "kappa_phi",
            self.acq_widget_layout.kappa_phi_ledit,
            float,
            self.kappa_phi_validator,
        )

        tpl = limits_dict.get("exposure_time")
        if tpl:
            self.exp_time_validator.setRange(tpl[0], tpl[1], 6)
        self._acquisition_mib.bind_value_update(
            "exp_time",
            self.acq_widget_layout.exp_time_ledit,
            float,
            self.exp_time_validator,
        )

        self._acquisition_mib.bind_value_update(
            "energy", self.acq_widget_layout.energy_ledit, float,
            self.energy_validator)
        self.acq_widget_layout.energy_ledit.setToolTip(
            "Energy limits %0.3f : %0.3f" %
            (self.energy_validator.bottom(), self.energy_validator.top()))

        self._acquisition_mib.bind_value_update(
            "transmission",
            self.acq_widget_layout.transmission_ledit,
            float,
            self.transmission_validator,
        )

        self._acquisition_mib.bind_value_update(
            "resolution",
            self.acq_widget_layout.resolution_ledit,
            float,
            self.resolution_validator,
        )

        if HWR.beamline.diffractometer.in_plate_mode():
            self.acq_widget_layout.num_images_cbox.clear()
            self.acq_widget_layout.num_images_cbox.addItem("1")
            self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)

    def set_energy(self, energy, wav):
        if not self.acq_widget_layout.energy_ledit.hasFocus():
            self.acq_widget_layout.energy_ledit.setText(str(energy))

    def update_transmission(self, transmission):
        if self.acq_widget_layout.transmission_ledit.hasFocus():
            self.acq_widget_layout.transmission_ledit.setText(
                str(transmission))

    def update_resolution(self, resolution):
        if not self.acq_widget_layout.resolution_ledit.hasFocus():
            self.acq_widget_layout.resolution_ledit.setText(str(resolution))

    def update_energy_limits(self, limits):
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(
                "Energy limits %0.3f : %0.3f" % (limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(
                "Transmission limits %0.3f : %0.3f" % (limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
                "Resolution limits %0.3f : %0.3f" % (limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        if limits:
            self.exp_time_validator.setBottom(limits[0])
            self.exp_time_validator.setTop(limits[1])
            self.acq_widget_layout.exp_time_ledit.setToolTip(
                "Exposure time limits %0.3f : %0.3f" % (limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_energy(self, energy):
        if ("energy" not in self.value_changed_list
                and not self.acq_widget_layout.energy_ledit.hasFocus()):
            self.acq_widget_layout.energy_ledit.setText("%.4f" % float(energy))

    def init_detector_roi_modes(self):
        roi_modes = HWR.beamline.detector.get_roi_modes()
        if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
            for roi_mode in roi_modes:
                self.acq_widget_layout.detector_roi_mode_combo.addItem(
                    roi_mode)
            self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
            self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)

    def update_exp_time_limits(self):
        try:
            exp_time_limits = (
                HWR.beamline.detector.get_exposure_time_limits())
            max_osc_speed = HWR.beamline.diffractometer.get_osc_max_speed()
            top_limit = (float(self.acq_widget_layout.osc_range_ledit.text()) /
                         max_osc_speed)
            limits = (max(exp_time_limits[0], top_limit), exp_time_limits[1])
            self.update_detector_exp_time_limits(limits)
        except BaseException:
            pass

    def update_detector_roi_mode(self, roi_mode_index):
        if (roi_mode_index is not None and
                self.acq_widget_layout.detector_roi_mode_combo.count() > 0):
            self.acq_widget_layout.detector_roi_mode_combo.setCurrentIndex(
                roi_mode_index)

    def update_osc_range_limits(self, limits=None):
        pass

    def detector_roi_mode_changed(self, roi_mode_index):
        HWR.beamline.detector.set_roi_mode(roi_mode_index)

    def update_data_model(self, acquisition_parameters, path_template):
        self._acquisition_parameters = acquisition_parameters
        self._acquisition_mib.set_model(acquisition_parameters)
        self._path_template = path_template
        self.update_num_images(None, acquisition_parameters.num_images)

    def set_tunable_energy(self, state):
        self.acq_widget_layout.energy_ledit.setEnabled(state)

    def use_osc_start(self, state):
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def check_parameter_conflict(self):
        return self._acquisition_mib.validate_all()
Beispiel #6
0
    def __init__(self, parent=None, name="", fl=0, data_model=None, layout=None):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)
        self.parent = parent

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._base_image_dir = ""
        self._base_process_dir = ""
        self.path_conflict_state = False
        self.enable_macros = False

        if data_model is None:
            self._data_model = queue_model_objects.PathTemplate()
        else:
            self._data_model = data_model

        self._data_model_pm = DataModelInputBinder(self._data_model)

        # Graphic elements ----------------------------------------------------
        if layout == "vertical":
            self.data_path_layout = qt_import.load_ui_file(
                "data_path_widget_vertical_layout.ui"
            )
        else:
            self.data_path_layout = qt_import.load_ui_file(
                "data_path_widget_horizontal_layout.ui"
            )

        # Layout --------------------------------------------------------------
        _main_vlayout = qt_import.QVBoxLayout(self)
        _main_vlayout.addWidget(self.data_path_layout)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # Qt signal/slot connections ------------------------------------------
        self.data_path_layout.prefix_ledit.textChanged.connect(
            self._prefix_ledit_change
        )
        self.data_path_layout.run_number_ledit.textChanged.connect(
            self._run_number_ledit_change
        )
        self.data_path_layout.browse_button.clicked.connect(self._browse_clicked)
        self.data_path_layout.folder_ledit.textChanged.connect(
            self._folder_ledit_change
        )
        self.data_path_layout.compression_cbox.clicked.connect(
            self._compression_toggled
        )

        # Other ---------------------------------------------------------------
        self._data_model_pm.bind_value_update(
            "base_prefix", self.data_path_layout.prefix_ledit, str, None
        )

        self._data_model_pm.bind_value_update(
            "run_number",
            self.data_path_layout.run_number_ledit,
            int,
            qt_import.QIntValidator(0, 1000, self),
        )

        self._data_model_pm.bind_value_update(
            "compression", self.data_path_layout.compression_cbox, bool, None
        )
Beispiel #7
0
    def __init__(
        self,
        parent=None,
        name=None,
        fl=0,
        acq_params=None,
        path_template=None,
        layout="horizontal",
    ):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # If the acq. widget is used with grids then total osc range is not
        # equal to num_images * osc_range, but num_images_per_line * osc_range
        # For grids the osc total range is updated when a grid is selected

        self.grid_mode = False

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = qt_import.load_ui_file(
                "acquisition_widget_horizontal_layout.ui"
            )
            self.use_osc_start(False)
        else:
            self.acq_widget_layout = qt_import.load_ui_file(
                "acquisition_widget_vertical_layout.ui"
            )

        # Layout --------------------------------------------------------------
        __main_vlayout = qt_import.QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(self.fix_osc_start)
        self.acq_widget_layout.exp_time_ledit.textChanged.connect(
            self.exposure_time_ledit_changed
        )
        self.acq_widget_layout.exp_time_total_ledit.textEdited.connect(
            self.exp_time_total_ledit_changed
        )
        self.acq_widget_layout.first_image_ledit.textChanged.connect(
            self.first_image_ledit_change
        )
        self.acq_widget_layout.num_images_ledit.textChanged.connect(
            self.num_images_ledit_change
        )
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(
            self.detector_roi_mode_changed
        )
        self.acq_widget_layout.energies_combo.activated.connect(self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(self.use_mad)
        self.acq_widget_layout.osc_start_ledit.textEdited.connect(
            self.osc_start_ledit_changed
        )
        self.acq_widget_layout.osc_range_ledit.textEdited.connect(
            self.osc_range_per_frame_ledit_changed
        )
        self.acq_widget_layout.osc_total_range_ledit.textEdited.connect(
            self.osc_total_range_ledit_changed
        )
        self.acq_widget_layout.energy_ledit.textEdited.connect(
            self.energy_ledit_changed
        )
        self.acq_widget_layout.transmission_ledit.textEdited.connect(
            self.transmission_ledit_changed
        )
        self.acq_widget_layout.resolution_ledit.textEdited.connect(
            self.resolution_ledit_changed
        )
        self.acq_widget_layout.kappa_ledit.textEdited.connect(self.kappa_ledit_changed)
        self.acq_widget_layout.kappa_phi_ledit.textEdited.connect(
            self.kappa_phi_ledit_changed
        )

        if self.acq_widget_layout.findChild(qt_import.QLineEdit, "overlap_ledit"):
            self.acq_widget_layout.overlap_ledit.textChanged.connect(
                self.overlap_changed
            )
        if self.acq_widget_layout.findChild(qt_import.QCheckBox, "max_osc_range_cbx"):
            self.acq_widget_layout.max_osc_range_cbx.toggled.connect(
                self.max_osc_range_toggled
            )

        # Other ---------------------------------------------------------------
        self.value_changed_list = []

        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(
            ["ip: -", "pk: -", "rm1: -", "rm2: -"]
        )

        self.osc_start_validator = qt_import.QDoubleValidator(
            -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit
        )
        self.osc_range_per_frame_validator = qt_import.QDoubleValidator(
            0, 10000, 4, self.acq_widget_layout.osc_range_ledit
        )
        self.osc_total_range_validator = qt_import.QDoubleValidator(
            0, 10000, 4, self.acq_widget_layout.osc_total_range_ledit
        )
        self.kappa_validator = qt_import.QDoubleValidator(
            -0.01, 360, 4, self.acq_widget_layout.kappa_ledit
        )
        self.kappa_phi_validator = qt_import.QDoubleValidator(
            -360, 360, 4, self.acq_widget_layout.kappa_phi_ledit
        )
        self.energy_validator = qt_import.QDoubleValidator(
            4, 25, 5, self.acq_widget_layout.energy_ledit
        )
        self.resolution_validator = qt_import.QDoubleValidator(
            0, 15, 3, self.acq_widget_layout.resolution_ledit
        )
        self.transmission_validator = qt_import.QDoubleValidator(
            0, 100, 3, self.acq_widget_layout.transmission_ledit
        )
        self.exp_time_validator = qt_import.QDoubleValidator(
            0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit
        )
        self.first_img_validator = qt_import.QIntValidator(
            0, 99999, self.acq_widget_layout.first_image_ledit
        )
        self.num_img_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_images_ledit
        )
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

        self.init_limits()
Beispiel #8
0
class XrayImagingParametersWidget(qt_import.QWidget):
    def __init__(self, parent=None, name=None, fl=0, xray_imaging_params=None):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Internal variables --------------------------------------------------

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        self._xray_imaging_parameters = xray_imaging_params
        self._xray_imaging_mib = DataModelInputBinder(
            self._xray_imaging_parameters)

        self._parameters_widget = qt_import.load_ui_file(
            "xray_imaging_parameters_widget_layout.ui")
        # Layout --------------------------------------------------------------
        __main_vlayout = qt_import.QVBoxLayout(self)
        __main_vlayout.addWidget(self._parameters_widget)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._parameters_widget.ff_pre_cbox.toggled.connect(
            self.ff_pre_toggled)
        self._parameters_widget.ff_post_cbox.toggled.connect(
            self.ff_post_toggled)
        self._parameters_widget.add_button.pressed.connect(
            self.add_distance_pressed)
        self._parameters_widget.remove_button.pressed.connect(
            self.remove_distance_pressed)

        # Other ---------------------------------------------------------------
        # self.detector_distance_validator = qt_import.QIntValidator(
        #     0, 99999, self._parameters_widget.detector_distance_ledit
        # )
        self.detector_distance_validator = qt_import.QDoubleValidator(
            0, 99999, 2, self._parameters_widget.detector_distance_ledit)

        self._xray_imaging_mib.bind_value_update(
            "camera_write_data", self._parameters_widget.store_data_cbox, bool,
            None)

        self._xray_imaging_mib.bind_value_update(
            "ff_pre", self._parameters_widget.ff_pre_cbox, bool, None)

        self._xray_imaging_mib.bind_value_update(
            "ff_post", self._parameters_widget.ff_post_cbox, bool, None)

        self._xray_imaging_mib.bind_value_update(
            "ff_apply", self._parameters_widget.ff_apply_cbox, bool, None)

        self._xray_imaging_mib.bind_value_update(
            "ff_ssim_enabled", self._parameters_widget.ff_ssim_cbox, bool,
            None)

        self._xray_imaging_mib.bind_value_update(
            "ff_num_images", self._parameters_widget.ff_num_images_ledit, int,
            None)

        self._xray_imaging_mib.bind_value_update(
            "sample_offset_a",
            self._parameters_widget.ff_offset_a_ledit,
            float,
            None,
        )

        self._xray_imaging_mib.bind_value_update(
            "sample_offset_b",
            self._parameters_widget.ff_offset_b_ledit,
            float,
            None,
        )

        self._xray_imaging_mib.bind_value_update(
            "sample_offset_c",
            self._parameters_widget.ff_offset_c_ledit,
            float,
            None,
        )

        self._xray_imaging_mib.bind_value_update(
            "detector_distance",
            self._parameters_widget.detector_distance_ledit,
            float,
            self.detector_distance_validator,
        )

    def ff_pre_toggled(self, state):
        self.toggle_ff_controls()

    def ff_post_toggled(self, state):
        self.toggle_ff_controls()

    def toggle_ff_controls(self):
        enable_ff_controls = self._parameters_widget.ff_pre_cbox.isChecked() or \
           self._parameters_widget.ff_post_cbox.isChecked()

        self._parameters_widget.ff_apply_cbox.setEnabled(enable_ff_controls)
        self._parameters_widget.ff_ssim_cbox.setEnabled(enable_ff_controls)
        self._parameters_widget.ff_num_images_label.setEnabled(
            enable_ff_controls)
        self._parameters_widget.ff_num_images_ledit.setEnabled(
            enable_ff_controls)
        self._parameters_widget.ff_offset_a_label.setEnabled(
            enable_ff_controls)
        self._parameters_widget.ff_offset_a_ledit.setEnabled(
            enable_ff_controls)
        self._parameters_widget.ff_offset_b_label.setEnabled(
            enable_ff_controls)
        self._parameters_widget.ff_offset_b_ledit.setEnabled(
            enable_ff_controls)
        self._parameters_widget.ff_offset_c_label.setEnabled(
            enable_ff_controls)
        self._parameters_widget.ff_offset_c_ledit.setEnabled(
            enable_ff_controls)

    def add_distance_pressed(self):
        if str(self._parameters_widget.detector_distance_ledit.text()).isdigit:
            self._parameters_widget.detector_distance_listwidget.addItem(
                self._parameters_widget.detector_distance_ledit.text())
            self._parameters_widget.remove_button.setEnabled(True)
            self._parameters_widget.detector_distance_listwidget.setCurrentRow(
                self._parameters_widget.detector_distance_listwidget.count() -
                1)

    def remove_distance_pressed(self):
        self._parameters_widget.detector_distance_listwidget.takeItem(
            self._parameters_widget.detector_distance_listwidget.currentRow())
        self._parameters_widget.remove_button.setEnabled(
            self._parameters_widget.detector_distance_listwidget.count > 0)

    def enable_distance_tools(self, state):
        self._parameters_widget.add_button.setEnabled(state)
        self._parameters_widget.remove_button.setEnabled(state)
        self._parameters_widget.detector_distance_listwidget.setEnabled(state)

    def set_detector_distance(self, value):
        self._parameters_widget.detector_distance_ledit.setText("%d" % value)
        self._xray_imaging_parameters.detector_distance = value

    def populate_widget(self, item):
        xray_imaging_params = item.get_model().xray_imaging_parameters
        self.update_data_model(xray_imaging_params)

    def update_data_model(self, xray_imaging_params):
        self._xray_imaging_parameters = xray_imaging_params
        self._xray_imaging_mib.set_model(xray_imaging_params)
Beispiel #9
0
    def __init__(self, parent=None, name="char_parameter_widget"):

        qt_import.QWidget.__init__(self, parent)

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._char = None
        self._char_params = queue_model_objects.CharacterisationParameters()
        self._char_params_mib = DataModelInputBinder(self._char_params)
        self._tree_view_item = None
        self.previous_energy = None

        self.add_dc_cb = None

        # Graphic elements ----------------------------------------------------
        main_widget = qt_import.QWidget(self)
        rone_widget = qt_import.QWidget(main_widget)
        self.reference_img_widget = ReferenceImageWidget(rone_widget)
        self.acq_widget = self.reference_img_widget.acq_widget
        self.path_widget = self.reference_img_widget.path_widget
        self.position_widget = qt_import.load_ui_file(
            "snapshot_widget_layout.ui")
        self.position_widget.setMinimumSize(450, 340)

        rtwo_widget = qt_import.QWidget(main_widget)
        self.char_type_widget = CharTypeWidget(rtwo_widget)
        self.routine_dc_widget = self.char_type_widget.routine_dc_page
        self.sad_widget = self.char_type_widget.sad_page
        self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page
        self.opt_parameters_widget = OptimisationParametersWidgetLayout(self)

        rtree_widget = qt_import.QWidget(main_widget)
        self.rad_dmg_widget = qt_import.load_ui_file(
            "radiation_damage_model_widget_layout.ui")
        self.vertical_dimension_widget = qt_import.load_ui_file(
            "vertical_crystal_dimension_widget_layout.ui")

        # Layout --------------------------------------------------------------
        rone_widget_layout = qt_import.QHBoxLayout(rone_widget)
        rone_widget_layout.addWidget(self.reference_img_widget)
        rone_widget_layout.addWidget(self.position_widget)
        # rone_widget_layout.addStretch(0)
        rone_widget_layout.setSpacing(2)
        rone_widget_layout.setContentsMargins(0, 0, 0, 0)

        rtwo_widget_layout = qt_import.QHBoxLayout(rtwo_widget)
        rtwo_widget_layout.addWidget(self.char_type_widget)
        rtwo_widget_layout.addWidget(self.opt_parameters_widget)
        rtwo_widget_layout.addStretch(0)
        rtwo_widget_layout.setSpacing(2)
        rtwo_widget_layout.setContentsMargins(0, 0, 0, 0)

        rtree_widget_layout = qt_import.QHBoxLayout(rtree_widget)
        rtree_widget_layout.addWidget(self.rad_dmg_widget)
        rtree_widget_layout.addWidget(self.vertical_dimension_widget)
        rtree_widget_layout.addStretch(10)
        rtree_widget_layout.setSpacing(2)
        rtree_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_widget_vlayout = qt_import.QVBoxLayout(main_widget)
        _main_widget_vlayout.addWidget(rone_widget)
        _main_widget_vlayout.addWidget(rtwo_widget)
        _main_widget_vlayout.addWidget(rtree_widget)
        _main_widget_vlayout.addStretch(10)
        _main_widget_vlayout.setSpacing(2)
        _main_widget_vlayout.setContentsMargins(0, 0, 0, 0)

        _main_hlayout = qt_import.QHBoxLayout(self)
        _main_hlayout.addWidget(main_widget)
        _main_hlayout.setSpacing(0)
        _main_hlayout.addStretch(0)
        _main_hlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies -------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.toggle_permitted_range(
            self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.
            isChecked())

        self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.toggled.connect(
            self.toggle_permitted_range)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            "min_dose",
            self.routine_dc_widget.dose_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_time",
            self.routine_dc_widget.time_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "use_min_dose", self.routine_dc_widget.min_dose_radio, bool, None)

        self._char_params_mib.bind_value_update(
            "use_min_time", self.routine_dc_widget.min_time_radio, bool, None)

        self._char_params_mib.bind_value_update(
            "account_rad_damage",
            self.routine_dc_widget.radiation_damage_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "auto_res", self.sad_widget.automatic_resolution_radio, bool, None)

        self._char_params_mib.bind_value_update(
            "sad_res",
            self.sad_widget.sad_resolution_ledit,
            float,
            qt_import.QDoubleValidator(0.5, 20, 3, self),
        )

        self._char_params_mib.bind_value_update(
            "opt_sad", self.sad_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            "determine_rad_params", self.rad_dmg_char_widget.rad_damage_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            "burn_osc_start",
            self.rad_dmg_char_widget.burn_osc_start_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "burn_osc_interval",
            self.rad_dmg_char_widget.burn_osc_interval_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "use_aimed_resolution",
            self.opt_parameters_widget.opt_param_widget.maximum_res_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "use_aimed_multiplicity",
            self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "aimed_resolution",
            self.opt_parameters_widget.opt_param_widget.maximum_res_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "aimed_multiplicity",
            self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "aimed_i_sigma",
            self.opt_parameters_widget.opt_param_widget.i_over_sigma_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "aimed_completness",
            self.opt_parameters_widget.opt_param_widget.aimed_comp_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "strategy_complexity",
            self.opt_parameters_widget.opt_param_widget.start_comp_cbox,
            int,
            None,
        )

        self._char_params_mib.bind_value_update(
            "use_permitted_rotation",
            self.opt_parameters_widget.opt_param_widget.permitted_range_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "permitted_phi_start",
            self.opt_parameters_widget.opt_param_widget.phi_start_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "permitted_phi_end",
            self.opt_parameters_widget.opt_param_widget.phi_end_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "low_res_pass_strat",
            self.opt_parameters_widget.opt_param_widget.low_res_pass_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "rad_suscept",
            self.rad_dmg_widget.sensetivity_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "beta",
            self.rad_dmg_widget.beta_over_gray_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "gamma",
            self.rad_dmg_widget.gamma_over_gray_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "max_crystal_vdim",
            self.vertical_dimension_widget.max_vdim_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_crystal_vdim",
            self.vertical_dimension_widget.min_vdim_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_crystal_vphi",
            self.vertical_dimension_widget.min_vphi_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "max_crystal_vphi",
            self.vertical_dimension_widget.max_vphi_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        # self._char_params_mib.bind_value_update('space_group',
        #                                        self.vertical_dimension_widget.space_group_ledit,
        #                                        str,
        #                                        None)

        self.vertical_dimension_widget.space_group_ledit.addItems(
            queue_model_enumerables.XTAL_SPACEGROUPS)

        self.char_type_widget.charact_type_tbox.currentChanged.connect(
            self.update_char_type)
        self.rad_dmg_char_widget.rad_damage_cbx.toggled.connect(
            self.enable_opt_parameters_widget)
        self.opt_parameters_widget.opt_param_widget.maximum_res_cbx.toggled.connect(
            self.enable_maximum_res_ledit)
        self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx.toggled.connect(
            self.enable_aimed_mult_ledit)
        self.path_widget.data_path_layout.prefix_ledit.textChanged.connect(
            self._prefix_ledit_change)
        self.path_widget.data_path_layout.run_number_ledit.textChanged.connect(
            self._run_number_ledit_change)
        self.vertical_dimension_widget.space_group_ledit.activated.connect(
            self._space_group_change)
Beispiel #10
0
class AcquisitionWidget(qt_import.QWidget):

    acqParametersChangedSignal = qt_import.pyqtSignal(list)
    madEnergySelectedSignal = qt_import.pyqtSignal(str, float, bool)

    def __init__(
        self,
        parent=None,
        name=None,
        fl=0,
        acq_params=None,
        path_template=None,
        layout="horizontal",
    ):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # If the acq. widget is used with grids then total osc range is not
        # equal to num_images * osc_range, but num_images_per_line * osc_range
        # For grids the osc total range is updated when a grid is selected

        self.grid_mode = False

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = qt_import.load_ui_file(
                "acquisition_widget_horizontal_layout.ui"
            )
            self.use_osc_start(False)
        else:
            self.acq_widget_layout = qt_import.load_ui_file(
                "acquisition_widget_vertical_layout.ui"
            )

        # Layout --------------------------------------------------------------
        __main_vlayout = qt_import.QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(self.fix_osc_start)
        self.acq_widget_layout.exp_time_ledit.textChanged.connect(
            self.exposure_time_ledit_changed
        )
        self.acq_widget_layout.exp_time_total_ledit.textEdited.connect(
            self.exp_time_total_ledit_changed
        )
        self.acq_widget_layout.first_image_ledit.textChanged.connect(
            self.first_image_ledit_change
        )
        self.acq_widget_layout.num_images_ledit.textChanged.connect(
            self.num_images_ledit_change
        )
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(
            self.detector_roi_mode_changed
        )
        self.acq_widget_layout.energies_combo.activated.connect(self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(self.use_mad)
        self.acq_widget_layout.osc_start_ledit.textEdited.connect(
            self.osc_start_ledit_changed
        )
        self.acq_widget_layout.osc_range_ledit.textEdited.connect(
            self.osc_range_per_frame_ledit_changed
        )
        self.acq_widget_layout.osc_total_range_ledit.textEdited.connect(
            self.osc_total_range_ledit_changed
        )
        self.acq_widget_layout.energy_ledit.textEdited.connect(
            self.energy_ledit_changed
        )
        self.acq_widget_layout.transmission_ledit.textEdited.connect(
            self.transmission_ledit_changed
        )
        self.acq_widget_layout.resolution_ledit.textEdited.connect(
            self.resolution_ledit_changed
        )
        self.acq_widget_layout.kappa_ledit.textEdited.connect(self.kappa_ledit_changed)
        self.acq_widget_layout.kappa_phi_ledit.textEdited.connect(
            self.kappa_phi_ledit_changed
        )

        if self.acq_widget_layout.findChild(qt_import.QLineEdit, "overlap_ledit"):
            self.acq_widget_layout.overlap_ledit.textChanged.connect(
                self.overlap_changed
            )
        if self.acq_widget_layout.findChild(qt_import.QCheckBox, "max_osc_range_cbx"):
            self.acq_widget_layout.max_osc_range_cbx.toggled.connect(
                self.max_osc_range_toggled
            )

        # Other ---------------------------------------------------------------
        self.value_changed_list = []

        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(
            ["ip: -", "pk: -", "rm1: -", "rm2: -"]
        )

        self.osc_start_validator = qt_import.QDoubleValidator(
            -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit
        )
        self.osc_range_per_frame_validator = qt_import.QDoubleValidator(
            0, 10000, 4, self.acq_widget_layout.osc_range_ledit
        )
        self.osc_total_range_validator = qt_import.QDoubleValidator(
            0, 10000, 4, self.acq_widget_layout.osc_total_range_ledit
        )
        self.kappa_validator = qt_import.QDoubleValidator(
            -0.01, 360, 4, self.acq_widget_layout.kappa_ledit
        )
        self.kappa_phi_validator = qt_import.QDoubleValidator(
            -360, 360, 4, self.acq_widget_layout.kappa_phi_ledit
        )
        self.energy_validator = qt_import.QDoubleValidator(
            4, 25, 5, self.acq_widget_layout.energy_ledit
        )
        self.resolution_validator = qt_import.QDoubleValidator(
            0, 15, 3, self.acq_widget_layout.resolution_ledit
        )
        self.transmission_validator = qt_import.QDoubleValidator(
            0, 100, 3, self.acq_widget_layout.transmission_ledit
        )
        self.exp_time_validator = qt_import.QDoubleValidator(
            0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit
        )
        self.first_img_validator = qt_import.QIntValidator(
            0, 99999, self.acq_widget_layout.first_image_ledit
        )
        self.num_img_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_images_ledit
        )
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

        self.init_limits()

    def use_max_osc_range(self, state):
        self.acq_widget_layout.max_osc_range_cbx.setEnabled(state)

    def fix_osc_start(self, state):
        """
        Fix osc start, so the lineEdit do not change when osc is changed
        """
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def update_osc_start(self, new_value):
        """
        Updates osc line edit
        """
        if (
            "osc_start" not in self.value_changed_list
            and not self.acq_widget_layout.osc_start_ledit.hasFocus()
            and not self.acq_widget_layout.osc_start_cbox.isChecked()
        ):
            osc_start_value = 0
            try:
                osc_start_value = round(float(new_value), 2)
            except TypeError:
                pass

            self.acq_widget_layout.osc_start_ledit.setText(str(osc_start_value))
            self._acquisition_parameters.osc_start = osc_start_value

            # self.update_osc_total_range_limits()
            # self.update_num_images_limits()

    def osc_start_ledit_changed(self, osc_start):
        """Fixes osc start edit"""
        if "osc_start" not in self.value_changed_list:
            self.value_changed_list.append("osc_start")
        self.update_osc_total_range_limits()
        self.update_num_images_limits()
        self.emit_acq_parameters_changed()

    def update_osc_start_limits(self):
        """In the plate mode sets osc start limits"""
        self.update_osc_total_range_limits()
        self.update_num_images_limits()

    def osc_range_per_frame_ledit_changed(self, new_value):
        self.update_osc_total_range()
        self.update_num_images_limits()
        self.update_exp_time_limits()
        self.emit_acq_parameters_changed()

    def update_osc_range_per_frame_limits(self):
        try:
            max_osc_speed = HWR.beamline.diffractometer.get_osc_max_speed()
            top_limit = max_osc_speed * float(
                self.acq_widget_layout.exp_time_ledit.text()
            )
            self.osc_range_per_frame_validator.setTop(top_limit)
            tool_tip = (
                "Oscillation range per frame limits 0 : "
                + "%0.4f\n4 digits precision." % top_limit
            )

            self.acq_widget_layout.osc_range_ledit.setToolTip(tool_tip)
            self._acquisition_mib.validate_all()
        except BaseException:
            pass

    def update_osc_total_range(self):
        self.acq_widget_layout.osc_total_range_ledit.blockSignals(True)

        if not self.grid_mode:
            try:
                self.acq_widget_layout.osc_total_range_ledit.setText(
                    "%0.2f" %
                    (
                        float(self.acq_widget_layout.osc_range_ledit.text())
                        * int(self.acq_widget_layout.num_images_ledit.text())
                    )
                )
            except BaseException:
                pass
        self.acq_widget_layout.osc_total_range_ledit.blockSignals(False)

    def update_total_exp_time(self):
        try:
            self.acq_widget_layout.exp_time_total_ledit.setText(
                "%.2f"
                % (
                    float(self.acq_widget_layout.exp_time_ledit.text())
                    * float(self.acq_widget_layout.num_images_ledit.text())
                )
            )
        except BaseException:
            pass

    def osc_total_range_ledit_changed(self, new_value):
        if not self.grid_mode:
            try:
                num_images = int(
                    float(new_value)
                    / float(self.acq_widget_layout.osc_range_ledit.text())
                )
                self.acq_widget_layout.num_images_ledit.blockSignals(True)
                self.acq_widget_layout.num_images_ledit.setText("%d" % num_images)
                self._acquisition_parameters.num_images = num_images
                self.acq_widget_layout.num_images_ledit.blockSignals(False)
            except BaseException:
                pass
            self.emit_acq_parameters_changed()

    def exp_time_total_ledit_changed(self, new_value):
        try:
            exp_time = float(new_value)  / float(self.acq_widget_layout.num_images_ledit.text())
            self.acq_widget_layout.exp_time_ledit.blockSignals(True)
            self.acq_widget_layout.exp_time_ledit.setText("%.4f" % exp_time)
            self._acquisition_parameters.exp_time = exp_time
            self.acq_widget_layout.exp_time_ledit.blockSignals(False)
        except BaseException:
            pass
        self.emit_acq_parameters_changed()

    def update_osc_total_range_limits(self, num_images=None):
        """Updates osc totol range. Limits are changed if a plate is used.
           - For simple oscillation osc_range is defined by osc_start and
             osc_start top limit.
           - For mesh osc_range is defined by number of images per line
             and osc in the middle of mesh
        """
        if HWR.beamline.diffractometer.in_plate_mode():
            if hasattr(self.parent(), "set_osc_total_range"):
                self.parent().set_osc_total_range(num_images)
                self._acquisition_mib.validate_all()

    def update_exp_time_limits(self):
        try:
            exp_time_limits = (
                HWR.beamline.detector.get_exposure_time_limits()
            )
            max_osc_speed = HWR.beamline.diffractometer.get_osc_max_speed()
            top_limit = (
                float(self.acq_widget_layout.osc_range_ledit.text()) / max_osc_speed
            )
            limits = (max(exp_time_limits[0], top_limit), exp_time_limits[1])

            self.update_detector_exp_time_limits(limits)
        except BaseException:
            pass

    def update_kappa(self, new_value):
        if not self.acq_widget_layout.kappa_ledit.hasFocus() and new_value is not None:
            self.acq_widget_layout.kappa_ledit.setText(str(new_value))
            self.emit_acq_parameters_changed()

    def update_kappa_phi(self, new_value):
        if not self.acq_widget_layout.kappa_phi_ledit.hasFocus() and new_value:
            self.acq_widget_layout.kappa_phi_ledit.setText(str(new_value))
            self.emit_acq_parameters_changed()

    def use_osc_start(self, state):
        self.acq_widget_layout.osc_start_cbox.setVisible(state)
        self.acq_widget_layout.osc_start_label.setVisible(not state)
        self.acq_widget_layout.osc_start_ledit.setEnabled(not state)

    def use_kappa(self, state):
        if HWR.beamline.diffractometer is not None:
            if HWR.beamline.diffractometer.in_plate_mode():
                state = False
        self.acq_widget_layout.kappa_label.setEnabled(state)
        self.acq_widget_layout.kappa_ledit.setEnabled(state)
        self.acq_widget_layout.kappa_phi_label.setEnabled(state)
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)

    def init_limits(self):
        limits_dict = HWR.beamline.acquisition_limit_values

        tpl = limits_dict.get("osc_range")
        if tpl:
            self.osc_start_validator.setRange(tpl[0], tpl[1], 4)
            self.osc_range_per_frame_validator.setRange(tpl[0], tpl[1], 4)
            self.osc_total_range_validator.setRange(tpl[0], tpl[1], 4)

        self._acquisition_mib.bind_value_update(
            "osc_start",
            self.acq_widget_layout.osc_start_ledit,
            float,
            self.osc_start_validator,
        )

        self._acquisition_mib.bind_value_update(
            "osc_range",
            self.acq_widget_layout.osc_range_ledit,
            float,
            self.osc_range_per_frame_validator,
        )

        self._acquisition_mib.bind_value_update(
            "osc_total_range",
            self.acq_widget_layout.osc_total_range_ledit,
            float,
            self.osc_total_range_validator,
        )

        tpl = limits_dict.get("kappa")
        if tpl:
            self.kappa_validator.setRange(tpl[0], tpl[1], 4)
        self._acquisition_mib.bind_value_update(
            "kappa", self.acq_widget_layout.kappa_ledit, float, self.kappa_validator
        )

        tpl = limits_dict.get("kappa_phi")
        if tpl:
            self.kappa_phi_validator.setRange(tpl[0], tpl[1], 4)
        self._acquisition_mib.bind_value_update(
            "kappa_phi",
            self.acq_widget_layout.kappa_phi_ledit,
            float,
            self.kappa_phi_validator,
        )

        tpl = limits_dict.get("exposure_time")
        if tpl:
            self.exp_time_validator.setRange(tpl[0], tpl[1], 6)

        self._acquisition_mib.bind_value_update(
            "exp_time",
            self.acq_widget_layout.exp_time_ledit,
            float,
            self.exp_time_validator,
        )

        tpl = limits_dict.get("number_of_images")
        if tpl:
            self.num_img_validator.setRange(tpl[0], tpl[1])
            self.first_img_validator.setRange(tpl[0], tpl[1])

        self._acquisition_mib.bind_value_update(
            "first_image",
            self.acq_widget_layout.first_image_ledit,
            int,
            self.first_img_validator,
        )

        self._acquisition_mib.bind_value_update(
            "num_images",
            self.acq_widget_layout.num_images_ledit,
            int,
            self.num_img_validator,
        )

        num_passes = self.acq_widget_layout.findChild(
            qt_import.QLineEdit, "num_passes_ledit"
        )

        if num_passes:
            self._acquisition_mib.bind_value_update(
                "num_passes", num_passes, int, qt_import.QIntValidator(1, 1000, self)
            )

        overlap_ledit = self.acq_widget_layout.findChild(
            qt_import.QLineEdit, "overlap_ledit"
        )

        if overlap_ledit:
            self._acquisition_mib.bind_value_update(
                "overlap",
                overlap_ledit,
                float,
                qt_import.QDoubleValidator(-1000, 1000, 2, self),
            )

        self._acquisition_mib.bind_value_update(
            "energy", self.acq_widget_layout.energy_ledit, float, self.energy_validator
        )
        self.update_energy_limits(
            (self.energy_validator.bottom(), self.energy_validator.top())
        )

        self._acquisition_mib.bind_value_update(
            "transmission",
            self.acq_widget_layout.transmission_ledit,
            float,
            self.transmission_validator,
        )
        self.update_transmission_limits(
            (self.transmission_validator.bottom(), self.transmission_validator.top())
        )

        self._acquisition_mib.bind_value_update(
            "resolution",
            self.acq_widget_layout.resolution_ledit,
            float,
            self.resolution_validator,
        )
        # self.update_resolution_limits((self.resolution_validator.bottom(),
        #                               self.resolution_validator.top()))

        self._acquisition_mib.bind_value_update(
            "shutterless", self.acq_widget_layout.shutterless_cbx, bool, None
        )

        self.set_tunable_energy(HWR.beamline.tunable_wavelength)

        has_shutter_less = HWR.beamline.detector.has_shutterless()
        self.acq_widget_layout.shutterless_cbx.setEnabled(has_shutter_less)
        self.acq_widget_layout.shutterless_cbx.setChecked(has_shutter_less)

        if HWR.beamline.disable_num_passes:
            num_passes = self.acq_widget_layout.findChild(
                qt_import.QLineEdit, "num_passes_ledit"
            )
            if num_passes:
                num_passes.setDisabled(True)

        self.init_detector_roi_modes()

    def first_image_ledit_change(self, new_value):
        self.emit_acq_parameters_changed()

    def exposure_time_ledit_changed(self, new_value):
        """If the exposure time changes we have to check the osc speed
           and if necessary update osc range per frame
        """
        self.update_osc_range_per_frame_limits()
        self.update_osc_total_range_limits()
        self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def num_images_ledit_change(self, new_value):
        if str(new_value).isdigit():
            # self._path_template.num_files = int(new_value)
            self.update_osc_range_per_frame_limits()
            self.update_osc_total_range_limits()
            self.update_osc_total_range()
            self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def overlap_changed(self, new_value):

        if HWR.beamline.detector.has_shutterless():
            try:
                new_value = float(new_value)
            except ValueError:
                pass

            if new_value != 0:
                self.acq_widget_layout.shutterless_cbx.setEnabled(False)
                self.acq_widget_layout.shutterless_cbx.setChecked(False)
                self._acquisition_parameters.shutterless = False
            else:
                self.acq_widget_layout.shutterless_cbx.setEnabled(True)
                self.acq_widget_layout.shutterless_cbx.setChecked(True)
                self._acquisition_parameters.shutterless = True

    def use_mad(self, state):
        self.acq_widget_layout.energies_combo.setEnabled(state)
        if state:
            (name, energy) = self.get_mad_energy()

            if energy != 0:
                self.update_energy(energy)
            self.madEnergySelectedSignal.emit(name, energy, state)
        else:
            self.update_energy(self.previous_energy)
            # energy = HWR.beamline.energy.get_current_energy()
            self.madEnergySelectedSignal.emit("", self.previous_energy, state)

    def max_osc_range_toggled(self, state):
        self.update_osc_total_range_limits()

    def get_mad_energy(self):
        energy_str = str(self.acq_widget_layout.energies_combo.currentText())
        (name, value) = energy_str.split(":")

        name = name.strip()
        value = value.strip()
        value = 0 if (value == "-") else float(value)

        return (name, value)

    def set_energies(self, energy_scan_result):
        self.acq_widget_layout.energies_combo.clear()

        inflection = (
            ("ip: %.4f" % energy_scan_result.inflection)
            if energy_scan_result.inflection
            else "ip: -"
        )

        peak = (
            ("pk: %.4f" % energy_scan_result.peak)
            if energy_scan_result.peak
            else "pk: -"
        )

        first_remote = (
            ("rm1: %.4f" % energy_scan_result.first_remote)
            if energy_scan_result.first_remote
            else "rm1: -"
        )

        second_remote = (
            ("rm2: %.4f" % energy_scan_result.second_remote)
            if energy_scan_result.second_remote
            else "rm2: -"
        )

        self.acq_widget_layout.energies_combo.addItems(
            [inflection, peak, first_remote, second_remote]
        )

    def energy_selected(self, index):
        if self.acq_widget_layout.mad_cbox.isChecked():
            (name, energy) = self.get_mad_energy()
            if energy != 0:
                self.update_energy(energy)

            self.madEnergySelectedSignal.emit(name, energy, True)

    def energy_ledit_changed(self, new_value):
        if "energy" not in self.value_changed_list:
            self.value_changed_list.append("energy")
        self.emit_acq_parameters_changed()

    def update_energy(self, energy):
        if (
            "energy" not in self.value_changed_list
            and not self.acq_widget_layout.energy_ledit.hasFocus()
        ):
            self.acq_widget_layout.energy_ledit.setText(str(energy))
        self.emit_acq_parameters_changed()

    def transmission_ledit_changed(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.value_changed_list.append("transmission")
        self.emit_acq_parameters_changed()

    def update_transmission(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.acq_widget_layout.transmission_ledit.setText(str(transmission))
        self.emit_acq_parameters_changed()

    def resolution_ledit_changed(self, resolution):
        if "resolution" not in self.value_changed_list:
            self.value_changed_list.append("resolution")
        self.emit_acq_parameters_changed()

    def update_resolution(self, resolution):
        if (
            "resolution" not in self.value_changed_list
            and not self.acq_widget_layout.resolution_ledit.hasFocus()
        ):
            self.acq_widget_layout.resolution_ledit.setText(str(resolution))
        self.emit_acq_parameters_changed()

    def update_energy_limits(self, limits):
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(
                "Energy limits %0.4f : %0.4f keV\n" % (limits[0], limits[1])
                + "4 digits precision."
            )
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(
                "Transmission limits %0.2f : %0.2f %%\n" % (limits[0], limits[1])
                + "2 digits precision."
            )
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
                "Resolution limits %0.4f : %0.4f %s\n"
                % (limits[0], limits[1], chr(197))
                + "4 digits precision."
            )
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        if limits:
            self.exp_time_validator.setRange(limits[0], limits[1], 6)
            self.acq_widget_layout.exp_time_ledit.setToolTip(
                "Exposure time limits %0.6f s : %0.1f s\n" % (limits[0], limits[1])
                + "6 digits precision."
            )
            self._acquisition_mib.validate_all()

    def update_num_images_limits(self, num_images_limits=None):
        """Updates number of images limit. Method used if plate mode.
        """

        self._acquisition_mib.validate_all()

        return
        if HWR.beamline.diffractometer.in_plate_mode():
            if num_images_limits is None:
                try:
                    osc_start = float(self.acq_widget_layout.osc_start_ledit.text())
                    osc_range = float(self.acq_widget_layout.osc_range_ledit.text())
                except ValueError:
                    return

                if osc_range == 0:
                    return

                num_images_limits = int(
                    (self.osc_start_validator.top() - osc_start) / osc_range
                )

            self.num_img_validator.setTop(num_images_limits)
            self.acq_widget_layout.num_images_ledit.setToolTip(
                "Number of images limits : %d" % num_images_limits
            )
            self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        roi_modes = HWR.beamline.detector.get_roi_modes()
        if (
            len(roi_modes) > 0
            and self.acq_widget_layout.detector_roi_mode_combo.count() == 0
        ):
            for roi_mode in roi_modes:
                self.acq_widget_layout.detector_roi_mode_combo.addItem(roi_mode)
            self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
            self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)

    def update_detector_roi_mode(self, roi_mode_index):
        if (
            roi_mode_index is not None
            and self.acq_widget_layout.detector_roi_mode_combo.count() > 0
        ):
            self.acq_widget_layout.detector_roi_mode_combo.setCurrentIndex(
                roi_mode_index
            )

    def detector_roi_mode_changed(self, roi_mode_index):
        HWR.beamline.detector.set_roi_mode(roi_mode_index)

    def kappa_ledit_changed(self, new_value):
        if "kappa" not in self.value_changed_list:
            self.value_changed_list.append("kappa")
        self.emit_acq_parameters_changed()

    def kappa_phi_ledit_changed(self, new_value):
        if "kappa_phi" not in self.value_changed_list:
            self.value_changed_list.append("kappa_phi")
        self.emit_acq_parameters_changed()

    def update_data_model(self, acquisition_parameters, path_template):
        self._acquisition_parameters = acquisition_parameters
        self._path_template = path_template
        self._acquisition_mib.set_model(acquisition_parameters)

        # Update mad widgets
        mad = True if self._path_template.mad_prefix != "" else False
        if mad:
            mad_prefix = str(self._path_template.mad_prefix)
            index = MAD_ENERGY_COMBO_NAMES[str(mad_prefix)]
            self.acq_widget_layout.energies_combo.setCurrentIndex(index)
            self.acq_widget_layout.mad_cbox.setChecked(True)
            self.acq_widget_layout.energies_combo.setEnabled(True)
        else:
            self.acq_widget_layout.mad_cbox.setChecked(False)
            self.acq_widget_layout.energies_combo.setEnabled(False)
            self.acq_widget_layout.energies_combo.setCurrentIndex(0)

        self.update_osc_total_range()
        self.update_total_exp_time()

        self.emit_acq_parameters_changed()

    def set_tunable_energy(self, state):
        self.acq_widget_layout.energy_ledit.setEnabled(state)
        self.acq_widget_layout.mad_cbox.setEnabled(state)
        self.acq_widget_layout.energies_combo.setEnabled(state)

    def check_parameter_conflict(self):
        return self._acquisition_mib.validate_all()

    def emit_acq_parameters_changed(self):
        self.acqParametersChangedSignal.emit(self._acquisition_mib.validate_all())
Beispiel #11
0
class CharParametersWidget(qt_import.QWidget):
    def __init__(self, parent=None, name="char_parameter_widget"):

        qt_import.QWidget.__init__(self, parent)

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._char = None
        self._char_params = queue_model_objects.CharacterisationParameters()
        self._char_params_mib = DataModelInputBinder(self._char_params)
        self._tree_view_item = None
        self.previous_energy = None

        self.add_dc_cb = None

        # Graphic elements ----------------------------------------------------
        main_widget = qt_import.QWidget(self)
        rone_widget = qt_import.QWidget(main_widget)
        self.reference_img_widget = ReferenceImageWidget(rone_widget)
        self.acq_widget = self.reference_img_widget.acq_widget
        self.path_widget = self.reference_img_widget.path_widget
        self.position_widget = qt_import.load_ui_file(
            "snapshot_widget_layout.ui")
        self.position_widget.setMinimumSize(450, 340)

        rtwo_widget = qt_import.QWidget(main_widget)
        self.char_type_widget = CharTypeWidget(rtwo_widget)
        self.routine_dc_widget = self.char_type_widget.routine_dc_page
        self.sad_widget = self.char_type_widget.sad_page
        self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page
        self.opt_parameters_widget = OptimisationParametersWidgetLayout(self)

        rtree_widget = qt_import.QWidget(main_widget)
        self.rad_dmg_widget = qt_import.load_ui_file(
            "radiation_damage_model_widget_layout.ui")
        self.vertical_dimension_widget = qt_import.load_ui_file(
            "vertical_crystal_dimension_widget_layout.ui")

        # Layout --------------------------------------------------------------
        rone_widget_layout = qt_import.QHBoxLayout(rone_widget)
        rone_widget_layout.addWidget(self.reference_img_widget)
        rone_widget_layout.addWidget(self.position_widget)
        # rone_widget_layout.addStretch(0)
        rone_widget_layout.setSpacing(2)
        rone_widget_layout.setContentsMargins(0, 0, 0, 0)

        rtwo_widget_layout = qt_import.QHBoxLayout(rtwo_widget)
        rtwo_widget_layout.addWidget(self.char_type_widget)
        rtwo_widget_layout.addWidget(self.opt_parameters_widget)
        rtwo_widget_layout.addStretch(0)
        rtwo_widget_layout.setSpacing(2)
        rtwo_widget_layout.setContentsMargins(0, 0, 0, 0)

        rtree_widget_layout = qt_import.QHBoxLayout(rtree_widget)
        rtree_widget_layout.addWidget(self.rad_dmg_widget)
        rtree_widget_layout.addWidget(self.vertical_dimension_widget)
        rtree_widget_layout.addStretch(10)
        rtree_widget_layout.setSpacing(2)
        rtree_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_widget_vlayout = qt_import.QVBoxLayout(main_widget)
        _main_widget_vlayout.addWidget(rone_widget)
        _main_widget_vlayout.addWidget(rtwo_widget)
        _main_widget_vlayout.addWidget(rtree_widget)
        _main_widget_vlayout.addStretch(10)
        _main_widget_vlayout.setSpacing(2)
        _main_widget_vlayout.setContentsMargins(0, 0, 0, 0)

        _main_hlayout = qt_import.QHBoxLayout(self)
        _main_hlayout.addWidget(main_widget)
        _main_hlayout.setSpacing(0)
        _main_hlayout.addStretch(0)
        _main_hlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies -------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.toggle_permitted_range(
            self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.
            isChecked())

        self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.toggled.connect(
            self.toggle_permitted_range)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            "min_dose",
            self.routine_dc_widget.dose_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_time",
            self.routine_dc_widget.time_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "use_min_dose", self.routine_dc_widget.min_dose_radio, bool, None)

        self._char_params_mib.bind_value_update(
            "use_min_time", self.routine_dc_widget.min_time_radio, bool, None)

        self._char_params_mib.bind_value_update(
            "account_rad_damage",
            self.routine_dc_widget.radiation_damage_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "auto_res", self.sad_widget.automatic_resolution_radio, bool, None)

        self._char_params_mib.bind_value_update(
            "sad_res",
            self.sad_widget.sad_resolution_ledit,
            float,
            qt_import.QDoubleValidator(0.5, 20, 3, self),
        )

        self._char_params_mib.bind_value_update(
            "opt_sad", self.sad_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            "determine_rad_params", self.rad_dmg_char_widget.rad_damage_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            "burn_osc_start",
            self.rad_dmg_char_widget.burn_osc_start_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "burn_osc_interval",
            self.rad_dmg_char_widget.burn_osc_interval_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "use_aimed_resolution",
            self.opt_parameters_widget.opt_param_widget.maximum_res_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "use_aimed_multiplicity",
            self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "aimed_resolution",
            self.opt_parameters_widget.opt_param_widget.maximum_res_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "aimed_multiplicity",
            self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "aimed_i_sigma",
            self.opt_parameters_widget.opt_param_widget.i_over_sigma_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "aimed_completness",
            self.opt_parameters_widget.opt_param_widget.aimed_comp_ledit,
            float,
            qt_import.QDoubleValidator(0.01, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "strategy_complexity",
            self.opt_parameters_widget.opt_param_widget.start_comp_cbox,
            int,
            None,
        )

        self._char_params_mib.bind_value_update(
            "use_permitted_rotation",
            self.opt_parameters_widget.opt_param_widget.permitted_range_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "permitted_phi_start",
            self.opt_parameters_widget.opt_param_widget.phi_start_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "permitted_phi_end",
            self.opt_parameters_widget.opt_param_widget.phi_end_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "low_res_pass_strat",
            self.opt_parameters_widget.opt_param_widget.low_res_pass_cbx,
            bool,
            None,
        )

        self._char_params_mib.bind_value_update(
            "rad_suscept",
            self.rad_dmg_widget.sensetivity_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "beta",
            self.rad_dmg_widget.beta_over_gray_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "gamma",
            self.rad_dmg_widget.gamma_over_gray_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "max_crystal_vdim",
            self.vertical_dimension_widget.max_vdim_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_crystal_vdim",
            self.vertical_dimension_widget.min_vdim_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_crystal_vphi",
            self.vertical_dimension_widget.min_vphi_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "max_crystal_vphi",
            self.vertical_dimension_widget.max_vphi_ledit,
            float,
            qt_import.QDoubleValidator(0.0, 1000, 2, self),
        )

        # self._char_params_mib.bind_value_update('space_group',
        #                                        self.vertical_dimension_widget.space_group_ledit,
        #                                        str,
        #                                        None)

        self.vertical_dimension_widget.space_group_ledit.addItems(
            queue_model_enumerables.XTAL_SPACEGROUPS)

        self.char_type_widget.charact_type_tbox.currentChanged.connect(
            self.update_char_type)
        self.rad_dmg_char_widget.rad_damage_cbx.toggled.connect(
            self.enable_opt_parameters_widget)
        self.opt_parameters_widget.opt_param_widget.maximum_res_cbx.toggled.connect(
            self.enable_maximum_res_ledit)
        self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx.toggled.connect(
            self.enable_aimed_mult_ledit)
        self.path_widget.data_path_layout.prefix_ledit.textChanged.connect(
            self._prefix_ledit_change)
        self.path_widget.data_path_layout.run_number_ledit.textChanged.connect(
            self._run_number_ledit_change)
        self.vertical_dimension_widget.space_group_ledit.activated.connect(
            self._space_group_change)

    def _space_group_change(self, index):
        """
        Descript. :
        """
        self._char_params.space_group = queue_model_enumerables.XTAL_SPACEGROUPS[
            index]

    def _set_space_group(self, space_group):
        """
        Descript. :
        """
        index = 0

        if space_group in queue_model_enumerables.XTAL_SPACEGROUPS:
            index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group)

        self._space_group_change(index)
        self.vertical_dimension_widget.space_group_ledit.setCurrentIndex(index)

    def _prefix_ledit_change(self, new_value):
        """
        Descript. :
        """
        prefix = self._data_collection.acquisitions[
            0].path_template.get_prefix()
        self._char.set_name(prefix)
        self._tree_view_item.setText(0, self._char.get_name())

    def _run_number_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self._char.set_number(int(new_value))
            self._tree_view_item.setText(0, self._char.get_name())

    def enable_aimed_mult_ledit(self, state):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit.setEnabled(
            state)

    def enable_maximum_res_ledit(self, state):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.maximum_res_ledit.setEnabled(
            state)

    def update_char_type(self, index):
        """
        Descript. :
        """
        self._char_params.experiment_type = index

    def toggle_permitted_range(self, status):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.phi_start_ledit.setEnabled(
            status)
        self.opt_parameters_widget.opt_param_widget.phi_end_ledit.setEnabled(
            status)

    def enable_opt_parameters_widget(self, state):
        """
        Descript. :
        """
        if not self._char.is_executed():
            self.opt_parameters_widget.setEnabled(not state)
        else:
            self.opt_parameters_widget.setEnabled(False)

    def set_enabled(self, state):
        """
        Descript. :
        """
        self.char_type_widget.setEnabled(state)
        self.routine_dc_widget.setEnabled(state)
        self.sad_widget.setEnabled(state)
        self.rad_dmg_char_widget.setEnabled(state)
        self.reference_img_widget.setEnabled(state)
        self.acq_widget.setEnabled(state)
        self.path_widget.setEnabled(state)
        self.opt_parameters_widget.setEnabled(state)
        self.rad_dmg_widget.setEnabled(state)
        self.vertical_dimension_widget.setEnabled(state)

    def populate_parameter_widget(self, tree_view_item):
        """
        Descript. :
        """
        self._tree_view_item = tree_view_item
        self._char = tree_view_item.get_model()
        self._data_collection = self._char.reference_image_collection
        self._char_params = self._char.characterisation_parameters
        self._char_params_mib.set_model(self._char.characterisation_parameters)
        self._set_space_group(self._char_params.space_group)

        self.acq_widget.update_data_model(
            self._char.reference_image_collection.acquisitions[0].
            acquisition_parameters,
            self._char.reference_image_collection.acquisitions[0].
            path_template,
        )

        self.path_widget.update_data_model(
            self._char.reference_image_collection.acquisitions[0].path_template
        )

        if self._data_collection.acquisitions[
                0].acquisition_parameters.centred_position.snapshot_image:
            image = self._data_collection.acquisitions[
                0].acquisition_parameters.centred_position.snapshot_image
            ration = image.height() / float(image.width())
            image = image.scaled(
                400,
                400 * ration,
                qt_import.Qt.KeepAspectRatio,
                qt_import.Qt.SmoothTransformation,
            )
            self.position_widget.svideo.setPixmap(qt_import.QPixmap(image))

        self.toggle_permitted_range(self._char_params.use_permitted_rotation)
        self.enable_opt_parameters_widget(
            self._char_params.determine_rad_params)
        self.enable_maximum_res_ledit(self._char_params.use_aimed_resolution)
        self.enable_aimed_mult_ledit(self._char_params.use_aimed_multiplicity)

        item = self.char_type_widget.charact_type_tbox.widget(
            self._char_params.experiment_type)
        if item:
            self.char_type_widget.charact_type_tbox.setCurrentWidget(item)
        self.char_type_widget.toggle_time_dose()
        crystal = self._char.reference_image_collection.crystal
        self.acq_widget.set_energies(crystal.energy_scan_result)
Beispiel #12
0
    def __init__(self, parent=None, name=None, fl=0):

        CreateTaskBase.__init__(self, parent, name, fl, "Characterisation")
        self.setObjectName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._vertical_dimension_widget = None
        self._current_selected_item = None
        self._char = None
        self._char_params = None

        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)

        # Graphic elements ----------------------------------------------------
        self._acq_widget = AcquisitionWidgetSimple(
            self,
            acq_params=self._acquisition_parameters,
            path_template=self._path_template,
        )

        self._data_path_widget = DataPathWidget(self,
                                                data_model=self._path_template,
                                                layout="vertical")

        self._vertical_dimension_widget = qt_import.load_ui_file(
            "vertical_crystal_dimension_widget_layout.ui")

        self._char_widget = qt_import.load_ui_file(
            "characterise_simple_widget_vertical_layout.ui")

        # Layout --------------------------------------------------------------
        _main_vlayout = qt_import.QVBoxLayout(self)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.setSpacing(6)
        _main_vlayout.addStretch(0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.connect(
            self.path_template_changed)
        self._acq_widget.acqParametersChangedSignal.connect(
            self.acq_parameters_changed)

        self._vertical_dimension_widget.space_group_ledit.activated.connect(
            self._space_group_change)

        self._char_widget.characterisation_gbox.toggled.connect(
            self.characterisation_gbox_toggled)
        self._char_widget.wait_result_cbx.toggled.connect(
            self.wait_results_cbx_toggled)
        self._char_widget.execute_plan_cbx.toggled.connect(
            self.run_diffraction_plan_cbx_toggled)

        # Other ---------------------------------------------------------------
        if True:
            self._char_params_mib.bind_value_update(
                "opt_sad", self._char_widget.optimised_sad_cbx, bool, None)

            self._char_params_mib.bind_value_update(
                "account_rad_damage", self._char_widget.account_rad_dmg_cbx,
                bool, None)

            self._char_params_mib.bind_value_update(
                "strategy_complexity", self._char_widget.start_comp_cbox, int,
                None)

            self._char_params_mib.bind_value_update(
                "max_crystal_vdim",
                self._vertical_dimension_widget.max_vdim_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

            self._char_params_mib.bind_value_update(
                "min_crystal_vdim",
                self._vertical_dimension_widget.min_vdim_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

            self._char_params_mib.bind_value_update(
                "min_crystal_vphi",
                self._vertical_dimension_widget.min_vphi_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

            self._char_params_mib.bind_value_update(
                "max_crystal_vphi",
                self._vertical_dimension_widget.max_vphi_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

        self._vertical_dimension_widget.space_group_ledit.addItems(
            XTAL_SPACEGROUPS)

        self._data_path_widget.data_path_layout.compression_cbox.setVisible(
            False)
Beispiel #13
0
class CreateCharWidget(CreateTaskBase):
    def __init__(self, parent=None, name=None, fl=0):

        CreateTaskBase.__init__(self, parent, name, fl, "Characterisation")
        self.setObjectName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._vertical_dimension_widget = None
        self._current_selected_item = None
        self._char = None
        self._char_params = None

        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)

        # Graphic elements ----------------------------------------------------
        self._acq_widget = AcquisitionWidgetSimple(
            self,
            acq_params=self._acquisition_parameters,
            path_template=self._path_template,
        )

        self._data_path_widget = DataPathWidget(self,
                                                data_model=self._path_template,
                                                layout="vertical")

        self._vertical_dimension_widget = qt_import.load_ui_file(
            "vertical_crystal_dimension_widget_layout.ui")

        self._char_widget = qt_import.load_ui_file(
            "characterise_simple_widget_vertical_layout.ui")

        # Layout --------------------------------------------------------------
        _main_vlayout = qt_import.QVBoxLayout(self)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.setSpacing(6)
        _main_vlayout.addStretch(0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.connect(
            self.path_template_changed)
        self._acq_widget.acqParametersChangedSignal.connect(
            self.acq_parameters_changed)

        self._vertical_dimension_widget.space_group_ledit.activated.connect(
            self._space_group_change)

        self._char_widget.characterisation_gbox.toggled.connect(
            self.characterisation_gbox_toggled)
        self._char_widget.wait_result_cbx.toggled.connect(
            self.wait_results_cbx_toggled)
        self._char_widget.execute_plan_cbx.toggled.connect(
            self.run_diffraction_plan_cbx_toggled)

        # Other ---------------------------------------------------------------
        if True:
            self._char_params_mib.bind_value_update(
                "opt_sad", self._char_widget.optimised_sad_cbx, bool, None)

            self._char_params_mib.bind_value_update(
                "account_rad_damage", self._char_widget.account_rad_dmg_cbx,
                bool, None)

            self._char_params_mib.bind_value_update(
                "strategy_complexity", self._char_widget.start_comp_cbox, int,
                None)

            self._char_params_mib.bind_value_update(
                "max_crystal_vdim",
                self._vertical_dimension_widget.max_vdim_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

            self._char_params_mib.bind_value_update(
                "min_crystal_vdim",
                self._vertical_dimension_widget.min_vdim_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

            self._char_params_mib.bind_value_update(
                "min_crystal_vphi",
                self._vertical_dimension_widget.min_vphi_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

            self._char_params_mib.bind_value_update(
                "max_crystal_vphi",
                self._vertical_dimension_widget.max_vphi_ledit,
                float,
                qt_import.QDoubleValidator(0.0, 1000, 2, self),
            )

        self._vertical_dimension_widget.space_group_ledit.addItems(
            XTAL_SPACEGROUPS)

        self._data_path_widget.data_path_layout.compression_cbox.setVisible(
            False)

    def enable_compression(self, state):
        CreateTaskBase.enable_compression(self, False)

    def use_induced_burn(self, state):
        self._acquisition_parameters.induce_burn = state

    def _space_group_change(self, index):
        self._char_params.space_group = queue_model_enumerables.XTAL_SPACEGROUPS[
            index]

    def _set_space_group(self, space_group):
        index = 0

        if self._vertical_dimension_widget:
            if space_group in XTAL_SPACEGROUPS:
                index = XTAL_SPACEGROUPS.index(space_group)

            self._space_group_change(index)
            self._vertical_dimension_widget.space_group_ledit.setCurrentIndex(
                index)

    def init_models(self):
        CreateTaskBase.init_models(self)
        self._init_models()

    def _init_models(self):
        self._char = queue_model_objects.Characterisation()
        self._char_params = self._char.characterisation_parameters
        self._processing_parameters = queue_model_objects.ProcessingParameters(
        )
        self._set_space_group(self._processing_parameters.space_group)

        self._acquisition_parameters = (
            HWR.beamline.get_default_acquisition_parameters("default"))

        self._char_params = (HWR.beamline.characterisation.
                             get_default_characterisation_parameters())
        self._path_template.reference_image_prefix = "ref"
        # The num images drop down default value is 1
        # we would like it to be 2
        self._acquisition_parameters.num_images = 2
        self._char.characterisation_software = (
            queue_model_enumerables.COLLECTION_ORIGIN.EDNA)
        self._path_template.num_files = 2
        self._path_template.compression = False
        self._acquisition_parameters.shutterless = False

    def single_item_selection(self, tree_item):
        CreateTaskBase.single_item_selection(self, tree_item)

        if isinstance(tree_item, queue_item.SampleQueueItem):
            if self._char_params.space_group == "":
                sample_model = tree_item.get_model()
                self._set_space_group(
                    sample_model.processing_parameters.space_group)
        elif isinstance(tree_item, queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, queue_item.CharacterisationQueueItem):
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            self._char = tree_item.get_model()

            if self._char.get_path_template():
                self._path_template = self._char.get_path_template()

            self._data_path_widget.update_data_model(self._path_template)

            data_collection = self._char.reference_image_collection

            self._char_params = self._char.characterisation_parameters
            self._char_params_mib.set_model(self._char_params)

            self._acquisition_parameters = data_collection.acquisitions[
                0].acquisition_parameters

            self._acq_widget.update_data_model(self._acquisition_parameters,
                                               self._path_template)
            # self.get_acquisition_widget().use_osc_start(True)

            if len(data_collection.acquisitions) == 1:
                HWR.beamline.sample_view.select_shape_with_cpos(
                    self._acquisition_parameters.centred_position)

            self._processing_parameters = data_collection.processing_parameters
        else:
            self.setDisabled(True)

    def update_processing_parameters(self, crystal):
        self._processing_parameters.space_group = crystal.space_group
        self._char_params.space_group = crystal.space_group
        self._processing_parameters.cell_a = crystal.cell_a
        self._processing_parameters.cell_alpha = crystal.cell_alpha
        self._processing_parameters.cell_b = crystal.cell_b
        self._processing_parameters.cell_beta = crystal.cell_beta
        self._processing_parameters.cell_c = crystal.cell_c
        self._processing_parameters.cell_gamma = crystal.cell_gamma

    def approve_creation(self):
        result = CreateTaskBase.approve_creation(self)
        selected_shapes = HWR.beamline.sample_view.get_selected_shapes()

        for shape in selected_shapes:
            if isinstance(shape, GraphicsItemPoint):
                result = True
        return result

    # Called by the owning widget (task_toolbox_widget) to create
    # a collection. when a data collection group is selected.
    def _create_task(self, sample, shape, comments=None):
        tasks = []

        if not shape or not isinstance(shape, GraphicsItemPoint):
            cpos = queue_model_objects.CentredPosition()
            cpos.snapshot_image = HWR.beamline.sample_view.get_snapshot()
        else:
            # Shapes selected and sample is mounted, get the
            # centred positions for the shapes
            snapshot = HWR.beamline.sample_view.get_snapshot(shape)
            cpos = copy.deepcopy(shape.get_centred_position())
            cpos.snapshot_image = snapshot

        char_params = copy.deepcopy(self._char_params)
        acq = self._create_acq(sample)
        dc = queue_model_objects.DataCollection([acq], sample.crystals[0],
                                                self._processing_parameters)

        # Reference images for characterisations should be taken 90 deg apart
        # this is achived by setting overap to -89
        acq.acquisition_parameters.overlap = -89
        acq.acquisition_parameters.centred_position = cpos

        if comments:
            acq.acquisition_parameters.comments = comments

        dc.acquisitions[0] = acq
        dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.EDNA_REF
        dc.run_online_processing = False

        char = queue_model_objects.Characterisation(dc, char_params)
        char.set_name(dc.acquisitions[0].path_template.get_prefix())
        char.set_number(dc.acquisitions[0].path_template.run_number)
        char.run_characterisation = self._char_widget.characterisation_gbox.isChecked(
        )
        char.wait_result = self._char_widget.wait_result_cbx.isChecked()
        char.run_diffraction_plan = self._char_widget.execute_plan_cbx.isChecked(
        )
        char.diff_plan_compression = self._tree_brick.compression_state

        tasks.append(char)
        self._path_template.run_number += 1

        if HWR.beamline.flux.get_value() < 1e9:
            logging.getLogger("GUI").error(
                "No flux reading is available! " +
                "Characterisation result may be wrong. "
                "Measure flux before running the characterisation.")

        return tasks

    def characterisation_gbox_toggled(self, state):
        if self._char:
            self._char.run_characterisation = state

    def wait_results_cbx_toggled(self, state):
        if self._char:
            self._char.wait_result = state

    def run_diffraction_plan_cbx_toggled(self, state):
        if self._char:
            self._char.run_diffraction_plan = state
Beispiel #14
0
class AcquisitionSsxWidget(qt_import.QWidget):

    acqParametersChangedSignal = qt_import.pyqtSignal(list)

    def __init__(
        self,
        parent=None,
        name=None,
        fl=0,
        acq_params=None,
        path_template=None,
        layout="vertical",
    ):
        """
        Loads ui file that defines the gui layout.
        Initiates QLineEdits by adding limits, precision
        Connects to qt signals to update acquisition parameters
        :param parent:
        :param name:
        :param fl:
        :param acq_params:
        :param path_template:
        :param layout:
        """

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Internal variables --------------------------------------------------
        self.value_changed_list = []

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters(
            )
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)

        self.acq_widget_layout = qt_import.load_ui_file(
            "acquisition_widget_vertical_ssx_layout.ui")
        # Layout --------------------------------------------------------------
        __main_vlayout = qt_import.QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.num_triggers_ledit.textChanged.connect(
            self.num_triggers_ledit_changed)
        self.acq_widget_layout.num_images_per_trigger_ledit.textChanged.connect(
            self.num_images_per_trigger_ledit_changed)

        self.acq_widget_layout.exp_time_ledit.textChanged.connect(
            self.exposure_time_ledit_changed)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(
            self.detector_roi_mode_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(
            self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(
            self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(
            self.resolution_ledit_changed)

        # Other ---------------------------------------------------------------
        self.energy_validator = qt_import.QDoubleValidator(
            4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = qt_import.QDoubleValidator(
            0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = qt_import.QDoubleValidator(
            0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = qt_import.QDoubleValidator(
            0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.num_triggers_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_triggers_ledit)
        self.num_images_per_trigger_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_images_per_trigger_ledit)
        self.num_img_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_images_ledit)
        self.hare_num_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.hare_num_ledit)

        limits_dict = HWR.beamline.acquisition_limit_values

        tpl = limits_dict.get("exposure_time")
        if tpl:
            self.exp_time_validator.setRange(tpl[0], tpl[1], 6)

        self._acquisition_mib.bind_value_update(
            "exp_time",
            self.acq_widget_layout.exp_time_ledit,
            float,
            self.exp_time_validator,
        )

        self._acquisition_mib.bind_value_update(
            "num_triggers",
            self.acq_widget_layout.num_triggers_ledit,
            int,
            self.num_triggers_validator,
        )

        self._acquisition_mib.bind_value_update(
            "num_images_per_trigger",
            self.acq_widget_layout.num_images_per_trigger_ledit,
            int,
            self.num_images_per_trigger_validator,
        )

        self._acquisition_mib.bind_value_update(
            "hare_num",
            self.acq_widget_layout.hare_num_ledit,
            int,
            self.hare_num_validator,
        )

        tpl = limits_dict.get("number_of_images")
        if tpl:
            self.num_img_validator.setRange(tpl[0], tpl[1])

        self._acquisition_mib.bind_value_update(
            "num_images",
            self.acq_widget_layout.num_images_ledit,
            int,
            self.num_img_validator,
        )

        self._acquisition_mib.bind_value_update(
            "energy", self.acq_widget_layout.energy_ledit, float,
            self.energy_validator)
        self.update_energy_limits(
            (self.energy_validator.bottom(), self.energy_validator.top()))

        self._acquisition_mib.bind_value_update(
            "transmission",
            self.acq_widget_layout.transmission_ledit,
            float,
            self.transmission_validator,
        )
        self.update_transmission_limits((self.transmission_validator.bottom(),
                                         self.transmission_validator.top()))

        self._acquisition_mib.bind_value_update(
            "resolution",
            self.acq_widget_layout.resolution_ledit,
            float,
            self.resolution_validator,
        )

        self.init_detector_roi_modes()
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)
        self.update_exp_time_limits()

    def update_osc_total_range(self):
        """
        :return: None
        """
        return

    def use_osc_start(self, status):
        """
        :param status: boolean
        :return: None
        """
        return

    def use_max_osc_range(self, status):
        """
        :param status: boolean
        :return: None
        """
        return

    def use_kappa(self, status):
        """
        :param status: boolean
        :return: None
        """
        return

    def exposure_time_ledit_changed(self, value):
        """
        Updates exposure time QLineEdit
        :param value: str
        :return: None
        """
        self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def energy_ledit_changed(self, value):
        """
        Fixes energy value. Energy change will not rewrite the typed energy value
        :param value: str
        :return: None
        """
        if "energy" not in self.value_changed_list:
            self.value_changed_list.append("energy")
        self.emit_acq_parameters_changed()

    def update_energy(self, energy):
        """
        Updates energy QLineEdit
        :param energy: energy in keV (float)
        :param wav: wavelength in A (float)
        :return: None
        """
        if ("energy" not in self.value_changed_list
                and not self.acq_widget_layout.energy_ledit.hasFocus()):
            self.acq_widget_layout.energy_ledit.setText(str(energy))
        self.emit_acq_parameters_changed()

    def transmission_ledit_changed(self, transmission):
        """
        Event when a value in the transmission QLineEdit is changed
        :param transmission: in perc. (str)
        :return: None
        """
        if "transmission" not in self.value_changed_list:
            self.value_changed_list.append("transmission")
        self.emit_acq_parameters_changed()

    def update_transmission(self, transmission):
        """
        Updates transmission QLineEdit
        :param transmission: in perc. (float)
        :return: None
        """
        if "transmission" not in self.value_changed_list:
            self.acq_widget_layout.transmission_ledit.setText(
                str(transmission))
        self.emit_acq_parameters_changed()

    def resolution_ledit_changed(self, resolution):
        """
        Method called when user changes resolution
        :param resolution: in A (float)
        :return: None
        """
        if "resolution" not in self.value_changed_list:
            self.value_changed_list.append("resolution")
        self.emit_acq_parameters_changed()

    def update_resolution(self, resolution):
        """
        Updates resolution QLineEdit
        :param resolution: A (float)
        :return: None
        """
        if ("resolution" not in self.value_changed_list
                and not self.acq_widget_layout.resolution_ledit.hasFocus()):
            self.acq_widget_layout.resolution_ledit.setText(str(resolution))
        self.emit_acq_parameters_changed()

    def update_energy_limits(self, limits):
        """
        Updates energy limits
        :param limits: list of two floats
        :return: None
        """
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(
                "Energy limits %0.4f : %0.4f keV\n" % (limits[0], limits[1]) +
                "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        """
        Updates transmission limits
        :param limits: list of two floats
        :return: None
        """
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(
                "Transmission limits %0.2f : %0.2f %%\n" %
                (limits[0], limits[1]) + "2 digits precision.")
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        """
        Updates resolution limits
        :param limits: list of two floats
        :return: None
        """
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
                "Resolution limits %0.4f : %0.4f %s\n" %
                (limits[0], limits[1], chr(197)) + "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        """
        Updates exposure time limits
        :param limits: list of two floats
        :return: None
        """
        if limits:
            self.exp_time_validator.setRange(limits[0], limits[1], 6)
            self.acq_widget_layout.exp_time_ledit.setToolTip(
                "Exposure time limits %0.6f s : %0.1f s\n" %
                (limits[0], limits[1]) + "6 digits precision.")
            self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        """
        Initiates detetor ROI modes. Available modes are added to the combobox
        :return: None
        """
        roi_modes = HWR.beamline.detector.get_roi_modes()
        if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
            for roi_mode in roi_modes:
                self.acq_widget_layout.detector_roi_mode_combo.addItem(
                    roi_mode)
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(
            len(roi_modes) > 1)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(
            len(roi_modes) > 1)

    def update_detector_roi_mode(self, roi_mode_index):
        """
        Method called when roi mode has been chaned
        :param roi_mode_index: int
        :return: None
        """
        if (roi_mode_index is not None and
                self.acq_widget_layout.detector_roi_mode_combo.count() > 0):
            self.acq_widget_layout.detector_roi_mode_combo.setCurrentIndex(
                roi_mode_index)

    def detector_roi_mode_changed(self, roi_mode_index):
        """
        Method called when user selects a detector roi mode
        :param roi_mode_index: int
        :return:
        """
        HWR.beamline.detector.set_roi_mode(roi_mode_index)

    def update_osc_range_per_frame_limits(self):
        """
        Updates osc range per frame limits
        :return: None
        """
        return

    def update_exp_time_limits(self):
        self.update_detector_exp_time_limits(
            HWR.beamline.detector.get_exposure_time_limits())

    def update_osc_start(self, value):
        """
        Updates osc start
        :param value: float
        :return: None
        """
        return

    def update_kappa(self, value):
        """
        Updates kappa value
        :param value: float
        :return:
        """
        return

    def update_kappa_phi(self, value):
        """
        Updates kappa phi value
        :param value: float
        :return: None
        """
        return

    def update_data_model(self, acquisition_parameters, path_template):
        """
        Updates data model
        :param acquisition_parameters: AcquisitionParameters
        :param path_template: PathTemplate
        :return: None
        """
        self._acquisition_parameters = acquisition_parameters
        self._path_template = path_template
        self._acquisition_mib.set_model(acquisition_parameters)
        self.emit_acq_parameters_changed()

    def check_parameter_conflict(self):
        """
        Checks for parameter conflicts
        :return: list of conflicts
        """
        return self._acquisition_mib.validate_all()

    def emit_acq_parameters_changed(self):
        """
        Emits acqParametersChangedSignal
        :return: None
        """
        self.acqParametersChangedSignal.emit(
            self._acquisition_mib.validate_all())

    def set_energies(self, energies):
        """
        Sets energies
        :param energies:
        :return: None
        """
        return

    def num_triggers_ledit_changed(self, value):
        """
        Updates num images and total exp time
        :param value: QString
        :return: None
        """
        if "num_triggers" not in self.value_changed_list:
            self.value_changed_list.append("num_triggers")
        self.update_num_images()
        self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def num_images_per_trigger_ledit_changed(self, value):
        """
                Updates num images and total exp time
                :param value: QString
                :return: None
                """
        if "num_images_per_trigger" not in self.value_changed_list:
            self.value_changed_list.append("num_images_per_trigger")
        self.update_num_images()
        self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def update_num_images(self):
        """
        Updates num images
        :return: None
        """
        self.acq_widget_layout.num_images_ledit.setText(
            str(self._acquisition_parameters.num_triggers *
                self._acquisition_parameters.num_images_per_trigger))

    def update_total_exp_time(self):
        """Updates total exposure time
        :return: None
        """
        try:
            self.acq_widget_layout.exp_time_total_ledit.setText(
                "%.2f" %
                (float(self.acq_widget_layout.exp_time_ledit.text()) *
                 float(self.acq_widget_layout.num_images_ledit.text())))
        except BaseException:
            pass
Beispiel #15
0
    def __init__(self, *args):

        BaseWidget.__init__(self, *args)

        # Internal variables ------------------------------------------------
        self.sample = queue_model_objects.Sample()
        self.crystal = self.sample.crystals[0]
        self.sample_mib = DataModelInputBinder(self.sample)
        self.crystal_mib = DataModelInputBinder(self.crystal)

        # Signals ------------------------------------------------------------

        # Slots --------------------------------------------------------------
        self.define_slot("populate_sample_details", ({}))

        # Graphic elements ----------------------------------------------------
        _info_widget = qt_import.QWidget(self)
        self.crystal_widget = qt_import.load_ui_file("crystal_widget_layout.ui")
        self.sample_info_widget = qt_import.load_ui_file("sample_info_widget_layout.ui")
        # self.ispyb_sample_info_widget = ISPyBSampleInfoWidget(self)

        # Layout --------------------------------------------------------------
        _info_widget_hlayout = qt_import.QHBoxLayout(_info_widget)
        _info_widget_hlayout.addWidget(self.sample_info_widget)
        _info_widget_hlayout.addWidget(self.crystal_widget)
        _info_widget_hlayout.addStretch(0)
        _info_widget_hlayout.setSpacing(0)
        _info_widget_hlayout.setContentsMargins(2, 2, 2, 2)

        _main_hlayout = qt_import.QVBoxLayout(self)
        _main_hlayout.addWidget(_info_widget)
        # _main_hlayout.addWidget(self.ispyb_sample_info_widget)
        _main_hlayout.addStretch(0)
        _main_hlayout.setSpacing(0)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------

        # Other ---------------------------------------------------------------
        self.crystal_mib.bind_value_update(
            "space_group", self.crystal_widget.space_group_value_label, str, None
        )

        self.crystal_mib.bind_value_update(
            "protein_acronym",
            self.crystal_widget.protein_acronym_value_label,
            str,
            None,
        )

        self.crystal_mib.bind_value_update(
            "cell_a", self.crystal_widget.a_value_label, str, None
        )

        self.crystal_mib.bind_value_update(
            "cell_alpha", self.crystal_widget.alpha_value_label, str, None
        )

        self.crystal_mib.bind_value_update(
            "cell_b", self.crystal_widget.b_value_label, str, None
        )

        self.crystal_mib.bind_value_update(
            "cell_beta", self.crystal_widget.beta_value_label, str, None
        )

        self.crystal_mib.bind_value_update(
            "cell_c", self.crystal_widget.c_value_label, str, None
        )

        self.crystal_mib.bind_value_update(
            "cell_gamma", self.crystal_widget.gamma_value_label, str, None
        )

        self.sample_mib.bind_value_update(
            "name", self.sample_info_widget.name_value_label, str, None
        )

        self.sample_mib.bind_value_update(
            "code", self.sample_info_widget.data_matrix_value_label, str, None
        )

        self.sample_mib.bind_value_update(
            "holder_length",
            self.sample_info_widget.holder_length_value_label,
            str,
            None,
        )

        self.sample_mib.bind_value_update(
            "lims_sample_location",
            self.sample_info_widget.sample_location_value_label,
            str,
            None,
        )

        self.sample_mib.bind_value_update(
            "lims_container_location",
            self.sample_info_widget.basket_location_value_label,
            str,
            None,
        )
Beispiel #16
0
    def __init__(
        self,
        parent=None,
        name=None,
        fl=0,
        acq_params=None,
        path_template=None,
        layout="vertical",
    ):
        """
        Loads ui file that defines the gui layout.
        Initiates QLineEdits by adding limits, precision
        Connects to qt signals to update acquisition parameters
        :param parent:
        :param name:
        :param fl:
        :param acq_params:
        :param path_template:
        :param layout:
        """

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Internal variables --------------------------------------------------
        self.value_changed_list = []

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters(
            )
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)

        self.acq_widget_layout = qt_import.load_ui_file(
            "acquisition_widget_vertical_ssx_layout.ui")
        # Layout --------------------------------------------------------------
        __main_vlayout = qt_import.QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.num_triggers_ledit.textChanged.connect(
            self.num_triggers_ledit_changed)
        self.acq_widget_layout.num_images_per_trigger_ledit.textChanged.connect(
            self.num_images_per_trigger_ledit_changed)

        self.acq_widget_layout.exp_time_ledit.textChanged.connect(
            self.exposure_time_ledit_changed)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(
            self.detector_roi_mode_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(
            self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(
            self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(
            self.resolution_ledit_changed)

        # Other ---------------------------------------------------------------
        self.energy_validator = qt_import.QDoubleValidator(
            4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = qt_import.QDoubleValidator(
            0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = qt_import.QDoubleValidator(
            0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = qt_import.QDoubleValidator(
            0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.num_triggers_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_triggers_ledit)
        self.num_images_per_trigger_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_images_per_trigger_ledit)
        self.num_img_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.num_images_ledit)
        self.hare_num_validator = qt_import.QIntValidator(
            1, 9999999, self.acq_widget_layout.hare_num_ledit)

        limits_dict = HWR.beamline.acquisition_limit_values

        tpl = limits_dict.get("exposure_time")
        if tpl:
            self.exp_time_validator.setRange(tpl[0], tpl[1], 6)

        self._acquisition_mib.bind_value_update(
            "exp_time",
            self.acq_widget_layout.exp_time_ledit,
            float,
            self.exp_time_validator,
        )

        self._acquisition_mib.bind_value_update(
            "num_triggers",
            self.acq_widget_layout.num_triggers_ledit,
            int,
            self.num_triggers_validator,
        )

        self._acquisition_mib.bind_value_update(
            "num_images_per_trigger",
            self.acq_widget_layout.num_images_per_trigger_ledit,
            int,
            self.num_images_per_trigger_validator,
        )

        self._acquisition_mib.bind_value_update(
            "hare_num",
            self.acq_widget_layout.hare_num_ledit,
            int,
            self.hare_num_validator,
        )

        tpl = limits_dict.get("number_of_images")
        if tpl:
            self.num_img_validator.setRange(tpl[0], tpl[1])

        self._acquisition_mib.bind_value_update(
            "num_images",
            self.acq_widget_layout.num_images_ledit,
            int,
            self.num_img_validator,
        )

        self._acquisition_mib.bind_value_update(
            "energy", self.acq_widget_layout.energy_ledit, float,
            self.energy_validator)
        self.update_energy_limits(
            (self.energy_validator.bottom(), self.energy_validator.top()))

        self._acquisition_mib.bind_value_update(
            "transmission",
            self.acq_widget_layout.transmission_ledit,
            float,
            self.transmission_validator,
        )
        self.update_transmission_limits((self.transmission_validator.bottom(),
                                         self.transmission_validator.top()))

        self._acquisition_mib.bind_value_update(
            "resolution",
            self.acq_widget_layout.resolution_ledit,
            float,
            self.resolution_validator,
        )

        self.init_detector_roi_modes()
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)
        self.update_exp_time_limits()
Beispiel #17
0
class DataPathWidget(qt_import.QWidget):

    pathTemplateChangedSignal = qt_import.pyqtSignal()

    def __init__(self, parent=None, name="", fl=0, data_model=None, layout=None):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)
        self.parent = parent

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._base_image_dir = ""
        self._base_process_dir = ""
        self.path_conflict_state = False
        self.enable_macros = False

        if data_model is None:
            self._data_model = queue_model_objects.PathTemplate()
        else:
            self._data_model = data_model

        self._data_model_pm = DataModelInputBinder(self._data_model)

        # Graphic elements ----------------------------------------------------
        if layout == "vertical":
            self.data_path_layout = qt_import.load_ui_file(
                "data_path_widget_vertical_layout.ui"
            )
        else:
            self.data_path_layout = qt_import.load_ui_file(
                "data_path_widget_horizontal_layout.ui"
            )

        # Layout --------------------------------------------------------------
        _main_vlayout = qt_import.QVBoxLayout(self)
        _main_vlayout.addWidget(self.data_path_layout)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # Qt signal/slot connections ------------------------------------------
        self.data_path_layout.prefix_ledit.textChanged.connect(
            self._prefix_ledit_change
        )
        self.data_path_layout.run_number_ledit.textChanged.connect(
            self._run_number_ledit_change
        )
        self.data_path_layout.browse_button.clicked.connect(self._browse_clicked)
        self.data_path_layout.folder_ledit.textChanged.connect(
            self._folder_ledit_change
        )
        self.data_path_layout.compression_cbox.clicked.connect(
            self._compression_toggled
        )

        # Other ---------------------------------------------------------------
        self._data_model_pm.bind_value_update(
            "base_prefix", self.data_path_layout.prefix_ledit, str, None
        )

        self._data_model_pm.bind_value_update(
            "run_number",
            self.data_path_layout.run_number_ledit,
            int,
            qt_import.QIntValidator(0, 1000, self),
        )

        self._data_model_pm.bind_value_update(
            "compression", self.data_path_layout.compression_cbox, bool, None
        )

    def set_base_image_directory(self, base_image_dir):
        self._base_image_dir = base_image_dir

    def set_base_process_directory(self, base_process_dir):
        self._base_process_dir = base_process_dir

    def _browse_clicked(self):
        file_dialog = qt_import.QFileDialog(self)
        file_dialog.setNameFilter("%s*" % self._base_image_dir)

        selected_dir = str(
            file_dialog.getExistingDirectory(
                self, "Select a directory", str(self._base_image_dir), qt_import.QFileDialog.ShowDirsOnly
            )
        )
        if selected_dir is not None and len(selected_dir) > 0 and selected_dir.startswith(self._base_image_dir):
            self.set_directory(selected_dir)
        else:
            msg = "Selected directory do not start " +\
                  "with the base directory %s" % self._base_image_dir
            logging.getLogger("GUI").error(msg)

    def _prefix_ledit_change(self, new_value):
        cursor_pos = self.data_path_layout.prefix_ledit.cursorPosition()

        if len(new_value) > 0:
            available_chars = (
                string.ascii_lowercase + string.ascii_uppercase + string.digits + "-_"
            )
            if self.enable_macros:
                available_chars += "%"
            new_value = "".join(i for i in str(new_value) if i in available_chars)
            new_value = new_value.replace("\\", "")

        if len(new_value) > 50:
            logging.getLogger("GUI").error(
                "Current prefix is to long (max 50 characters are allowed)"
            )
            new_value = new_value[:-1]

        self.data_path_layout.prefix_ledit.setText(new_value)
        self.data_path_layout.prefix_ledit.setCursorPosition(cursor_pos)

        self._data_model.base_prefix = str(new_value)
        self.update_file_name()
        self.pathTemplateChangedSignal.emit()

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self._data_model.run_number = int(new_value)
            self.data_path_layout.run_number_ledit.setText(str(new_value))

            self.update_file_name()
            self.pathTemplateChangedSignal.emit()
        else:
            # self.data_path_layout.run_number_ledit.setText(str(self._data_model.run_number))
            colors.set_widget_color(
                self.data_path_layout.folder_ledit, colors.LIGHT_YELLOW
            )

    def _folder_ledit_change(self, new_value):
        base_image_dir = self._base_image_dir
        base_proc_dir = self._base_process_dir
        new_sub_dir = str(new_value).strip(" ")

        cursor_pos = self.data_path_layout.folder_ledit.cursorPosition()
        if len(new_value) > 0:
            available_chars = (
                string.ascii_lowercase + string.ascii_uppercase + string.digits + "-_/"
            )
            if self.enable_macros:
                available_chars += "%"
            new_value = "".join(i for i in str(new_value) if i in available_chars)
            # new_value = new_value.replace("\\", "")

        new_sub_dir = str(new_value).strip(" ")
        self.data_path_layout.folder_ledit.setText(new_value)
        self.data_path_layout.folder_ledit.setCursorPosition(cursor_pos)

        if len(new_sub_dir) > 0:
            if new_sub_dir[0] == os.path.sep:
                new_sub_dir = new_sub_dir[1:]
            new_image_directory = os.path.join(base_image_dir, str(new_sub_dir))
            new_proc_dir = os.path.join(base_proc_dir, str(new_sub_dir))
        else:
            new_image_directory = base_image_dir
            new_proc_dir = base_proc_dir

        self._data_model.directory = new_image_directory
        self._data_model.process_directory = new_proc_dir
        colors.set_widget_color(self.data_path_layout.folder_ledit, colors.WHITE)

        self.pathTemplateChangedSignal.emit()

    def _compression_toggled(self, state):
        if hasattr(self.parent, "_tree_brick"):
            if self.parent._tree_brick:
                self.parent._tree_brick.compression_state = state

        queue_model_objects.Characterisation.set_char_compression(state)
        self._data_model.compression = state
        self.update_file_name()
        self.pathTemplateChangedSignal.emit()

    def update_file_name(self):
        """
        updates filename if prefix or run number changed
        at start values are initalized before precision is set.
        so a check for isdigit is done to be on the safe side
        """
        if str(self._data_model.precision).isdigit():
            file_name = self._data_model.get_image_file_name()
            file_name = file_name.replace(
                "%" + str(self._data_model.precision) + "d",
                int(self._data_model.precision) * "#",
            )
            file_name = file_name.strip(" ")
            self.data_path_layout.file_name_value_label.setText(file_name)

    def set_data_path(self, path):
        (dir_name, file_name) = os.path.split(path)
        if self._data_model.precision:
            precision = self._data_model.precision
        else:
            precision = "5"

        self.set_directory(dir_name)
        file_name = file_name.replace(
            "%" + str(self._data_model.precision) + "d",
            int(precision) * "#",
        )
        self.data_path_layout.file_name_value_label.setText(file_name)

    def set_directory(self, directory):
        self._data_model.directory = str(directory)

        if len(directory.split("/")) != len(self._base_image_dir.split("/")):
            dir_parts = directory.split("/")
            sub_dir = os.path.join(*dir_parts[len(self._base_image_dir.split("/")) :])
            self.data_path_layout.folder_ledit.setText(sub_dir)
        else:
            self.data_path_layout.folder_ledit.setText("")
            self._data_model.directory = self._base_image_dir

        self.data_path_layout.base_path_ledit.setText(self._base_image_dir)

    # def set_run_number(self, run_number):
    #    """
    #    Descript. :
    #    """
    #    self._data_model.run_number = int(run_number)
    #    self.data_path_layout.run_number_ledit.setText(str(run_number))

    def set_prefix(self, base_prefix):
        self._data_model.base_prefix = str(base_prefix)
        self.data_path_layout.prefix_ledit.setText(str(base_prefix))
        file_name = self._data_model.get_image_file_name()
        file_name = file_name.replace(
            "%" + str(self._data_model.precision) + "d",
            int(self._data_model.precision) * "#",
        )
        self.data_path_layout.file_name_value_label.setText(file_name)

    def update_data_model(self, data_model):
        self._data_model = data_model
        self.set_data_path(data_model.get_image_path())
        self._data_model_pm.set_model(data_model)
        self.data_path_layout.browse_button.setEnabled(os.path.exists(self._base_image_dir))

    def indicate_path_conflict(self, conflict):
        if conflict:
            colors.set_widget_color(
                self.data_path_layout.prefix_ledit,
                colors.LIGHT_RED,
                qt_import.QPalette.Base,
            )
            colors.set_widget_color(
                self.data_path_layout.run_number_ledit,
                colors.LIGHT_RED,
                qt_import.QPalette.Base,
            )
            colors.set_widget_color(
                self.data_path_layout.folder_ledit,
                colors.LIGHT_RED,
                qt_import.QPalette.Base,
            )

            logging.getLogger("GUI").error(
                "The current path settings will overwrite data "
                + "from another task. Correct the problem before "
                + "adding to queue"
            )
        else:
            # We had a conflict previous, but its corrected now !
            if self.path_conflict_state:
                logging.getLogger("GUI").info("Path valid")

                colors.set_widget_color(
                    self.data_path_layout.prefix_ledit,
                    colors.WHITE,
                    qt_import.QPalette.Base,
                )
                colors.set_widget_color(
                    self.data_path_layout.run_number_ledit,
                    colors.WHITE,
                    qt_import.QPalette.Base,
                )
                colors.set_widget_color(
                    self.data_path_layout.folder_ledit,
                    colors.WHITE,
                    qt_import.QPalette.Base,
                )
        self.path_conflict_state = conflict
Beispiel #18
0
    def __init__(self, parent=None, name=None, fl=0, xray_imaging_params=None):

        qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Internal variables --------------------------------------------------

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        self._xray_imaging_parameters = xray_imaging_params
        self._xray_imaging_mib = DataModelInputBinder(
            self._xray_imaging_parameters)

        self._parameters_widget = qt_import.load_ui_file(
            "xray_imaging_parameters_widget_layout.ui")
        # Layout --------------------------------------------------------------
        __main_vlayout = qt_import.QVBoxLayout(self)
        __main_vlayout.addWidget(self._parameters_widget)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._parameters_widget.ff_pre_cbox.toggled.connect(
            self.ff_pre_toggled)
        self._parameters_widget.ff_post_cbox.toggled.connect(
            self.ff_post_toggled)
        self._parameters_widget.add_button.pressed.connect(
            self.add_distance_pressed)
        self._parameters_widget.remove_button.pressed.connect(
            self.remove_distance_pressed)

        # Other ---------------------------------------------------------------
        # self.detector_distance_validator = qt_import.QIntValidator(
        #     0, 99999, self._parameters_widget.detector_distance_ledit
        # )
        self.detector_distance_validator = qt_import.QDoubleValidator(
            0, 99999, 2, self._parameters_widget.detector_distance_ledit)

        self._xray_imaging_mib.bind_value_update(
            "camera_write_data", self._parameters_widget.store_data_cbox, bool,
            None)

        self._xray_imaging_mib.bind_value_update(
            "ff_pre", self._parameters_widget.ff_pre_cbox, bool, None)

        self._xray_imaging_mib.bind_value_update(
            "ff_post", self._parameters_widget.ff_post_cbox, bool, None)

        self._xray_imaging_mib.bind_value_update(
            "ff_apply", self._parameters_widget.ff_apply_cbox, bool, None)

        self._xray_imaging_mib.bind_value_update(
            "ff_ssim_enabled", self._parameters_widget.ff_ssim_cbox, bool,
            None)

        self._xray_imaging_mib.bind_value_update(
            "ff_num_images", self._parameters_widget.ff_num_images_ledit, int,
            None)

        self._xray_imaging_mib.bind_value_update(
            "sample_offset_a",
            self._parameters_widget.ff_offset_a_ledit,
            float,
            None,
        )

        self._xray_imaging_mib.bind_value_update(
            "sample_offset_b",
            self._parameters_widget.ff_offset_b_ledit,
            float,
            None,
        )

        self._xray_imaging_mib.bind_value_update(
            "sample_offset_c",
            self._parameters_widget.ff_offset_c_ledit,
            float,
            None,
        )

        self._xray_imaging_mib.bind_value_update(
            "detector_distance",
            self._parameters_widget.detector_distance_ledit,
            float,
            self.detector_distance_validator,
        )
Beispiel #19
0
class AdvancedParametersWidget(qt_import.QWidget):
    def __init__(self, parent=None, name="advanced_parameters_widget"):
        qt_import.QWidget.__init__(self, parent)

        # Internal values -----------------------------------------------------
        self._data_collection = None
        self._tree_view_item = None
        self._acquisition_mib = None

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = qt_import.QWidget(self)
        self._data_path_widget = DataPathWidget(_dc_parameters_widget)
        self._acq_widget = AcquisitionWidget(_dc_parameters_widget,
                                             layout="horizontal")

        # Layout --------------------------------------------------------------
        _dc_parameters_widget_layout = qt_import.QVBoxLayout(
            _dc_parameters_widget)
        _dc_parameters_widget_layout.addWidget(self._data_path_widget)
        _dc_parameters_widget_layout.addWidget(self._acq_widget)
        _dc_parameters_widget_layout.setSpacing(2)
        _dc_parameters_widget_layout.addStretch(10)
        _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_hlayout = qt_import.QHBoxLayout(self)
        _main_hlayout.addWidget(_dc_parameters_widget)
        _main_hlayout.setSpacing(2)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)
        _main_hlayout.addStretch(0)

        # Qt signal/slot connections ------------------------------------------
        # self._acq_widget.acqParametersChangedSignal.\
        #     connect(self.acq_parameters_changed)
        # self._data_path_widget.pathTemplateChangedSignal.\
        #     connect(self.acq_parameters_changed)
        self._acq_widget.madEnergySelectedSignal.connect(
            self.mad_energy_selected)

        # Ohter ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.acq_widget_layout.mad_cbox.hide()
        self._acq_widget.acq_widget_layout.energies_combo.hide()
        self._acq_widget.acq_widget_layout.shutterless_cbx.hide()

    def mad_energy_selected(self, name, energy, state):
        path_template = self._data_collection.acquisitions[0].path_template

        if state:
            path_template.mad_prefix = name
        else:
            path_template.mad_prefix = ""

        run_number = HWR.beamline.queue_model.get_next_run_number(
            path_template)

        self._data_path_widget.set_run_number(run_number)
        self._data_path_widget.set_prefix(path_template.base_prefix)
        model = self._tree_view_item.get_model()
        model.set_name(path_template.get_prefix())
        self._tree_view_item.setText(0, model.get_name())

    def populate_widget(self, tree_view_item, data_collection):
        self._tree_view_item = tree_view_item
        self._data_collection = data_collection

        # if isinstance(tree_view_item, queue_item.XrayCenteringQueueItem):
        #    self._data_collection = tree_view_item.get_model().reference_image_collection
        # else:
        #    self._data_collection = tree_view_item.get_model()
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)

        self._acquisition_mib = DataModelInputBinder(
            self._data_collection.acquisitions[0].acquisition_parameters)

        # The acq_widget sends a signal to the path_widget, and it relies
        # on that both models upto date, we need to refactor this part
        # so that both models are set before taking ceratin actions.
        # This workaround, works for the time beeing.
        self._data_path_widget.update_data_model(
            self._data_collection.acquisitions[0].path_template)

        self._acq_widget.update_data_model(
            self._data_collection.acquisitions[0].acquisition_parameters,
            self._data_collection.acquisitions[0].path_template,
        )
        # self._acq_widget.use_osc_start(False)

        self._acq_widget.acq_widget_layout.num_images_ledit.setDisabled(
            data_collection.is_mesh())
        invalid = self._acquisition_mib.validate_all()
        if invalid:
            msg = (
                "This data collection has one or more incorrect parameters," +
                " correct the fields marked in red to solve the problem.")
            logging.getLogger("GUI").warning(msg)