Exemple #1
0
def profile(peaklist,
            fwhm=0.1,
            points=10,
            noise=0,
            raster=None,
            forceFwhm=False,
            model='gaussian'):
    """Make profile spectrum for given peaklist.
        peaklist (mspy.peaklist) - peaklist
        fwhm (float) - default peak fwhm
        points (int) - default number of points per peak width (not used if raster is given)
        noise (float) - random noise width
        raster (1D numpy.array) - m/z raster
        forceFwhm (bool) - use default fwhm for all peaks
        model (gaussian, lorentzian, gausslorentzian) - peak shape function
    """

    # check peaklist type
    if not isinstance(peaklist, obj_peaklist.peaklist):
        peaklist = obj_peaklist.peaklist(peaklist)

    # check raster type
    if raster != None and not isinstance(raster, numpy.ndarray):
        raster = numpy.array(raster)

    # get peaks
    peaks = []
    for peak in peaklist:
        peaks.append([peak.mz, peak.intensity, peak.fwhm])
        if forceFwhm or not peak.fwhm:
            peaks[-1][2] = fwhm

    # get model
    shape = 0
    if model == 'gaussian':
        shape = 0
    elif model == 'lorentzian':
        shape = 1
    elif model == 'gausslorentzian':
        shape = 2

    # make profile
    if raster != None:
        data = calculations.signal_profile_to_raster(numpy.array(peaks),
                                                     raster, float(noise),
                                                     shape)
    else:
        data = calculations.signal_profile(numpy.array(peaks), int(points),
                                           float(noise), shape)

    # make baseline
    baseline = []
    for peak in peaklist:
        if not baseline or baseline[-1][0] != peak.mz:
            baseline.append([peak.mz, -peak.base])

    # apply baseline
    data = mod_signal.subbase(data, numpy.array(baseline))

    return data
Exemple #2
0
def profile(peaklist, fwhm=0.1, points=10, noise=0, raster=None, forceFwhm=False, model='gaussian'):
    """Make profile spectrum for given peaklist.
        peaklist (mspy.peaklist) - peaklist
        fwhm (float) - default peak fwhm
        points (int) - default number of points per peak width (not used if raster is given)
        noise (float) - random noise width
        raster (1D numpy.array) - m/z raster
        forceFwhm (bool) - use default fwhm for all peaks
        model (gaussian, lorentzian, gausslorentzian) - peak shape function
    """

    # check peaklist type
    if not isinstance(peaklist, obj_peaklist.peaklist):
        peaklist = obj_peaklist.peaklist(peaklist)

    # check raster type
    if raster != None and not isinstance(raster, numpy.ndarray):
        raster = numpy.array(raster)

    # get peaks
    peaks = []
    for peak in peaklist:
        peaks.append([peak.mz, peak.intensity, peak.fwhm])
        if forceFwhm or not peak.fwhm:
            peaks[-1][2] = fwhm

    # get model
    shape = 0
    if model == 'gaussian':
        shape = 0
    elif model == 'lorentzian':
        shape = 1
    elif model == 'gausslorentzian':
        shape = 2

    # make profile
    if raster != None:
        data = calculations.signal_profile_to_raster(numpy.array(peaks), raster, float(noise), shape)
    else:
        data = calculations.signal_profile(numpy.array(peaks), int(points), float(noise), shape)

    # make baseline
    baseline = []
    for peak in peaklist:
        if not baseline or baseline[-1][0] != peak.mz:
            baseline.append([peak.mz, -peak.base])

    # apply baseline
    data = mod_signal.subbase(data, numpy.array(baseline))

    return data
