def build_fitted_diffraction_pattern(self, fit_global_parameters):

        fitted_patterns = numpy.full(self.diffraction_patterns_number, None)

        for index in range(self.diffraction_patterns_number):
            wavelength = fit_global_parameters.measured_dataset.incident_radiations[0 if len(fit_global_parameters.measured_dataset.incident_radiations) == 1 else index].wavelength

            fitted_pattern = DiffractionPattern()

            fitted_intensity = fit_function_direct(self.twotheta_experimental_list[index],
                                                   fit_global_parameters,
                                                   diffraction_pattern_index=index)
            fitted_residual = self.intensity_experimental_list[index] - fitted_intensity

            for i in range(0, len(fitted_intensity)):
                diffraction_point = DiffractionPoint(twotheta=self.twotheta_experimental_list[index][i],
                                                     intensity=fitted_intensity[i],
                                                     error=fitted_residual[i])
                diffraction_point.apply_wavelength(wavelength)

                fitted_pattern.add_diffraction_point(diffraction_point=diffraction_point)

            fitted_patterns[index] = fitted_pattern

        return fitted_patterns
Example #2
0
    def remove_all(self):
        if ConfirmDialog.confirmed(
                parent=self,
                message="Confirm Removal of ALL diffraction Pattern?"):
            self.diffraction_pattern_tabs.clear()
            self.diffraction_pattern_box_array = []

            diffraction_pattern_box = DiffractionPatternBox(
                widget=self,
                parent=gui.createTabPage(
                    self.diffraction_pattern_tabs,
                    DiffractionPattern.get_default_name(0)),
                index=0)

            self.diffraction_pattern_box_array.append(diffraction_pattern_box)

            self.tabs.clear()
            self.tab_diff = []
            self.tabs_data_plot = []
            self.tab_data = []
            self.tab_plot = []
            self.plot = []
            self.table_data = []

            self.tab_diff.append(
                gui.createTabPage(self.tabs,
                                  DiffractionPattern.get_default_name(0)))
            self.tabs_data_plot.append(gui.tabWidget(self.tab_diff[0]))
            self.tab_data.append(
                gui.createTabPage(self.tabs_data_plot[0], "Data"))
            self.tab_plot.append(
                gui.createTabPage(self.tabs_data_plot[0], "Plot"))

            self.plot.append(PlotWindow())
            self.plot[0].setDefaultPlotLines(True)
            self.plot[0].setActiveCurveColor(color="#00008B")
            self.plot[0].setGraphXLabel(r"2$\theta$")
            self.plot[0].setGraphYLabel("Intensity")

            self.tab_plot[0].layout().addWidget(self.plot[0])

            table_widget = self.create_table_widget()

            self.table_data.append(table_widget)

            self.tab_data[0].layout().addWidget(table_widget,
                                                alignment=Qt.AlignHCenter)

            self.dumpSettings()
    def __init__(self):
        super().__init__(show_automatic_box=True)
        
        line_profiles_box = gui.widgetBox(self.controlArea,
                                 "Line Profiles", orientation="vertical",
                                 width=self.CONTROL_AREA_WIDTH - 10, height=600)


        button_box = gui.widgetBox(line_profiles_box,
                                   "", orientation="horizontal",
                                   width=self.CONTROL_AREA_WIDTH-25)

        gui.button(button_box, self, "Send Line Profiles", height=40, callback=self.send_line_profiles)

        self.line_profiles_tabs = gui.tabWidget(line_profiles_box)
        self.line_profiles_box_array = []

        for index in range(len(self.reflections_of_phases)):
            line_profiles_tab = gui.createTabPage(self.line_profiles_tabs, DiffractionPattern.get_default_name(index))

            line_profiles_box = LineProfileBox(widget=self,
                                               parent=line_profiles_tab,
                                               diffraction_pattern_index = index,
                                               reflections_of_phases = self.reflections_of_phases[index],
                                               limits                = self.limits[index],
                                               limit_types           = self.limit_types[index])

            self.line_profiles_box_array.append(line_profiles_box)

        runaction = OWAction("Send Line Profiles", self)
        runaction.triggered.connect(self.send_line_profiles)
        self.addAction(runaction)

        orangegui.rubber(self.controlArea)
Example #4
0
 def diffraction_pattern_name(cls,
                              fit_global_parameter,
                              diffraction_pattern_index,
                              use_single_set=False):
     if use_single_set:
         return "All Diffraction Patterns"
     elif fit_global_parameter is None:
         return DiffractionPattern.get_default_name(0)
     else:
         return fit_global_parameter.measured_dataset.get_diffraction_pattern(
             diffraction_pattern_index).get_name(diffraction_pattern_index)
