示例#1
0
    def _set_measurement_files(self):
        """Sets up the .cut file list.
        """
        self.tof_list_tree_widget = QtWidgets.QTreeWidget()
        self.tof_list_tree_widget.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        header = QtWidgets.QTreeWidgetItem()
        header.setText(0, "Pre-calculated elements")
        self.gridLayout_2.addWidget(self.tof_list_tree_widget, 0, 1)
        self.tof_list_tree_widget.setHeaderItem(header)

        # Add calculated tof_list files to tof_list_tree_widget by
        # measurement under the same sample.
        for measurement in self.simulation.sample.get_measurements():
            root = QtWidgets.QTreeWidgetItem([measurement.name])

            cuts, elem_loss = measurement.get_cut_files()
            gutils.fill_tree(root,
                             cuts,
                             data_func=lambda c: (c, measurement),
                             text_func=lambda c: c.name)

            self.tof_list_tree_widget.addTopLevelItem(root)

            elem_loss_root = QtWidgets.QTreeWidgetItem(["Element losses"])
            gutils.fill_tree(elem_loss_root,
                             elem_loss,
                             data_func=lambda c: (c, measurement),
                             text_func=lambda c: c.name)
            root.addChild(elem_loss_root)
            root.setExpanded(True)

        self.tof_list_files = {}
示例#2
0
    def _set_simulation_files(self, recoil_widget):
        """Sets up the simulation files in a QTreeWidget.
        """
        header_item = QtWidgets.QTreeWidgetItem()
        header_item.setText(0, "Simulated element (observed atoms)")
        self.treeWidget.setHeaderItem(header_item)

        for elem_sim in self.simulation.element_simulations:
            root = QtWidgets.QTreeWidgetItem(
                [f"{elem_sim.get_full_name()} ({elem_sim.get_atom_count()})"])
            gutils.fill_tree(root,
                             elem_sim.recoil_elements,
                             data_func=lambda rec: (elem_sim, rec, None),
                             text_func=lambda rec: rec.get_full_name())
            if elem_sim.is_optimization_finished():
                gutils.fill_tree(root,
                                 elem_sim.optimization_recoils,
                                 data_func=lambda rec:
                                 (elem_sim, rec, OptimizationType.RECOIL),
                                 text_func=lambda rec: rec.get_full_name())
            self.treeWidget.addTopLevelItem(root)
            root.setExpanded(True)

        self.used_recoil = {(recoil_widget.element_simulation,
                             recoil_widget.recoil_element, None)}
