Exemple #1
0
    def updateFit(self):
        """ Do the configured fit and show it in the plot """
        fit_name = self._wm_logger_logic.fc.current_fit
        fit_result = self._wm_logger_logic.fc.current_fit_result
        fit_param = self._wm_logger_logic.fc.current_fit_param

        if fit_result is not None:
            # display results as formatted text
            self._mw.fit_results_DisplayWidget.clear()
            try:
                formated_results = units.create_formatted_output(
                    fit_result.result_str_dict)
            except:
                formated_results = 'this fit does not return formatted results'
            self._mw.fit_results_DisplayWidget.setPlainText(formated_results)

        if fit_name is not None:
            self._mw.fit_methods_ComboBox.setCurrentFit(fit_name)

        # check which fit method is used and show the curve in the plot accordingly
        if fit_name != 'No Fit':
            self.curve_fit.setData(x=self._wm_logger_logic.wlog_fit_x,
                                   y=self._wm_logger_logic.wlog_fit_y)

            if self.curve_fit not in self._mw.plotWidget.listDataItems():
                self._mw.plotWidget.addItem(self.curve_fit)
        else:
            if self.curve_fit in self._mw.plotWidget.listDataItems():
                self._mw.plotWidget.removeItem(self.curve_fit)
Exemple #2
0
    def update_fit(self, x_data, y_data, result_str_dict, current_fit):
        """ Update the shown fit. """
        if current_fit != 'No Fit':
            # display results as formatted text
            self._mw.odmr_fit_results_DisplayWidget.clear()
            try:
                formated_results = units.create_formatted_output(result_str_dict)
            except:
                formated_results = 'this fit does not return formatted results'
            self._mw.odmr_fit_results_DisplayWidget.setPlainText(formated_results)

        self._mw.fit_methods_ComboBox.blockSignals(True)
        self._mw.fit_methods_ComboBox.setCurrentFit(current_fit)
        self._mw.fit_methods_ComboBox.blockSignals(False)

        # check which Fit method is used and remove or add again the
        # odmr_fit_image, check also whether a odmr_fit_image already exists.
        if current_fit != 'No Fit':
            self.odmr_fit_image.setData(x=x_data, y=y_data)
            if self.odmr_fit_image not in self._mw.odmr_PlotWidget.listDataItems():
                self._mw.odmr_PlotWidget.addItem(self.odmr_fit_image)
        else:
            if self.odmr_fit_image in self._mw.odmr_PlotWidget.listDataItems():
                self._mw.odmr_PlotWidget.removeItem(self.odmr_fit_image)

        self._mw.odmr_PlotWidget.getViewBox().updateAutoRange()
        return
Exemple #3
0
    def update_fit(self, x_data, y_data, result_str_dict, current_fit):
        """ Update the shown fit. """
        if current_fit != 'No Fit':
            # display results as formatted text
            self._mw.odmr_fit_results_DisplayWidget.clear()
            try:
                formated_results = units.create_formatted_output(
                    result_str_dict)
            except:
                formated_results = 'this fit does not return formatted results'
            self._mw.odmr_fit_results_DisplayWidget.setPlainText(
                formated_results)

        self._mw.fit_methods_ComboBox.blockSignals(True)
        self._mw.fit_methods_ComboBox.setCurrentFit(current_fit)
        self._mw.fit_methods_ComboBox.blockSignals(False)

        # check which Fit method is used and remove or add again the
        # odmr_fit_image, check also whether a odmr_fit_image already exists.
        if current_fit != 'No Fit':
            self.odmr_fit_image.setData(x=x_data, y=y_data)
            if self.odmr_fit_image not in self._mw.odmr_PlotWidget.listDataItems(
            ):
                self._mw.odmr_PlotWidget.addItem(self.odmr_fit_image)
        else:
            if self.odmr_fit_image in self._mw.odmr_PlotWidget.listDataItems():
                self._mw.odmr_PlotWidget.removeItem(self.odmr_fit_image)

        self._mw.odmr_PlotWidget.getViewBox().updateAutoRange()
        return
Exemple #4
0
    def update_fit(self):
        """ Do the configured fit and show it in the sum plot """
        x_data_fit, y_data_fit, fit_param, fit_result = self._odmr_logic.do_fit(
            fit_function=self._odmr_logic.current_fit_function)
        self._sd.fit_tabs[
            self._odmr_logic.current_fit_function].keepFitSettings(
                fit_result.params, 0)
        # The fit signal was already emitted in the logic, so there is no need
        # to set the fit data

        # check which Fit method is used and remove or add again the
        # odmr_fit_image, check also whether a odmr_fit_image already exists.
        if self._mw.fit_methods_ComboBox.currentText() == 'No Fit':
            if self.odmr_fit_image in self._mw.odmr_PlotWidget.listDataItems():
                self._mw.odmr_PlotWidget.removeItem(self.odmr_fit_image)
        else:
            if self.odmr_fit_image not in self._mw.odmr_PlotWidget.listDataItems(
            ):
                self._mw.odmr_PlotWidget.addItem(self.odmr_fit_image)

        self._mw.odmr_PlotWidget.getViewBox().updateAutoRange()
        self._mw.odmr_fit_results_DisplayWidget.clear()

        formated_results = units.create_formatted_output(fit_param)

        self._mw.odmr_fit_results_DisplayWidget.setPlainText(formated_results)
