Ejemplo n.º 1
0
    def set_use_single_parameter_set(self, on_init=False):
        self.parameter_tabs.clear()
        self.parameter_box_array.clear()

        dimension = self.get_current_dimension(
        ) if self.fit_global_parameters is None else self.fit_global_parameters.measured_dataset.get_diffraction_patterns_number(
        )

        for index in range(1 if self.use_single_parameter_set ==
                           1 else dimension):
            parameter_tab = gui.createTabPage(
                self.parameter_tabs,
                OWGenericWidget.diffraction_pattern_name(
                    self.fit_global_parameters, index,
                    self.use_single_parameter_set == 1))

            if index < self.get_current_dimension():  # keep the existing
                try:
                    parameter_box = self.get_parameter_box_instance(
                        parameter_tab, index)
                except:
                    parameter_box = self.get_empty_parameter_box_instance(
                        parameter_tab, index)  # prevents crash
            else:
                parameter_box = self.get_empty_parameter_box_instance(
                    parameter_tab, index)

            self.parameter_box_array.append(parameter_box)

            if not on_init: self.dumpSettings()
    def set_data(self, data):
        if not data is None:
            try:
                self.fit_global_parameters = data.duplicate()

                phases = self.fit_global_parameters.measured_dataset.phases
                if phases is None:
                    raise ValueError("Add Phase(s) before this widget")

                diffraction_patterns = self.fit_global_parameters.measured_dataset.diffraction_patterns
                if diffraction_patterns is None:
                    raise ValueError(
                        "Add Diffraction Pattern(s) before this widget!")

                thermal_parameters = self.fit_global_parameters.get_thermal_parameters(
                    ThermalParameters.__name__)

                self.set_use_single_parameter_set(on_init=True)

                if self.use_single_parameter_set == 0:  # NO
                    if not thermal_parameters is None:
                        for diffraction_pattern_index in range(
                                len(thermal_parameters)):
                            thermal_parameters_item = self.fit_global_parameters.get_thermal_parameters_item(
                                ThermalParameters.__name__,
                                diffraction_pattern_index)

                            self.debye_wallers_tabs.setTabText(
                                diffraction_pattern_index,
                                OWGenericWidget.diffraction_pattern_name(
                                    self.fit_global_parameters,
                                    diffraction_pattern_index, False))

                            debye_waller_box = self.debye_wallers_box_array[
                                diffraction_pattern_index]

                            if not thermal_parameters_item is None:
                                debye_waller_box.set_data(
                                    thermal_parameters_item)
                else:
                    if thermal_parameters is None:
                        self.set_use_single_parameter_set(True)
                    else:
                        self.__check_data_congruence(thermal_parameters)

                        thermal_parameters_item = self.fit_global_parameters.get_thermal_parameters_item(
                            thermal_parameters.__name__, 0)

                        self.debye_wallers_tabs.setTabText(
                            0,
                            OWGenericWidget.diffraction_pattern_name(
                                self.fit_global_parameters, 0, True))

                        if not thermal_parameters_item is None:
                            self.debye_wallers_box_array[0].set_data(
                                thermal_parameters_item)

                self.dumpSettings()

                if self.is_automatic_run:
                    self.send_debye_waller()

            except Exception as e:
                QMessageBox.critical(self, "Error", str(e), QMessageBox.Ok)

                if self.IS_DEVELOP: raise e
    def set_use_single_parameter_set(self, on_init=False):
        self.debye_wallers_tabs.clear()
        self.debye_wallers_box_array = []

        dimension = len(
            self.debye_waller_factors
        ) if self.fit_global_parameters is None else self.fit_global_parameters.measured_dataset.get_diffraction_patterns_number(
        )
        phases_number = len(
            self.debye_waller_factors[0]
        ) if self.fit_global_parameters is None else self.fit_global_parameters.measured_dataset.get_phases_number(
        )

        for diffraction_pattern_index in range(
                1 if self.use_single_parameter_set == 1 else dimension):
            debye_waller_tab = gui.createTabPage(
                self.debye_wallers_tabs,
                OWGenericWidget.diffraction_pattern_name(
                    self.fit_global_parameters, diffraction_pattern_index,
                    self.use_single_parameter_set == 1))

            # qui analisi delle fasi
            if diffraction_pattern_index < len(
                    self.debye_waller_factors):  # keep the existing
                use_debye_waller_factors = []
                debye_waller_factors = []
                debye_waller_factors_fixed = []
                debye_waller_factors_has_min = []
                debye_waller_factors_min = []
                debye_waller_factors_has_max = []
                debye_waller_factors_max = []
                debye_waller_factors_function = []
                debye_waller_factors_function_value = []

                for phase_index in range(phases_number):
                    if phase_index < len(
                            self.
                            debye_waller_factors[diffraction_pattern_index]):
                        use_debye_waller_factors.append(
                            self.use_debye_waller_factors[
                                diffraction_pattern_index][phase_index])
                        debye_waller_factors.append(self.debye_waller_factors[
                            diffraction_pattern_index][phase_index])
                        debye_waller_factors_fixed.append(
                            self.debye_waller_factors_fixed[
                                diffraction_pattern_index][phase_index])
                        debye_waller_factors_has_min.append(
                            self.debye_waller_factors_has_min[
                                diffraction_pattern_index][phase_index])
                        debye_waller_factors_min.append(
                            self.debye_waller_factors_min[
                                diffraction_pattern_index][phase_index])
                        debye_waller_factors_has_max.append(
                            self.debye_waller_factors_has_max[
                                diffraction_pattern_index][phase_index])
                        debye_waller_factors_max.append(
                            self.debye_waller_factors_max[
                                diffraction_pattern_index][phase_index])
                        debye_waller_factors_function.append(
                            self.debye_waller_factors_function[
                                diffraction_pattern_index][phase_index])
                        debye_waller_factors_function_value.append(
                            self.debye_waller_factors_function_value[
                                diffraction_pattern_index][phase_index])
                    else:
                        use_debye_waller_factors.append(1)
                        debye_waller_factors.append(0.1)
                        debye_waller_factors_fixed.append(0)
                        debye_waller_factors_has_min.append(0)
                        debye_waller_factors_min.append(0.0)
                        debye_waller_factors_has_max.append(0.0)
                        debye_waller_factors_max.append(0.0)
                        debye_waller_factors_function.append(0)
                        debye_waller_factors_function_value.append("")

                debye_waller_box = DebyeWallerBox(
                    widget=self,
                    parent=debye_waller_tab,
                    diffraction_pattern_index=diffraction_pattern_index,
                    use_debye_waller_factors=use_debye_waller_factors,
                    debye_waller_factors=debye_waller_factors,
                    debye_waller_factors_fixed=debye_waller_factors_fixed,
                    debye_waller_factors_has_min=debye_waller_factors_has_min,
                    debye_waller_factors_min=debye_waller_factors_min,
                    debye_waller_factors_has_max=debye_waller_factors_has_max,
                    debye_waller_factors_max=debye_waller_factors_max,
                    debye_waller_factors_function=debye_waller_factors_function,
                    debye_waller_factors_function_value=
                    debye_waller_factors_function_value)
            else:
                debye_waller_box = DebyeWallerBox(
                    widget=self,
                    parent=debye_waller_tab,
                    diffraction_pattern_index=diffraction_pattern_index,
                    use_debye_waller_factors=[1] * phases_number,
                    debye_waller_factors=[0.1] * phases_number,
                    debye_waller_factors_fixed=[0] * phases_number,
                    debye_waller_factors_has_min=[0] * phases_number,
                    debye_waller_factors_min=[0.0] * phases_number,
                    debye_waller_factors_has_max=[0.0] * phases_number,
                    debye_waller_factors_max=[0.0] * phases_number,
                    debye_waller_factors_function=[0] * phases_number,
                    debye_waller_factors_function_value=[""] * phases_number)

            self.debye_wallers_box_array.append(debye_waller_box)

            if not on_init: self.dumpSettings()
    def set_data(self, data):
        if not data is None:
            try:
                self.fit_global_parameters = data.duplicate()

                diffraction_patterns = self.fit_global_parameters.measured_dataset.diffraction_patterns
                phases               = self.fit_global_parameters.measured_dataset.phases
                line_profiles        = self.fit_global_parameters.measured_dataset.line_profiles

                if diffraction_patterns is None: raise ValueError("No Diffraction Pattern in input data!")
                if phases is None:               raise ValueError("No Phases in input data!")

                different_phases   = len(phases) != len(self.reflections_of_phases[0])
                different_patterns = len(line_profiles) != len(self.reflections_of_phases)

                if different_patterns or different_phases:
                    self.line_profiles_tabs.clear()
                    self.line_profiles_box_array = []

                    for diffraction_pattern_index in range(len(diffraction_patterns)):
                        line_profile_tab = gui.createTabPage(self.line_profiles_tabs, OWGenericWidget.diffraction_pattern_name(self.fit_global_parameters, diffraction_pattern_index))

                        if diffraction_pattern_index < len(self.reflections_of_phases): #keep the existing
                            reflections_of_phases = []
                            limits                = []
                            limit_types           = []

                            for phase_index in range(len(phases)):
                                if phase_index < len(self.reflections_of_phases[diffraction_pattern_index]):
                                    reflections_of_phases.append(self.reflections_of_phases[diffraction_pattern_index][phase_index])
                                    limits.append(self.limits[diffraction_pattern_index][phase_index])
                                    limit_types.append(self.limit_types[diffraction_pattern_index][phase_index])
                                else:
                                    reflections_of_phases.append("")
                                    limits.append(0.0)
                                    limit_types.append(0)

                            line_profile_box = LineProfileBox(widget=self,
                                                              parent=line_profile_tab,
                                                              diffraction_pattern_index = diffraction_pattern_index,
                                                              reflections_of_phases = reflections_of_phases,
                                                              limits         = limits,
                                                              limit_types    = limit_types)
                        else:
                            line_profile_box = LineProfileBox(widget=self,
                                                              parent=line_profile_tab,
                                                              diffraction_pattern_index = diffraction_pattern_index,
                                                              reflections_of_phases=[""]*len(phases),
                                                              limits=[0.0]*len(phases),
                                                              limit_types=[0]*len(phases))

                        self.line_profiles_box_array.append(line_profile_box)


                elif not line_profiles is None:
                    for diffraction_pattern_index in range(len(diffraction_patterns)):
                        self.line_profiles_tabs.setTabText(diffraction_pattern_index, OWGenericWidget.diffraction_pattern_name(self.fit_global_parameters, diffraction_pattern_index))
                        self.line_profiles_box_array[diffraction_pattern_index].set_data(line_profiles[diffraction_pattern_index])

                self.dumpSettings()

                if self.is_automatic_run:
                    self.send_line_profiles()

            except Exception as e:
                QMessageBox.critical(self, "Error",
                                     str(e),
                                     QMessageBox.Ok)

                if self.IS_DEVELOP: raise e
