def _alignData(self): """Re-calibrate data using theoretical envelope.""" # split data to raster and intensities xAxis, yAxis = numpy.hsplit(self.data, 2) raster = xAxis.flatten() intensities = yAxis.flatten() # model profiles models, exchanged = self._makeModels(raster) # fit current data fit = self._leastSquare(intensities, models, iterLimit=len(self.models)) # get all isotopes for all used models isotopes = [] for i, abundance in enumerate(fit): pattern = self.models[exchanged[i]][1] isotopes += [(p[0], p[1]*abundance) for p in pattern] # check isotopes if not isotopes: return # make total envelope profile = mod_pattern.profile(isotopes, fwhm=self.fwhm, points=10, model=self.peakShape) # label peaks in profile peaklist = mod_peakpicking.labelscan(profile, pickingHeight=0.95, relThreshold=0.01) # find useful calibrants calibrants = [] tolerance = self.fwhm/1.5 for peak in peaklist: for point in self.data: error = point[0] - peak.mz if abs(error) <= tolerance: if calibrants and calibrants[-1][0] == peak.mz and calibrants[-1][1] < point[1]: calibrants[-1] = (point[0], peak.mz) else: calibrants.append((point[0], peak.mz)) elif error > tolerance: break # calc calibration if len(calibrants) > 3: model, params, chi = mod_calibration.calibration(calibrants, model='quadratic') elif len(calibrants) > 1: model, params, chi = mod_calibration.calibration(calibrants, model='linear') else: return # apply calibration to data for x in range(len(self.data)): self.data[x][0] = model(params, self.data[x][0]) for x in range(len(self.spectrum)): self.spectrum[x][0] = model(params, self.spectrum[x][0])
def envelope(self, points=10): """Make envelope for current composition.""" # get isotopes isotopes = [] for x in self.models: abundance = self.models[x][2] isotopes += [(p[0], p[1]*abundance) for p in self.models[x][1]] # make profile from isotopes profile = mod_pattern.profile(isotopes, fwhm=self.fwhm, points=points, model=self.peakShape) return profile
def envelope(self, points=10): """Make envelope for current composition.""" # get isotopes isotopes = [] for x in self.models: abundance = self.models[x][2] isotopes += [(p[0], p[1] * abundance) for p in self.models[x][1]] # make profile from isotopes profile = mod_pattern.profile(isotopes, fwhm=self.fwhm, points=points, model=self.peakShape) return profile
def _makeModels(self, raster, reset=True): """Calculate pattern for every model.""" models = [] exchanged = [] # get raster rasterMin = raster[0] - self.fwhm rasterMax = raster[-1] + self.fwhm for x in sorted(self.models.keys()): CHECK_FORCE_QUIT() # get compound compound = self.models[x][0] # check if mz is within raster mz = compound.mz(self.charge) if mz[0] > rasterMax or mz[1] < rasterMin: continue # calculate isotopic pattern pattern = self.models[x][1] if reset or pattern == []: pattern = compound.pattern(fwhm=self.fwhm, charge=self.charge, real=False) self.models[x][1] = pattern # calculate model profile profile = mod_pattern.profile(pattern, fwhm=self.fwhm, raster=raster, model=self.peakShape) model = profile[:, 1].flatten() # check model profile if model.any(): models.append(model) exchanged.append(x) # make models matrix models = numpy.array(models) return models, exchanged
def _makeModels(self, raster, reset=True): """Calculate pattern for every model.""" models = [] exchanged = [] # get raster rasterMin = raster[0] - self.fwhm rasterMax = raster[-1] + self.fwhm for x in sorted(self.models.keys()): CHECK_FORCE_QUIT() # get compound compound = self.models[x][0] # check if mz is within raster mz = compound.mz(self.charge) if mz[0] > rasterMax or mz[1] < rasterMin: continue # calculate isotopic pattern pattern = self.models[x][1] if reset or pattern == []: pattern = compound.pattern(fwhm=self.fwhm, charge=self.charge, real=False) self.models[x][1] = pattern # calculate model profile profile = mod_pattern.profile(pattern, fwhm=self.fwhm, raster=raster, model=self.peakShape) model = profile[:,1].flatten() # check model profile if model.any(): models.append(model) exchanged.append(x) # make models matrix models = numpy.array(models) return models, exchanged
def _alignData(self): """Re-calibrate data using theoretical envelope.""" # split data to raster and intensities xAxis, yAxis = numpy.hsplit(self.data, 2) raster = xAxis.flatten() intensities = yAxis.flatten() # model profiles models, exchanged = self._makeModels(raster) # fit current data fit = self._leastSquare(intensities, models, iterLimit=len(self.models)) # get all isotopes for all used models isotopes = [] for i, abundance in enumerate(fit): pattern = self.models[exchanged[i]][1] isotopes += [(p[0], p[1] * abundance) for p in pattern] # check isotopes if not isotopes: return # make total envelope profile = mod_pattern.profile(isotopes, fwhm=self.fwhm, points=10, model=self.peakShape) # label peaks in profile peaklist = mod_peakpicking.labelscan(profile, pickingHeight=0.95, relThreshold=0.01) # find useful calibrants calibrants = [] tolerance = self.fwhm / 1.5 for peak in peaklist: for point in self.data: error = point[0] - peak.mz if abs(error) <= tolerance: if calibrants and calibrants[-1][ 0] == peak.mz and calibrants[-1][1] < point[1]: calibrants[-1] = (point[0], peak.mz) else: calibrants.append((point[0], peak.mz)) elif error > tolerance: break # calc calibration if len(calibrants) > 3: model, params, chi = mod_calibration.calibration(calibrants, model='quadratic') elif len(calibrants) > 1: model, params, chi = mod_calibration.calibration(calibrants, model='linear') else: return # apply calibration to data for x in range(len(self.data)): self.data[x][0] = model(params, self.data[x][0]) for x in range(len(self.spectrum)): self.spectrum[x][0] = model(params, self.spectrum[x][0])