Example #5
0
    def remove(self):
        if self.diffraction_pattern_tabs.count() <= 1:
            QMessageBox.critical(
                self, "Error",
                "Remove not possible, Fit process needs at least 1 element",
                QMessageBox.Ok)
        else:
            current_index = self.diffraction_pattern_tabs.currentIndex()

            if ConfirmDialog.confirmed(
                    parent=self,
                    message="Confirm Removal of " +
                    self.diffraction_pattern_tabs.tabText(current_index) +
                    "?"):
                self.diffraction_pattern_tabs.removeTab(current_index)
                self.diffraction_pattern_box_array.pop(current_index)

                self.tabs.removeTab(current_index)
                self.tab_diff.pop(current_index)
                self.tabs_data_plot.pop(current_index)
                self.tab_data.pop(current_index)
                self.tab_plot.pop(current_index)
                self.plot.pop(current_index)
                self.table_data.pop(current_index)

                for index in range(current_index,
                                   self.diffraction_pattern_tabs.count()):
                    self.diffraction_pattern_tabs.setTabText(
                        index, DiffractionPattern.get_default_name(index))
                    self.diffraction_pattern_box_array[index].index = index
                    self.tabs.setTabText(
                        index, DiffractionPattern.get_default_name(index))

                self.dumpSettings()
                self.diffraction_pattern_tabs.setCurrentIndex(current_index)
                self.tabs.setCurrentIndex(current_index)
Example #6
0
    def __init__(self):
        super().__init__(show_automatic_box=False)

        main_box = gui.widgetBox(self.controlArea,
                                 "Load Diffraction Pattern",
                                 orientation="vertical",
                                 width=self.CONTROL_AREA_WIDTH - 5,
                                 height=600)

        button_box = gui.widgetBox(main_box,
                                   "",
                                   orientation="horizontal",
                                   width=self.CONTROL_AREA_WIDTH - 25)

        gui.button(button_box,
                   self,
                   "Load Data",
                   height=50,
                   callback=self.load_diffraction_patterns)

        tabs_button_box = gui.widgetBox(main_box,
                                        "",
                                        addSpace=False,
                                        orientation="horizontal")

        btns = [
            gui.button(tabs_button_box,
                       self,
                       "Insert Before",
                       callback=self.insert_before),
            gui.button(tabs_button_box,
                       self,
                       "Insert After",
                       callback=self.insert_after),
            gui.button(tabs_button_box, self, "Remove", callback=self.remove),
            gui.button(tabs_button_box,
                       self,
                       "Remove All",
                       callback=self.remove_all)
        ]

        for btn in btns:
            btn.setFixedHeight(40)

        btns[3].setStyleSheet("color: red")
        font = QFont(btns[3].font())
        font.setItalic(True)
        btns[3].setFont(font)

        self.diffraction_pattern_tabs = gui.tabWidget(main_box)
        self.diffraction_pattern_box_array = []

        for index in range(len(self.filename)):
            diffraction_pattern_tab = gui.createTabPage(
                self.diffraction_pattern_tabs,
                DiffractionPattern.get_default_name(index))

            diffraction_pattern_box = DiffractionPatternBox(
                widget=self,
                parent=diffraction_pattern_tab,
                index=index,
                filename=self.filename[index],
                twotheta_min=self.twotheta_min[index],
                twotheta_has_min=self.twotheta_has_min[index],
                twotheta_max=self.twotheta_max[index],
                twotheta_has_max=self.twotheta_has_max[index],
                diffraction_pattern_name=self.diffraction_pattern_name[index])

            self.diffraction_pattern_box_array.append(diffraction_pattern_box)

        self.tabs = gui.tabWidget(self.mainArea)
        self.tab_diff = []
        self.tabs_data_plot = []
        self.tab_data = []
        self.tab_plot = []
        self.plot = []
        self.table_data = []

        for index in range(len(self.filename)):
            self.tab_diff.append(
                gui.createTabPage(self.tabs,
                                  DiffractionPattern.get_default_name(index)))
            self.tabs_data_plot.append(gui.tabWidget(self.tab_diff[index]))
            self.tab_data.append(
                gui.createTabPage(self.tabs_data_plot[index], "Data"))
            self.tab_plot.append(
                gui.createTabPage(self.tabs_data_plot[index], "Plot"))

            self.plot.append(PlotWindow())
            self.plot[index].setDefaultPlotLines(True)
            self.plot[index].setActiveCurveColor(color="#00008B")
            self.plot[index].setGraphXLabel(r"2$\theta$")
            self.plot[index].setGraphYLabel("Intensity")

            self.tab_plot[index].layout().addWidget(self.plot[index])

            table_widget = self.create_table_widget()

            self.table_data.append(table_widget)

            self.tab_data[index].layout().addWidget(table_widget,
                                                    alignment=Qt.AlignHCenter)

        runaction = OWAction("Load Diffraction Patterns", self)
        runaction.triggered.connect(self.load_diffraction_patterns)
        self.addAction(runaction)