示例#3
0
    def __init__(self, elements: List[Element], ignored_graph: Set[Element],
                 ignored_ratio: Set[Element]):
        """Init the dialog.
        
        Args:
            elements: A list of elements in Depth Profile.
            ignored_graph: A list of elements ignored previously for the graph.
            ignored_ratio: A list of elements ignored previously for ratio
                calculation.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_depth_profile_ignored.ui", self)

        self._elements = sorted(set(elements))
        self.button_ok.clicked.connect(self.accept)
        self.button_cancel.clicked.connect(self.reject)

        # Fill the trees
        gutils.fill_tree(self.tree_elements.invisibleRootItem(),
                         self._elements)
        gutils.fill_tree(self.tree_ratio.invisibleRootItem(), self._elements)

        self.included_in_graph = set(elem for elem in self._elements
                                     if elem not in ignored_graph)
        self.included_in_ratio = set(elem for elem in self._elements
                                     if elem not in ignored_ratio)
示例#4
0
    def __init__(self):
        super().__init__()
        self.spinbox = QtWidgets.QSpinBox()
        self.doubleSpinbox = QtWidgets.QDoubleSpinBox()
        self.textBox = QtWidgets.QTextEdit()
        self.timeEdit = QtWidgets.QTimeEdit()
        self.checkBox = QtWidgets.QCheckBox()
        self.label = QtWidgets.QLabel()
        self.plaintext = QtWidgets.QPlainTextEdit()
        self.not2waySpinBox = QtWidgets.QSpinBox()
        self.scibox = ScientificSpinBox()
        self.listWidget = QtWidgets.QListWidget()
        self.group_box = QtWidgets.QGroupBox()

        self.radio_group = QtWidgets.QButtonGroup()
        for i in range(3):
            btn = QtWidgets.QRadioButton(f"rb{i}", self)
            self.radio_group.addButton(btn)

        gutils.set_btn_group_data(self.radio_group,
                                  ["fizz", "buzz", "fizzbuzz"])

        self.comboBox = QtWidgets.QComboBox()
        for i in range(3):
            self.comboBox.addItem(f"x-{i + 42}", i)

        self.tree = QtWidgets.QTreeWidget()
        gutils.fill_tree(self.tree.invisibleRootItem(), ["foo", "bar", "baz"])
示例#5
0
    def __init__(self, simulation: Simulation, parent):
        """Initializes an OptimizationDialog that displays various optimization
        parameters.

        Args:
            simulation: a Simulation object
            parent: a SimulationTabWidget
        """
        super().__init__()
        self.simulation = simulation
        self.tab = parent
        self.current_mode = OptimizationType.RECOIL

        uic.loadUi(gutils.get_ui_dir() / "ui_optimization_params.ui", self)

        self.recoil_widget = OptimizationRecoilParameterWidget()
        self.fluence_widget = OptimizationFluenceParameterWidget()

        self.load_properties_from_file()

        locale = QLocale.c()
        self.histogramTicksDoubleSpinBox.setLocale(locale)

        self.pushButton_OK.setEnabled(False)

        self.pushButton_Cancel.clicked.connect(self.close)
        self.pushButton_OK.clicked.connect(self.start_optimization)

        self.radios = QtWidgets.QButtonGroup(self)
        self.radios.buttonToggled[QtWidgets.QAbstractButton, bool].connect(
            self.choose_optimization_mode)
        self.parametersLayout.addWidget(self.recoil_widget)
        self.parametersLayout.addWidget(self.fluence_widget)
        self.fluence_widget.hide()

        self.radios.addButton(self.fluenceRadioButton)
        self.radios.addButton(self.recoilRadioButton)

        gutils.fill_tree(
            self.simulationTreeWidget.invisibleRootItem(),
            simulation.element_simulations,
            text_func=lambda elem_sim: elem_sim.get_full_name())

        self.simulationTreeWidget.itemSelectionChanged.connect(
            self._enable_ok_button)
        self.simulationTreeWidget.itemSelectionChanged.connect(
            self._adjust_x)
        self.auto_adjust_x_box.clicked.connect(self._adjust_x)

        self._fill_measurement_widget()

        self.measurementTreeWidget.itemSelectionChanged.connect(
            self._enable_ok_button)
        self.verbose = False
        self.eff_file_check_box.clicked.connect(self._enable_efficiency_label)
        # self.optimization_verbose_box.clicked.connect(self._verbose)
        self._update_efficiency_label()

        self.exec_()
示例#6
0
    def _set_external_files(self):
        """Sets up the external file QTreeWidget.
        """
        # Add a view for adding external files to draw
        self.external_tree_widget.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        header = QtWidgets.QTreeWidgetItem()
        header.setText(0, "External files")
        self.gridLayout_2.addWidget(self.external_tree_widget, 0, 2)
        self.external_tree_widget.setHeaderItem(header)

        gutils.fill_tree(self.external_tree_widget.invisibleRootItem(),
                         self.simulation.request.get_imported_files(),
                         text_func=lambda fp: fp.name)

        self.external_files = {}
示例#7
0
 def _fill_measurement_widget(self):
     """Add calculated tof_list files to tof_list_tree_widget by
     measurement under the same sample.
     """
     for sample in self.simulation.request.samples.samples:
         for measurement in sample.measurements.measurements.values():
             if self.simulation.sample is measurement.sample:
                 root = QtWidgets.QTreeWidgetItem()
                 root.setText(0, measurement.name)
                 self.measurementTreeWidget.addTopLevelItem(root)
                 cuts, elem_losses = measurement.get_cut_files()
                 gutils.fill_tree(root,
                                  cuts,
                                  data_func=lambda c: (c, measurement),
                                  text_func=lambda c: c.name)
                 loss_node = QtWidgets.QTreeWidgetItem(["Element losses"])
                 gutils.fill_tree(loss_node,
                                  elem_losses,
                                  data_func=lambda c: (c, measurement),
                                  text_func=lambda c: c.name)
                 root.addChild(loss_node)
                 root.setExpanded(True)
示例#8
0
    def __init__(self,
                 measurements: List[Measurement],
                 detector: Detector,
                 run: Run,
                 parent_settings_widget=None):
        """Inits the calibration dialog class.
        
        Args:
            measurements: A string list representing measurements files.
            detector: A Detector class object.
            run: Run object.
            parent_settings_widget: A widget this dialog was opened from.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_calibration_dialog.ui", self)

        self.measurements = measurements
        self.run = run
        self.detector = detector

        self.parent_settings_widget = parent_settings_widget
        self.tof_calibration = TOFCalibration()

        # Go through all the measurements and their cut files and list them.
        for measurement in self.measurements:
            item = QtWidgets.QTreeWidgetItem([measurement.name])
            cuts, _ = measurement.get_cut_files()
            gutils.fill_tree(item,
                             cuts,
                             data_func=lambda fp: CutFile(cut_file_path=fp),
                             text_func=lambda fp: fp.name)
            self.cutFilesTreeWidget.addTopLevelItem(item)
            item.setExpanded(True)
        # Resize columns to fit the content nicely
        for column in range(0, self.cutFilesTreeWidget.columnCount()):
            self.cutFilesTreeWidget.resizeColumnToContents(column)

        self.curveFittingWidget = CalibrationCurveFittingWidget(
            self, self.selected_cut_file, self.tof_calibration, self.detector,
            self.bin_width, 0, self.run)

        old_params = None
        # Get old parameters from the parent dialog
        if parent_settings_widget is not None:
            try:
                f1 = self.parent_settings_widget.tof_offset
                f2 = self.parent_settings_widget.tof_slope
                old_params = f1, f2
            except ValueError as e:
                print(f"Can't get old calibration parameters from the "
                      f"settings dialog: {e}.")

        self.linearFittingWidget = CalibrationLinearFittingWidget(
            self, self.tof_calibration, old_params)

        self.fittingResultsLayout.addWidget(self.curveFittingWidget)
        self.calibrationResultsLayout.addWidget(self.linearFittingWidget)

        # Set up connections
        self.cutFilesTreeWidget.itemSelectionChanged.connect(
            self.__update_curve_fit)
        self.pointsTreeWidget.itemClicked.connect(self.__set_state_for_point)
        self.acceptPointButton.clicked.connect(self.__accept_point)
        self.binWidthSpinBox.valueChanged.connect(self.__update_curve_fit)
        self.binWidthSpinBox.setKeyboardTracking(False)
        self.acceptCalibrationButton.clicked.connect(self.accept_calibration)
        self.cancelButton.clicked.connect(self.close)
        self.removePointButton.clicked.connect(self.remove_selected_points)
        self.tofChannelLineEdit.editingFinished.connect(
            lambda: self.set_calibration_point(
                float(self.tofChannelLineEdit.text())))

        # Set the validator for lineEdit so user can't give invalid values
        double_validator = QtGui.QDoubleValidator()
        self.tofChannelLineEdit.setValidator(double_validator)

        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.label_remove_timeout)

        try:
            self.__load_object(self.POINTS_OBJECT_FILENAME)
            for p in self.tof_calibration.tof_points:
                self.__accept_points(p)
        except OSError:
            pass

        self.exec_()