예제 #1
0
파일: esr.py 프로젝트: ziweiqiu/b26_toolkit
    def _update_plot(self, axes_list):
        """
        plotting function for esr
        Args:
            axes_list: list of axes objects on which to plot plots the esr on the first axes object
            data: data (dictionary that contains keys frequency, data and fit_params) if not provided use self.data
        Returns:

        """
        data = self.data

        plot_esr(axes_list[0], data['frequency'], data['data'], data['fit_params'])
예제 #2
0
    def _plot(self, axes_list, data=None):
        """
        plotting function for esr
        Args:
            axes_list: list of axes objects on which to plot plots the esr on the first axes object
            data: data (dictionary that contains keys frequency, data and fit_params) if not provided use self.data
        Returns:

        """
        if data is None:
            data = self.data

        mean_counts = self.current_avg_cnts

        plot_esr(axes_list[0],
                 data['frequency'],
                 data['data'],
                 data['fit_params'],
                 avg_counts=mean_counts)
예제 #3
0
            def display_data(lower_peak_widget = None, upper_peak_widget = None, display_fit = True):
                # find the NV index
                pt_id = int(os.path.basename(esr_folder).split('pt_')[-1])

                findnv_folder = glob.glob(folder + '\\data_subscripts\\*find_nv*pt_*{:d}'.format(pt_id))[0]

                f.clf()
                gs = gridspec.GridSpec(1, 2, width_ratios=[3, 1])
                ax0 = plt.subplot(gs[0])
                ax1 = plt.subplot(gs[1])
                ax = [ax0, ax1]
                plt.suptitle('NV #{:d}'.format(pt_id), fontsize=16)

                # load data
                data = Script.load_data(esr_folder)
                if lower_fit_widget.value == 0 and upper_fit_widget.value == 10e9:
                    freq = data['frequency']
                    ampl = data['data']
                else:
                    freq = data['frequency'][np.logical_and(data['frequency'] > lower_fit_widget.value, data['frequency'] < upper_fit_widget.value)]
                    ampl = data['data'][np.logical_and(data['frequency'] > lower_fit_widget.value, data['frequency'] < upper_fit_widget.value)]
                if lower_peak_widget is None:
                    fit_params = fit_data_set_array[pt_id, 2:8]
                else:
                    lower_peak = lower_peak_widget.value
                    upper_peak = upper_peak_widget.value
                    if upper_peak == 0:
                        start_vals = get_lorentzian_fit_starting_values(freq, ampl)
                        start_vals[2] = lower_peak
                        start_vals[1] = ampl[np.argmin(np.abs(freq - lower_peak))] - start_vals[0]
                        try:
                            fit_params = fit_lorentzian(freq, ampl, starting_params=start_vals,
                                                 bounds=[(0, -np.inf, 0, 0), (np.inf, 0, np.inf, np.inf)])
                        except:
                            # ESR fit failed!
                            fit_params = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]

                    else:
                        center_freq = np.mean(freq)
                        start_vals = []
                        start_vals.append(
                            get_lorentzian_fit_starting_values(freq[freq < center_freq], ampl[freq < center_freq]))
                        start_vals.append(
                            get_lorentzian_fit_starting_values(freq[freq > center_freq], ampl[freq > center_freq]))
                        start_vals = [
                            np.mean([start_vals[0][0], start_vals[1][0]]),  # offset
                            np.sum([start_vals[0][3], start_vals[1][3]]),  # FWHM
                            ampl[np.argmin(np.abs(freq-lower_peak))] - start_vals[0][0], ampl[np.argmin(np.abs(freq-upper_peak))]- start_vals[1][0],  # amplitudes
                            lower_peak, upper_peak  # centers
                        ]
                        try:
                            fit_params = fit_double_lorentzian(freq, ampl, starting_params=start_vals, bounds=
                            [(0, 0, -np.inf, -np.inf, min(freq), min(freq)), (np.inf, np.inf, 0, 0, max(freq), max(freq))])
                        except:
                            fit_params = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]

                if len(fit_params) == 4 or np.isnan(fit_params[4]):
                    fit_params = fit_params[0:4]

                # get nv positions
                #             data_pos = {'initial_point': [fit_data_set['xo'].values[pt_id]]}
                data_pos = Script.load_data(findnv_folder)
                #             pos = data_pos['maximum_point']
                #             pos_init = data_pos['initial_point']

                # plot NV image
                FindNV.plot_data([ax[1]], data_pos)

                # plot data and fits
                # print("fit_params: ", fit_params)

                sys.stdout.flush()

                if display_fit:
                    plot_esr(ax[0], data['frequency'], data['data'], fit_params=fit_params)
                else:
                    plot_esr(ax[0], data['frequency'], data['data'], fit_params=[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

                plt.tight_layout()
                plt.subplots_adjust(top=0.85) # Makes room at top of plot for figure suptitle

                plt.draw()
                plt.show()

                return fit_params, pt_id