Ejemplo n.º 5
0
    def set_data(self, data):
        if not data is None:
            try:
                self.fit_global_parameters = data.duplicate()

                diffraction_patterns = self.fit_global_parameters.measured_dataset.diffraction_patterns
                if diffraction_patterns is None:
                    raise ValueError("No Diffraction Pattern in input data!")

                parameters = self.get_parameter_array()

                if parameters is None:
                    self.set_use_single_parameter_set(on_init=True)
                else:
                    if self.use_single_parameter_set == 0:  # NO
                        tabs_to_remove = self.get_current_dimension() - len(
                            parameters)

                        if tabs_to_remove > 0:
                            for index in range(tabs_to_remove):
                                self.parameter_tabs.removeTab(-1)
                                self.parameter_box_array.pop()

                        for diffraction_pattern_index in range(
                                len(parameters)):
                            parameters_item = self.get_parameter_item(
                                diffraction_pattern_index)

                            if diffraction_pattern_index < self.get_current_dimension(
                            ):
                                parameter_box = self.parameter_box_array[
                                    diffraction_pattern_index]
                                self.parameter_tabs.setTabText(
                                    diffraction_pattern_index,
                                    OWGenericWidget.diffraction_pattern_name(
                                        self.fit_global_parameters,
                                        diffraction_pattern_index, False))
                            else:
                                parameter_box = self.get_empty_parameter_box_instance(
                                    parameter_tab=gui.createTabPage(
                                        self.parameter_tabs,
                                        OWGenericWidget.
                                        diffraction_pattern_name(
                                            self.fit_global_parameters,
                                            diffraction_pattern_index, False)),
                                    index=diffraction_pattern_index)
                                self.parameter_box_array.append(parameter_box)

                            if not parameters_item is None:
                                parameter_box.set_data(parameters_item)
                    else:
                        self.__check_data_congruence(parameters)

                        parameters_item = self.get_parameter_item(0)

                        self.parameter_tabs.setTabText(
                            0,
                            OWGenericWidget.diffraction_pattern_name(
                                self.fit_global_parameters, 0, True))
                        if not parameters_item is None:
                            self.parameter_box_array[0].set_data(
                                parameters_item)

                self.dumpSettings()

                if self.is_automatic_run:
                    self.send_parameter()

            except Exception as e:
                QMessageBox.critical(self, "Error", str(e), QMessageBox.Ok)

                if self.IS_DEVELOP: raise e