def _fine_scan_peak(self, cp):
        line, _ = self.graph.new_series(plotid=1)

        c = cp.dac
        w = self.fwindow / 2.0

        steps = self._calc_step_values(c - w, c + w, self.fstep_dac)
        self._scan_dac(steps)

        # get last scan
        xs = line.index.get_data()
        ys = line.value.get_data()

        try:
            center = calculate_peak_center(xs, ys)

            # if not isinstance(center, str):
            [lx, cx, hx], [ly, cy, hy], mx, my = center
            self.graph.add_vertical_rule(cx, plotid=1)
            self.info('new peak center. {} nominal={} dx={}'.format(
                cp.isotope, cp.dac, cx))
            cp.dac += cx
            self._redraw()
        except PeakCenterError as e:
            self.warning(e)
Beispiel #2
0
 def _calculate_peak_center(self, x, y):
     try:
         result = calculate_peak_center(x, y,
                                        min_peak_height=self.min_peak_height)
         return result
     except PeakCenterError, e:
         self.warning('Failed to find a valid peak. {}'.format(e))
Beispiel #3
0
 def _calculate_peak_center(self, x, y):
     result = calculate_peak_center(x, y,
                                    min_peak_height=self.min_peak_height)
     if result is not None:
         if isinstance(result, str):
             self.warning(result)
         else:
             return result
Beispiel #4
0
 def _calculate_peak_center(self, x, y):
     result = calculate_peak_center(x,
                                    y,
                                    min_peak_height=self.min_peak_height)
     if result is not None:
         if isinstance(result, str):
             self.warning(result)
         else:
             return result
Beispiel #5
0
    def _calculate_peak_center(self, x, y):
        # from pychron.core.time_series.time_series import smooth
        # graph = self.graph
        # self._series_factory(graph)
        # smooth_y = smooth(y)
        # graph.set_data(x, series=self._markup_idx-1)
        # graph.set_data(smooth_y, series=self._markup_idx-1, axis=1)

        try:
            result = calculate_peak_center(x, y,
                                           min_peak_height=self.min_peak_height,
                                           percent=self.percent)
            return result
        except PeakCenterError, e:
            self.warning('Failed to find a valid peak. {}'.format(e))
Beispiel #6
0
    def _calculate_peak_center(self, x, y, update_plot):
        if self.use_interpolation:
            f = interpolate.interp1d(x, y, kind=self.interpolation_kind)
            x = linspace(x.min(), x.max(), 500)
            y = f(x)
            if update_plot:
                self.graph.new_series(x, y, line_width=1)
                self.graph.redraw()

        if self.n_peaks > 1:
            self.warning('peak deconvolution disabled')
            # def res(p, y, x):
            #     yfit = None
            #     n = p.shape[0] / 3
            #     for h, m, s in p.reshape(n, 3):
            #         yi = h * norm.pdf(x, m, s)
            #         if yfit is None:
            #             yfit = yi
            #         else:
            #             yfit += yi
            #     err = y - yfit
            #     return err
            #
            # mm = x[y.argmax()]
            # counter = range(self.n_peaks)
            # p = [(1, mm, 1) for _ in counter]
            # plsq = leastsq(res, p, args=(y, x))
            #
            # centers = plsq[0]
            # for i in counter:
            #     c = centers[1 + 3 * i]
            #     self.graph.add_vertical_rule(c, color='blue')
            #
            # return c[1 + 3 * (self.select_peak - 1)]

        try:
            result = calculate_peak_center(x, y,
                                           min_peak_height=self.min_peak_height,
                                           percent=self.percent)
            return result
        except PeakCenterError, e:
            self.warning('Failed to find a valid peak. {}'.format(e))
Beispiel #7
0
    def _calculate_peak_center(self, x, y):
        if self.use_interpolation:
            f = interpolate.interp1d(x, y)
            x = linspace(x[0], x[-1], 1000)
            y = f(x)

            self.graph.new_series(x, y, line_style='dash')

        if self.n_peaks > 1:
            def res(p, y, x):
                yfit = None
                n = p.shape[0] / 3
                for h, m, s in p.reshape(n, 3):
                    yi = h * norm.pdf(x, m, s)
                    if yfit is None:
                        yfit = yi
                    else:
                        yfit += yi
                err = y - yfit
                return err

            mm = x[y.argmax()]
            counter = range(self.n_peaks)
            p = [(1, mm, 1) for _ in counter]
            plsq = leastsq(res, p, args=(y, x))

            centers = plsq[0]
            for i in counter:
                c = centers[1 + 3 * i]
                self.graph.add_vertical_rule(c, color='blue')

            return c[1 + 3 * (self.select_peak - 1)]

        try:
            result = calculate_peak_center(x, y,
                                           min_peak_height=self.min_peak_height,
                                           percent=self.percent)
            return result
        except PeakCenterError, e:
            self.warning('Failed to find a valid peak. {}'.format(e))
Beispiel #8
0
    def _fine_scan_peak(self, cp):
        line, _ = self.graph.new_series(plotid=1)

        c = cp.dac
        w = self.fwindow / 2.0

        steps = self._calc_step_values(c - w, c + w, self.fstep_dac)
        self._scan_dac(steps)

        #get last scan
        xs = line.index.get_data()
        ys = line.value.get_data()

        center = calculate_peak_center(xs, ys)
        if not isinstance(center, str):
            [lx, cx, hx], [ly, cy, hy], mx, my = center
            self.graph.add_vertical_rule(cx, plotid=1)
            self.info('new peak center. {} nominal={} dx={}'.format(cp.isotope, cp.dac, cx))
            cp.dac += cx
            self._redraw()
        else:
            self.warning(center)