def do_fit_neon(self): self.peak_threshold = self.calib_threshold_entry.value() self.peak_threshold = float(self.peak_threshold) self.do_acquisition() self.neon_fit_param, self.neon_fit_data = pressure.neon_fit( self.wavelength, self.intensity, self.peak_threshold) if self.fit_plot is not None: self.ax.lines.remove(self.fit_plot_[0]) self.fit_plot_ = self.ax.plot(self.wavelength, self.neon_fit_data, "b-", lw=1.5) self.fit_plot = 1 self.canvas.draw() #Getting the fitted peaks positions n = len(self.neon_fit_param.keys()) - 1 n = n / 4 #Number of peaks self.neon_peaks_positions = [] #fitted positions in wavelength for i in range(n): x = self.neon_fit_param["X%d" % i].value self.neon_peaks_positions.append(x) self.neon_peaks_positions = sorted(self.neon_peaks_positions) self.true_neon_wl_index = peak.get_index_from_values( __NEON_PEAKS__, self.neon_peaks_positions) self.neon_true_wavelength = __NEON_PEAKS__[self.true_neon_wl_index] self.measured_wl_pixel = peak.get_index_from_values( self.wavelength, self.neon_peaks_positions) self.calibrated_coefficients = pressure.calibration_coefficients( self.measured_wl_pixel, self.neon_true_wavelength)
def get_maxima(x, y, threshold=0.3): ind = peak.indexes(y, thres=threshold, min_dist=20) x_peaks = peak.interpolate(x, y, ind, width=20, func=peak.lorentzian_fit) #lorentzian_fit new_ind = peak.get_index_from_values(x, x_peaks) y_peaks = y[new_ind] return (x_peaks, y_peaks)
def neon_fit(x,y,threshold): ind = peak.indexes(y, thres=threshold, min_dist=30) x_peaks = peak.interpolate(x,y,ind, width=15, func = peak.lorentzian_fit) new_ind = peak.get_index_from_values(x, x_peaks) y_peaks = y[new_ind] param_init = neon_init(x_peaks, y_peaks) result = minimize(objective, param_init, args=(y,x, "neon")) y = neon_model(result.params, x) return result.params, y
def neon_fit(x, y, threshold): ind = peak.indexes(y, thres=threshold, min_dist=30) x_peaks = peak.interpolate(x, y, ind, width=15, func=peak.lorentzian_fit) new_ind = peak.get_index_from_values(x, x_peaks) y_peaks = y[new_ind] param_init = neon_init(x_peaks, y_peaks) result = minimize(objective, param_init, args=(y, x, "neon")) y = neon_model(result.params, x) return result.params, y
def do_fit_neon(self): self.peak_threshold = self.calib_threshold_entry.value() self.peak_threshold = float(self.peak_threshold) self.do_acquisition() self.neon_fit_param, self.neon_fit_data = pressure.neon_fit(self.wavelength,self.intensity, self.peak_threshold) if self.fit_plot is not None: self.ax.lines.remove(self.fit_plot_[0]) self.fit_plot_ = self.ax.plot(self.wavelength, self.neon_fit_data, "b-", lw=1.5) self.fit_plot = 1 self.canvas.draw() #Getting the fitted peaks positions n = len(self.neon_fit_param.keys())-1 n = n/4#Number of peaks self.neon_peaks_positions = []#fitted positions in wavelength for i in range(n): x = self.neon_fit_param["X%d"%i].value self.neon_peaks_positions.append(x) self.neon_peaks_positions = sorted(self.neon_peaks_positions) self.true_neon_wl_index = peak.get_index_from_values(__NEON_PEAKS__, self.neon_peaks_positions) self.neon_true_wavelength = __NEON_PEAKS__[self.true_neon_wl_index] self.measured_wl_pixel = peak.get_index_from_values(self.wavelength, self.neon_peaks_positions) self.calibrated_coefficients = pressure.calibration_coefficients(self.measured_wl_pixel, self.neon_true_wavelength)
# fit_param,fit_data = neon_fit(wavelength,intensity, 0.13) fit_param,fit_data = neon_fit(wavelength,intensity, 0.055) # f=figure() # ax=f.add_subplot(111) # ax.plot(wavelength, intensity, "ko") # ax.plot(wavelength, fit_data, "r-") # ax.bar(WL, INT, width=0.3, color="b") # show() nbr_peaks = len(fit_param.keys()) -1 nbr_peaks = nbr_peaks/4 fitted_wl = [] fitted_in = [] for i in range(nbr_peaks): wl = fit_param["X%d"%i].value inten = neon_model(fit_param, wl) fitted_wl.append(wl) fitted_in.append(inten) fitted_wl = np.array(fitted_wl) fitted_in = np.array(fitted_in) f2=figure() ax2=f2.add_subplot(111) ax2.plot(wavelength, intensity, "k-") # ax2.bar(fitted_wl, fitted_in, width=0.2, color="red") ax2.plot(wavelength, fit_data, "r-") for i in range(len(WL)): ax2.axvline(WL[i],color="g") true_ind = peak.get_index_from_values(WL, fitted_wl) true_wl = WL[true_ind] for i in range(len(true_wl)): ax2.text(fitted_wl[i], 0.2, str(round(true_wl[i],3))) show()
# fit_param,fit_data = neon_fit(wavelength,intensity, 0.13) fit_param, fit_data = neon_fit(wavelength, intensity, 0.055) # f=figure() # ax=f.add_subplot(111) # ax.plot(wavelength, intensity, "ko") # ax.plot(wavelength, fit_data, "r-") # ax.bar(WL, INT, width=0.3, color="b") # show() nbr_peaks = len(fit_param.keys()) - 1 nbr_peaks = nbr_peaks / 4 fitted_wl = [] fitted_in = [] for i in range(nbr_peaks): wl = fit_param["X%d" % i].value inten = neon_model(fit_param, wl) fitted_wl.append(wl) fitted_in.append(inten) fitted_wl = np.array(fitted_wl) fitted_in = np.array(fitted_in) f2 = figure() ax2 = f2.add_subplot(111) ax2.plot(wavelength, intensity, "k-") # ax2.bar(fitted_wl, fitted_in, width=0.2, color="red") ax2.plot(wavelength, fit_data, "r-") for i in range(len(WL)): ax2.axvline(WL[i], color="g") true_ind = peak.get_index_from_values(WL, fitted_wl) true_wl = WL[true_ind] for i in range(len(true_wl)): ax2.text(fitted_wl[i], 0.2, str(round(true_wl[i], 3))) show()