Exemple #5
0
    def updateFit(self):
        """ Do the configured fit and show it in the plot """
        fit_name = self._wm_logger_logic.fc.current_fit
        fit_result = self._wm_logger_logic.fc.current_fit_result
        fit_param = self._wm_logger_logic.fc.current_fit_param

        if fit_result is not None:
            # display results as formatted text
            self._mw.fit_results_DisplayWidget.clear()
            try:
                formated_results = units.create_formatted_output(fit_result.result_str_dict)
            except:
                formated_results = 'this fit does not return formatted results'
            self._mw.fit_results_DisplayWidget.setPlainText(formated_results)

        if fit_name is not None:
            self._mw.fit_methods_ComboBox.setCurrentFit(fit_name)

        # check which fit method is used and show the curve in the plot accordingly
        if fit_name != 'No Fit':
            self.curve_fit.setData(
                x=self._wm_logger_logic.wlog_fit_x,
                y=self._wm_logger_logic.wlog_fit_y)

            if self.curve_fit not in self._mw.plotWidget.listDataItems():
                self._mw.plotWidget.addItem(self.curve_fit)
        else:
            if self.curve_fit in self._mw.plotWidget.listDataItems():
                self._mw.plotWidget.removeItem(self.curve_fit)
Exemple #6
0
    def update_fit_display(self):
        """ Do the configured fit and show it in the sum plot """
        fit_name = self._odmr_logic.fc.current_fit
        fit_result = self._odmr_logic.fc.current_fit_result
        fit_param = self._odmr_logic.fc.current_fit_param

        if fit_result is not None:
            # display results as formatted text
            self._mw.odmr_fit_results_DisplayWidget.clear()
            try:
                formated_results = units.create_formatted_output(
                    fit_result.result_str_dict)
            except:
                formated_results = 'this fit does not return formatted results'
            self._mw.odmr_fit_results_DisplayWidget.setPlainText(
                formated_results)

        if fit_name is not None:
            self._mw.fit_methods_ComboBox.setCurrentFit(fit_name)

        # check which Fit method is used and remove or add again the
        # odmr_fit_image, check also whether a odmr_fit_image already exists.
        if fit_name != 'No Fit':
            self.odmr_fit_image.setData(x=self._odmr_logic.ODMR_fit_x,
                                        y=self._odmr_logic.ODMR_fit_y)
            if self.odmr_fit_image not in self._mw.odmr_PlotWidget.listDataItems(
            ):
                self._mw.odmr_PlotWidget.addItem(self.odmr_fit_image)
        else:
            if self.odmr_fit_image in self._mw.odmr_PlotWidget.listDataItems():
                self._mw.odmr_PlotWidget.removeItem(self.odmr_fit_image)

        self._mw.odmr_PlotWidget.getViewBox().updateAutoRange()
    def update_fit(self, fit_data, result_str_dict, current_fit):
        """ Update the drawn fit curve and displayed fit results.
        """
        if current_fit != 'No Fit':
            # display results as formatted text
            self._mw.spectrum_fit_results_DisplayWidget.clear()
            try:
                formated_results = units.create_formatted_output(
                    result_str_dict)
            except:
                formated_results = 'this fit does not return formatted results'
            self._mw.spectrum_fit_results_DisplayWidget.setPlainText(
                formated_results)

            # redraw the fit curve in the GUI plot.
            self._curve2.setData(x=fit_data[0, :], y=fit_data[1, :])
Exemple #8
0
    def fit_clicked(self):
        """ Do the configured fit and show it in the sum plot """
        self._mw.fit_param_TextEdit.clear()

        current_fit_function = self._mw.fit_methods_ComboBox.currentText()

        fit_x, fit_y, fit_param_dict, fit_result = self._trace_analysis.do_fit(fit_function=current_fit_function)

        self._fit_image.setData(x=fit_x, y=fit_y, pen=pg.mkPen(palette.c2, width=2))

        if len(fit_param_dict) == 0:
            fit_result = 'No Fit parameter passed.'

        else:
            fit_result = units.create_formatted_output(fit_param_dict)
        self._mw.fit_param_TextEdit.setPlainText(fit_result)

        return
    def fit_clicked(self):
        """ Do the configured fit and show it in the sum plot """
        self._mw.fit_param_TextEdit.clear()

        current_fit_function = self._mw.fit_methods_ComboBox.currentText()

        fit_x, fit_y, fit_param_dict, fit_result = self._trace_analysis.do_fit(fit_function=current_fit_function)

        self._fit_image.setData(x=fit_x, y=fit_y, pen=pg.mkPen(palette.c2, width=2))

        if len(fit_param_dict) == 0:
            fit_result = 'No Fit parameter passed.'

        else:
            fit_result = units.create_formatted_output(fit_param_dict)
        self._mw.fit_param_TextEdit.setPlainText(fit_result)

        return
