def spectrum_baseline(y, x=[], display=0, algorithm='derpsalsa', wl_level=9): """ ---------- x, y : spectral data display : 0, 1 or 2, optional The default is 2. 0: no display, 1: final, 2: verbose with plots algorithm : derpsalsa, psalsa, als, morph_pspline, Koch, wavelet The default is 'derpsalsa'. Returns baseline """ if len(x) == 0: x = np.linspace(0, 1000, num=len(y)) if display > 0: print('algorithm = ', algorithm, ' , starting') if algorithm == 'psalsa': baseline = psalsa_baseline(x, y, display) if algorithm == 'derpsalsa': baseline = derpsalsa_baseline(x, y, display) elif algorithm == 'als': baseline = baseline_als(x, y, display) elif algorithm == 'Koch': baseline = kolifier_morph_baseline(x, y, display) elif algorithm == 'morph_pspline': baseline = morph_pspline_baseline(x, y, display) elif algorithm == 'wavelet': from skued import baseline_dt, spectrum_colors max_iteration_number = 512 baseline = baseline_dt(y, level=wl_level, max_iter=max_iteration_number, wavelet='qshift3') if display >= 1: levels = list(range(wl_level - 2, wl_level + 3)) colors = spectrum_colors(levels) for l, c in zip(levels, colors): if l == wl_level: continue bltmp = baseline_dt(y, level=l, max_iter=max_iteration_number, wavelet='qshift3') plt.plot(x, bltmp, color=c) plt.plot(x, y, 'r', x, baseline, 'k--', linewidth=2) plot_annotation = 'wavelet bl; black-- at level ' + str(wl_level) plt.text(0.5, 0.92, plot_annotation, horizontalalignment='center', verticalalignment='center', transform=plt.gca().transAxes) plt.show() return baseline
def accept(self): directory = QtWidgets.QFileDialog.getExistingDirectory( self, 'Select a directory in which to save the processed files') if not directory: return self.progress_bar.setRange(0, len(self.files)) for index, file in enumerate(self.files, start=1): wavenumbers, counts = np.loadtxt(file, delimiter=',', unpack=True) baseline = baseline_dt(counts, **self.baseline_params) # Assemble the result into two columns: wavenumbers first, then baseline-corrected counts arr = np.empty(shape=(wavenumbers.size, 2)) arr[:, 0] = wavenumbers arr[:, 1] = counts - baseline # Determine the location of the processed file base = os.path.basename(file) processed_fname = os.path.join(directory, 'bs_' + base) np.savetxt(processed_fname, arr, delimiter=',') self.processing_update_signal.emit(index) # Write baseline parameters into a configuration file config = configparser.ConfigParser() config['BASELINE PARAMETERS'] = self.baseline_params with open(os.path.join(directory, 'baseline_parameters.txt'), mode='w') as configfile: config.write(configfile) super().accept()
def compute_baseline(self, first_stage, wavelet, max_iter=50, level=None, **kwargs): """ Compute and save the baseline computed based on the dual-tree complex wavelet transform. All keyword arguments are passed to scikit-ued's `baseline_dt` function. Parameters ---------- first_stage : str, optional Wavelet to use for the first stage. See :func:`skued.available_first_stage_filters` for a list of suitable arguments wavelet : str, optional Wavelet to use in stages > 1. Must be appropriate for the dual-tree complex wavelet transform. See :func:`skued.available_dt_filters` for possible values. max_iter : int, optional level : int or None, optional If None (default), maximum level is used. """ block = self.powder_data(timedelay=None, bgr=False) baseline_kwargs = { "array": block, "max_iter": max_iter, "level": level, "first_stage": first_stage, "wavelet": wavelet, "axis": 1, } baseline_kwargs.update(**kwargs) baseline = np.ascontiguousarray(baseline_dt( **baseline_kwargs)) # In rare cases this wasn't C-contiguous # The baseline dataset is guaranteed to exist after compte_angular_averages was called. self.powder_group["baseline"].resize(baseline.shape) self.powder_group["baseline"].write_direct(baseline) if level == None: level = dt_max_level(data=self.px_radius, first_stage=first_stage, wavelet=wavelet) self.level = level self.first_stage = first_stage self.wavelet = wavelet self.niter = max_iter self.powder_eq.cache_clear()
def compute_baseline(self, params): """ Compute dual-tree complex wavelet baseline. All parameters are passed to scikit-ued's baseline_dt function. """ # Determine the background markers index markers_index = sorted([ np.argmin(np.abs(m - self.abscissa)) for m in self.background_markers ]) params["background_regions"] = markers_index self.baseline = baseline_dt(self.raw_ordinates, **params) self.baseline_plot_signal.emit(self.abscissa, self.baseline)
exptl_s_full = exptl_data.scattering_vector #exptl_data.compute_baseline(first_stage='sym4',wavelet='qshift3') exptl_pattern_w_bg_full = exptl_data.powder_data(0, bgr=False) #keep only relevant parts of pattern start_index = np.min( np.asarray(exptl_s_full > (0.16 * 4 * np.pi)).nonzero()[0]) end_index = np.min(np.asarray(exptl_s_full > (0.75 * 4 * np.pi)).nonzero()[0]) exptl_s = exptl_s_full[start_index:end_index] exptl_pattern_w_bg = exptl_pattern_w_bg_full[start_index:end_index] #baseline removal; first_stage can be set to 'sym4' or 'sym5' baseline = baseline_dt(exptl_pattern_w_bg, first_stage='sym5', wavelet='qshift3', max_iter=100, level=6) exptl_pattern = exptl_pattern_w_bg - baseline mean_crystallite_size = 1.3e3 / (4.0 * np.pi) #in angstroms #mean_crystallite_size = 8e2/(4.0*np.pi) #in angstroms #sgrid = np.linspace(2.5,5,2048) sgrid = np.linspace(2.5, 16.288476969050766, 5096) textured_out, peaks = powderdiff(vo2, sgrid, refs, mean_crystallite_size, count_list=counts) ideal_out, ideal_peaks = powderdiff(vo2, sgrid,
def compute_baseline(self, params): """ Compute dual-tree complex wavelet baseline. All parameters are passed to scikit-ued's baseline_dt function. """ self.baseline = baseline_dt(self.raw_ordinates, **params) self.baseline_plot_signal.emit(self.abscissa, self.baseline)