def _generateNormalization(self, WS, normType, normWS): if normType == 'None': return None elif normType == "Extracted from Data": window = self.getProperty("PeakClippingWindowSize").value smooth_range = self.getProperty("SmoothingRange").value peak_clip_WS = CloneWorkspace(InputWorkspace=WS, OutputWorkspace='peak_clip_WS') n_histo = peak_clip_WS.getNumberHistograms() x = peak_clip_WS.extractX() y = peak_clip_WS.extractY() e = peak_clip_WS.extractE() for h in range(n_histo): peak_clip_WS.setX(h, x[h]) peak_clip_WS.setY( h, self.peak_clip(y[h], win=window, decrese=True, LLS=True, smooth_window=smooth_range)) peak_clip_WS.setE(h, e[h]) return 'peak_clip_WS' else: # other values are already held in normWS return normWS
def PyExec(self): # get input inws = self.getProperty("InputWorkspace").value niter = self.getProperty("NIterations").value xwindow = self.getProperty("XWindow").value doSGfilter = self.getProperty('ApplyFilterSG').value # make output workspace outws = CloneWorkspace(inws, OutputWorkspace=self.getProperty("OutputWorkspace").value) # loop over all spectra nbins = inws.blocksize() nspec = inws.getNumberHistograms() prog_reporter = Progress(self, start=0.0, end=1.0, nreports=nspec) for ispec in range(0, nspec): prog_reporter.report() # get n points in convolution window binwidth = np.mean(np.diff(inws.readX(ispec))) nwindow = int(np.ceil(xwindow / binwidth)) if not nwindow % 2: nwindow += 1 if nwindow < self.MIN_WINDOW_SIZE: raise RuntimeError('Convolution window must have at least three points') elif not nwindow < nbins: # not effective due to edge effects of the convolution raise RuntimeError("Data has must have at least the number of points as the convolution window") # do initial filter to remove very high intensity points if doSGfilter: ybg = savgol_filter(inws.readY(ispec), nwindow, polyorder=1) else: ybg = np.copy(inws.readY(ispec)) Ibar = np.mean(ybg) Imin = np.min(ybg) ybg[ybg > (Ibar + 2 * (Ibar - Imin))] = (Ibar + 2 * (Ibar - Imin)) # perform iterative smoothing ybg = self.doIterativeSmoothing(ybg, nwindow, niter) # replace intensity in output spectrum with background outws.setY(ispec, ybg) outws.setE(ispec, np.zeros(ybg.shape)) # set output self.setProperty("OutputWorkspace", outws)
def _generateNormalization(self, WS, normType, normWS): if normType == 'None': return None elif normType == "Extracted from Data": window = self.getProperty("PeakClippingWindowSize").value smooth_range = self.getProperty("SmoothingRange").value peak_clip_WS = CloneWorkspace(WS) n_histo = peak_clip_WS.getNumberHistograms() x = peak_clip_WS.extractX() y = peak_clip_WS.extractY() e = peak_clip_WS.extractE() for h in range(n_histo): peak_clip_WS.setX(h, x[h]) peak_clip_WS.setY(h, self.peak_clip(y[h], win=window, decrese=True, LLS=True, smooth_window=smooth_range)) peak_clip_WS.setE(h, e[h]) return peak_clip_WS else: # other values are already held in normWS return normWS