Exemple #10
0
    def updateFit(self):
        """ Do the configured fit and show it in the plot """
        fit_name = self._laser_logic.fc.current_fit
        fit_result = self._laser_logic.fc.current_fit_result
        fit_param = self._laser_logic.fc.current_fit_param

        if fit_result is not None:
            # display results as formatted text
            self._mw.fit_results_DisplayWidget.clear()
            try:
                formated_results = units.create_formatted_output(
                    fit_result.result_str_dict)
            except:
                formated_results = 'this fit does not return formatted results'
            self._mw.fit_results_DisplayWidget.setPlainText(formated_results)

        if fit_name is not None:
            self._mw.fit_methods_ComboBox.setCurrentFit(fit_name)

        # check which fit method is used and show the curve in the plot accordingly
        if fit_name != 'No Fit':
            self.curve_fit.setData(x=self._laser_logic.wlog_fit_x,
                                   y=self._laser_logic.wlog_fit_y)

            if self.curve_fit not in self._mw.plotWidget.listDataItems():
                self._mw.plotWidget.addItem(self.curve_fit)
        else:
            if self.curve_fit in self._mw.plotWidget.listDataItems():
                self._mw.plotWidget.removeItem(self.curve_fit)


#https://doc.qt.io/qt-5/signalsandslots.html
#When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal
# function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop.
# Execution of the code following the emit statement will occur once all slots have returned. The situation
# is slightly different when using queued connections; in such a case, the code following the emit keyword
# will continue immediately, and the slots will be executed later.

#Seems wrong??? sigStartQueryLoop is connected NOT through a queued connection and the function doesn't wait
#for the slots to complete. "slot returning" must just mean that the slot has begun executing???
Exemple #11
0
    def do_fit(self, fit_method, plot_index=0):
        """ Get the data of the x-axis being plotted.
        
        @param str fit_method: name of the fit_method, this needs to match the methods in
                               fit_container.
        @param int plot_index: index of the plot in the range from 0 to 2
        @return int plot_index, 3D np.ndarray fit_data, str result, str fit_method: result of fit
        """
        with self.threadlock:
            if not (0 <= plot_index < self.number_of_plots):
                raise IndexError(
                    'Plot index {0:d} out of bounds. Unable to perform data fit.'
                    .format(plot_index))
            # check that the fit_method is correct
            if fit_method is None or isinstance(fit_method, str):
                if fit_method not in self.fit_container.fit_list:
                    if fit_method is not None and fit_method != 'No Fit':
                        self.log.warning(
                            'Fit function "{0}" not available in fit container. Configure '
                            'available fits first.'.format(fit_method))
                    fit_method = 'No Fit'
            else:
                raise TypeError(
                    'Parameter fit_method must be str or None type.')

            result = ''
            fit_data = list()

            # do one fit for each data set in the plot
            for data_set in range(len(self._x_data[plot_index])):
                x_data = self._x_data[plot_index][data_set]
                y_data = self._y_data[plot_index][data_set]

                self.fit_container.set_current_fit(fit_method)

                # only fit if the is enough data to actually do the fit
                if len(x_data) < 2 or len(y_data) < 2 or min(x_data) == max(
                        x_data):
                    self.log.warning(
                        'The data you are trying to fit does not contain enough points for a fit.'
                    )
                    return (plot_index,
                            np.zeros(shape=(len(self._x_data[plot_index]), 2,
                                            10)), 'results',
                            self.fit_container.current_fit)

                # actually do the fit
                fit_x, fit_y, result_set = self.fit_container.do_fit(
                    np.array(x_data), np.array(y_data))
                fit_data_set = np.array([fit_x, fit_y])
                fit_data.append(fit_data_set)

                # Get formatted result string and concatenate the results of the data sets
                if fit_method == 'No Fit':
                    formatted_fitresult = 'No Fit'
                else:
                    try:
                        formatted_fitresult = units.create_formatted_output(
                            result_set.result_str_dict)
                    except:
                        formatted_fitresult = 'This fit does not return formatted results'
                tabbed_result = '\n  '.join(
                    formatted_fitresult.split('\n')[:-1])
                result += 'data_set {0}:\n  {1}\n'.format(
                    data_set, tabbed_result)

            # convert list to np.ndarray to make handling it much more efficient
            fit_data = np.array(fit_data)

            # save the fit results internally
            self._fit_data[plot_index] = fit_data
            self._fit_results[plot_index] = result
            self._fit_method[plot_index] = fit_method

            self.sigFitUpdated.emit(plot_index, fit_data, result,
                                    self.fit_container.current_fit)
            return plot_index, fit_data, result, self.fit_container.current_fit