Example #1
0
    def determine_actual_time(self):
        time, intensity = zip(*self.peak_data)
        if self.coeff.any():
            intensity = gauss_function(time, *self.coeff)
            intensity = intensity.tolist()

        max_intensity_index = intensity.index(max(intensity))
        self.actual_time = time[max_intensity_index]
Example #2
0
    def fit_gaussian_data(self):
        gauss_start = self.peak_time-3*self.peak.coeff[2]
        gauss_end = self.peak_time+3*self.peak.coeff[2]

        gauss_time = linspace(gauss_start, gauss_end, (gauss_end-
                              gauss_start)*1000)
        gauss_intensity = gauss_function(gauss_time, *self.peak.coeff)

        self.gauss_data = list(zip(gauss_time, gauss_intensity))
Example #3
0
    def determine_gaussian_area(self):
        time, intensity = zip(*self.peak_data)
        gaussian_area = 0.

        for index, _ in enumerate(intensity[self.low:self.high]):
            gaussian_area += max(
                gauss_function(time[self.low + index], *self.coeff),
                0) * (time[self.low + index] - time[self.low + index - 1])

        self.gaussian_area = gaussian_area
Example #4
0
    def plot_individual(self):
        time, intensity = zip(
            *self.master.peak.peak_data[self.master.peak.low:self.master.peak.
                                        high])

        f = InterpolatedUnivariateSpline(time, intensity)

        new_x = linspace(time[0], time[-1], 2500 * (time[-1] - time[0]))
        new_y = f(new_x)

        if self.master.peak.coeff.size > 0:
            new_gauss_x = linspace(time[0], time[-1],
                                   2500 * (time[-1] - time[0]))
            new_gauss_y = gauss_function(new_gauss_x, *self.master.peak.coeff)

        self.axes.clear()
        self.axes.plot(time, intensity, 'b*')
        self.axes.plot(
            (new_x[0], new_x[-1]),
            (self.master.peak.background, self.master.peak.background), 'red')
        self.axes.plot((new_x[0], new_x[-1]),
                       (self.master.peak.background + self.master.peak.noise,
                        self.master.peak.background + self.master.peak.noise),
                       color='green')
        self.axes.plot(new_x, new_y, color='blue', linestyle='dashed')
        if self.master.peak.coeff.size > 0:
            self.axes.plot(new_gauss_x,
                           new_gauss_y,
                           color='green',
                           linestyle='dashed')
        self.axes.plot((time[intensity.index(
            max(intensity))], time[intensity.index(max(intensity))]),
                       (self.master.peak.background, max(intensity)),
                       color='orange',
                       linestyle='dotted')
        self.axes.plot(
            (min(
                max(self.master.peak.center - self.master.peak.width,
                    new_x[0]), new_x[-1]),
             max(
                 min(self.master.peak.center + self.master.peak.width,
                     new_x[-1]), new_x[0])),
            (self.master.peak.height, self.master.peak.height),
            color='red',
            linestyle='dashed')
        self.axes.legend([
            'Raw Data', 'Background', 'Noise', 'Univariate Spline',
            'Gaussian Fit (' + str(int(self.master.peak.residual * 100)) +
            '%)', 'Signal (S/N ' +
            '{0:.2f}'.format(self.master.peak.signal_noise) + ')',
            'FWHM: ' + '{0:.2f}'.format(self.master.peak.fwhm)
        ],
                         loc='best')
        self.axes.set_title('Detail view: ' + str(self.master.peak.peak_name))
        self.pdf.savefig(self.fig)
Example #5
0
    def detect_peaks(self):
        orig_time, orig_intensity = zip(*self.master.chrom.chrom_data)
        curr_intensity = orig_intensity

        time_start = bisect_left(orig_time, self.settings.start)
        time_end = bisect_right(orig_time, self.settings.end)

        # Loop till intensity falls below specified threshold
        while (max(curr_intensity[time_start:time_end]) >
               self.settings.peak_detection_min * max(
               orig_intensity[time_start:time_end])):

            # Explore chromatogram to identify highest peak
            self.explore_chromatogram()

            # Determine parameters of highest peak
            self.determine_peak_parameters()

            # Foo
            if self.peak.coeff.any():
                new_intensity = []
                for index, i in enumerate(curr_intensity):
                    new_intensity.append(i - gauss_function(
                                         orig_time[index], *self.peak.coeff))
                curr_intensity = new_intensity

            # Subtract Gaussian intensity from the current intensity
            self.chrom_data = list(zip(orig_time, curr_intensity))

            # Create Gaussian data at 3 sigma width
            self.fit_gaussian_data()

            # Store detected peak
            self.detected_peaks.append({'data':self.gauss_data,
                                        'coeff': self.peak.coeff,
                                        'central_time': self.peak_time})

        # Sort by retention time
        self.detected_peaks = sorted(self.detected_peaks, key=lambda x:
                                     x['central_time'])

        # Restore original data
        self.master.chrom.chrom_data = list(zip(orig_time, orig_intensity))
Example #6
0
    def determine_height(self):
        edge = self.center + self.width
        height = gauss_function(edge, *self.coeff)

        self.height = height