Exemple #3
0
    def tospectrum(self,
                   signal,
                   fwhm=0.1,
                   forceFwhm=True,
                   autoAlign=True,
                   iterLimit=None,
                   relThreshold=0.,
                   pickingHeight=0.90,
                   baseline=None):
        """Fit modeled profiles to spectrum using tmp peaklist.
            signal (numpy array) - m/z / intensity pairs
            fwhm (float) - defaut fwhm
            forceFwhm (bool) - use default fwhm
            autoAlign (bool) - automatic m/z shift
            iterLimit (int) - maximum number of iterations
            pickingHeight (float) - peak picking height for centroiding
            relThreshold (float) - relative intensity threshold
            baseline (numpy array) - signal baseline
        """

        # crop signal to relevant m/z range
        i1 = mod_signal.locate(signal, self.mzrange[0])
        i2 = mod_signal.locate(signal, self.mzrange[1])
        signal = signal[i1:i2]

        # get peaklist from signal
        peaklist = mod_peakpicking.labelscan(signal=signal,
                                             pickingHeight=pickingHeight,
                                             relThreshold=relThreshold,
                                             baseline=baseline)

        # remove shoulder peaks
        peaklist.remshoulders(fwhm=fwhm)

        # correct signal baseline
        if baseline != None:
            self.spectrum = mod_signal.subbase(signal, baseline)

        # fit to peaklist
        return self.topeaklist(
            peaklist=peaklist,
            fwhm=fwhm,
            forceFwhm=forceFwhm,
            autoAlign=autoAlign,
            iterLimit=iterLimit,
            relThreshold=relThreshold,
        )
Exemple #4
0
    def subbase(self, window=0.1, offset=0.0):
        """Subtract baseline from profile.
            window (float or None) - noise calculation window (%/100)
            offset (float) - baseline offset, relative to noise width (in %/100)
        """

        # get baseline
        baseline = self.baseline(window=window, offset=offset)

        # subtract baseline
        profile = mod_signal.subbase(signal=self.profile, baseline=baseline)

        # store data
        self.profile = profile
        self.peaklist.empty()

        # clear buffers
        self.reset()
Exemple #5
0
    def subbase(self, window=0.1, offset=0.):
        """Subtract baseline from profile.
            window (float or None) - noise calculation window (%/100)
            offset (float) - baseline offset, relative to noise width (in %/100)
        """

        # get baseline
        baseline = self.baseline(window=window, offset=offset)

        # subtract baseline
        profile = mod_signal.subbase(signal=self.profile, baseline=baseline)

        # store data
        self.profile = profile
        self.peaklist.empty()

        # clear buffers
        self.reset()
Exemple #6
0
 def tospectrum(self, signal, fwhm=0.1, forceFwhm=True, autoAlign=True, iterLimit=None, relThreshold=0., pickingHeight=0.90, baseline=None):
     """Fit modeled profiles to spectrum using tmp peaklist.
         signal (numpy array) - m/z / intensity pairs
         fwhm (float) - defaut fwhm
         forceFwhm (bool) - use default fwhm
         autoAlign (bool) - automatic m/z shift
         iterLimit (int) - maximum number of iterations
         pickingHeight (float) - peak picking height for centroiding
         relThreshold (float) - relative intensity threshold
         baseline (numpy array) - signal baseline
     """
     
     # crop signal to relevant m/z range
     i1 = mod_signal.locate(signal, self.mzrange[0])
     i2 = mod_signal.locate(signal, self.mzrange[1])
     signal = signal[i1:i2]
     
     # get peaklist from signal
     peaklist = mod_peakpicking.labelscan(
         signal = signal,
         pickingHeight = pickingHeight,
         relThreshold = relThreshold,
         baseline = baseline
     )
     
     # remove shoulder peaks
     peaklist.remshoulders(fwhm=fwhm)
     
     # correct signal baseline
     if baseline != None:
         self.spectrum = mod_signal.subbase(signal, baseline)
     
     # fit to peaklist
     return self.topeaklist(
         peaklist = peaklist,
         fwhm = fwhm,
         forceFwhm = forceFwhm,
         autoAlign = autoAlign,
         iterLimit = iterLimit,
         relThreshold = relThreshold,
     )