Example #7
0
    def insert_after(self):
        current_index = self.diffraction_pattern_tabs.currentIndex()

        if ConfirmDialog.confirmed(
                parent=self,
                message="Confirm Insertion of a new element after " +
                self.diffraction_pattern_tabs.tabText(current_index) + "?"):
            diffraction_pattern_tab = gui.widgetBox(
                self.diffraction_pattern_tabs, addToLayout=0, margin=4)
            diffraction_pattern_box = DiffractionPatternBox(
                widget=self,
                parent=diffraction_pattern_tab,
                index=current_index + 1)
            diffraction_pattern_box.after_change_workspace_units()

            diffraction_pattern_pd_tab = gui.widgetBox(self.tabs,
                                                       addToLayout=0,
                                                       margin=4)

            if current_index == self.diffraction_pattern_tabs.count(
            ) - 1:  # LAST
                self.diffraction_pattern_tabs.addTab(diffraction_pattern_tab,
                                                     "TEMP")
                self.diffraction_pattern_box_array.append(
                    diffraction_pattern_box)

                self.tabs.addTab(diffraction_pattern_pd_tab, "TEMP")
                self.tab_diff.append(diffraction_pattern_pd_tab)

                self.tabs_data_plot.append(
                    gui.tabWidget(self.tab_diff[current_index + 1]))
                self.tab_data.append(
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Data"))
                self.tab_plot.append(
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Plot"))

                self.plot.append(PlotWindow())
                self.plot[current_index + 1].setDefaultPlotLines(True)
                self.plot[current_index +
                          1].setActiveCurveColor(color="#00008B")
                self.plot[current_index + 1].setGraphXLabel(r"2$\theta$")
                self.plot[current_index + 1].setGraphYLabel("Intensity")

                self.tab_plot[current_index + 1].layout().addWidget(
                    self.plot[current_index + 1])

                scrollarea = QScrollArea(self.tab_data[current_index])
                scrollarea.setMinimumWidth(805)
                scrollarea.setMinimumHeight(605)

                self.table_data.append(self.create_table_widget())

                scrollarea.setWidget(self.table_data[current_index + 1])
                scrollarea.setWidgetResizable(1)

                self.tab_data[current_index + 1].layout().addWidget(
                    scrollarea, alignment=Qt.AlignHCenter)
            else:
                self.diffraction_pattern_tabs.insertTab(
                    current_index + 1, diffraction_pattern_tab, "TEMP")
                self.diffraction_pattern_box_array.insert(
                    current_index + 1, diffraction_pattern_box)

                self.tabs.insertTab(current_index + 1,
                                    diffraction_pattern_pd_tab, "TEMP")
                self.tab_diff.insert(current_index + 1,
                                     diffraction_pattern_pd_tab)

                self.tabs_data_plot.insert(
                    current_index + 1,
                    gui.tabWidget(self.tab_diff[current_index + 1]))
                self.tab_data.insert(
                    current_index + 1,
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Data"))
                self.tab_plot.insert(
                    current_index + 1,
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Plot"))

                self.plot.insert(current_index + 1, PlotWindow())
                self.plot[current_index + 1].setDefaultPlotLines(True)
                self.plot[current_index +
                          1].setActiveCurveColor(color="#00008B")
                self.plot[current_index + 1].setGraphXLabel(r"2$\theta$")
                self.plot[current_index + 1].setGraphYLabel("Intensity")

                self.tab_plot[current_index + 1].layout().addWidget(
                    self.plot[current_index + 1])

                scrollarea = QScrollArea(self.tab_data[current_index + 1])
                scrollarea.setMinimumWidth(805)
                scrollarea.setMinimumHeight(605)

                self.table_data.insert(current_index + 1,
                                       self.create_table_widget())

                scrollarea.setWidget(self.table_data[current_index + 1])
                scrollarea.setWidgetResizable(1)

                self.tab_data[current_index + 1].layout().addWidget(
                    scrollarea, alignment=Qt.AlignHCenter)

            for index in range(current_index,
                               self.diffraction_pattern_tabs.count()):
                self.diffraction_pattern_tabs.setTabText(
                    index, DiffractionPattern.get_default_name(index))
                self.diffraction_pattern_box_array[index].index = index
                self.tabs.setTabText(
                    index, DiffractionPattern.get_default_name(index))

            self.dumpSettings()
            self.diffraction_pattern_tabs.setCurrentIndex(current_index + 1)
            self.tabs.setCurrentIndex(current_index + 1)