Ejemplo n.º 1
0
    def _apply_window_sequence(self,
                               silent=False,
                               fastmath=True,
                               usenifft=False,
                               errors="ignore"):
        winlen = len(self.window_seq)
        self.errorcounter = 0
        if not fastmath:
            # here we setup the shape for the Z array because
            # it is much faster than using np.append in every iteration
            _x, _y, _, _ = self._safe_cast()
            _obj = FFTMethod(_x, _y)
            _obj.ifft(usenifft=usenifft)
            x, y = find_roi(_obj.x, _obj.y)
            self.Y_cont = np.array(x)
            yshape = y.size
            xshape = len(self.window_seq)
            self.Z_cont = np.empty(shape=(yshape, xshape))

        for idx, (_center, _window) in enumerate(self.window_seq.items()):
            _x, _y, _, _ = self._safe_cast()
            _obj = FFTMethod(_x, _y)
            _obj.y *= _window.y
            _obj.ifft(usenifft=usenifft)
            x, y = find_roi(_obj.x, _obj.y)
            if not fastmath:
                self.Z_cont[:, idx] = y
            try:
                centx, _ = find_center(x, y)
                self.found_centers[_center] = centx
            except ValueError as err:
                self.errorcounter += 1
                if errors == "ignore":
                    self.found_centers[_center] = None
                else:
                    raise err
            if not silent:  # This creates about 5-15% overhead..
                sys.stdout.write('\r')
                j = (idx + 1) / winlen
                sys.stdout.write(
                    "Progress : [%-30s] %d%% (Errors: %d)" %
                    ('=' * int(30 * j), 100 * j, self.errorcounter))
                sys.stdout.flush()
Ejemplo n.º 2
0
    def test_find_center3(self):
        g = Generator(1, 4, 3, 7000)
        g.generate_freq()

        a = FFTMethod(*g.data)
        a.ifft()

        x, y = find_roi(a.x, a.y)

        x_peak, _ = find_center(x, y, n_largest=4)

        assert 6950 < x_peak < 7050
Ejemplo n.º 3
0
    def test_fwhm_detection(self):
        g = Generator(1, 4, 3, 1000)
        g.generate_freq()

        a = FFTMethod(*g.data)
        a.ifft()

        x, y = find_roi(a.x, a.y)

        cent, win_size, order = predict_fwhm(x,
                                             y,
                                             1000,
                                             10,
                                             prefer_high_order=True,
                                             tol=1e-3)
        assert cent > 1000
        assert win_size > 2000
Ejemplo n.º 4
0
 def _prepare_element(self,
                      idx,
                      window,
                      fastmath=True,
                      usenifft=False,
                      errors="ignore"):
     _x, _y, _, _ = self._safe_cast()
     _obj = FFTMethod(_x, _y)
     _obj.y *= window.y
     _obj.ifft(usenifft=usenifft)
     x, y = find_roi(_obj.x, _obj.y)
     if not fastmath:
         self.Z_cont[:, idx] = y
     try:
         centx, _ = find_center(x, y)
         return centx
     except ValueError as err:
         if errors == "ignore":
             return None
         else:
             raise err
Ejemplo n.º 5
0
    def _apply_window_seq_parallel(self,
                                   fastmath=True,
                                   usenifft=False,
                                   errors="ignore"):
        self.errorcounter = 0
        if not fastmath:
            # here we setup the shape for the Z array and allocate Y, because
            # it is much faster than using np.append in every iteration
            _x, _y, _, _ = self._safe_cast()
            _obj = FFTMethod(_x, _y)
            _obj.ifft(usenifft=usenifft)
            x, y = find_roi(_obj.x, _obj.y)
            yshape = y.size
            self.Y_cont = np.array(x)
            xshape = len(self.window_seq)
            self.Z_cont = np.empty(shape=(yshape, xshape))

        for idx, (_center, _window) in enumerate(self.window_seq.items()):
            element = self._prepare_element(idx, _window, fastmath, usenifft,
                                            errors)
            if element is None:
                self.errorcounter += 1  # This might be useless, since we lazy evaluate things..
            self.found_centers[_center] = element
Ejemplo n.º 6
0
 def test_find_roi(self):
     x, y = find_roi(np.linspace(-10, 10, 10000),
                     np.linspace(-10, 10, 10000))
     np.testing.assert_almost_equal(min(x), 0, decimal=2)
     np.testing.assert_almost_equal(min(y), 0, decimal=2)