예제 #1
0
def spectrum_baseline(y, x=[], display=0, algorithm='derpsalsa', wl_level=9):
    """
    ----------
    x, y : spectral data
    display : 0, 1 or 2, optional
        The default is 2.
        0: no display, 1: final, 2: verbose with plots
    algorithm : derpsalsa, psalsa, als, morph_pspline, Koch, wavelet
        The default is 'derpsalsa'.

    Returns
    baseline
    """
    if len(x) == 0:
        x = np.linspace(0, 1000, num=len(y))

    if display > 0:
        print('algorithm = ', algorithm, ' , starting')
    if algorithm == 'psalsa':
        baseline = psalsa_baseline(x, y, display)
    if algorithm == 'derpsalsa':
        baseline = derpsalsa_baseline(x, y, display)
    elif algorithm == 'als':
        baseline = baseline_als(x, y, display)
    elif algorithm == 'Koch':
        baseline = kolifier_morph_baseline(x, y, display)
    elif algorithm == 'morph_pspline':
        baseline = morph_pspline_baseline(x, y, display)
    elif algorithm == 'wavelet':
        from skued import baseline_dt, spectrum_colors
        max_iteration_number = 512
        baseline = baseline_dt(y,
                               level=wl_level,
                               max_iter=max_iteration_number,
                               wavelet='qshift3')
        if display >= 1:
            levels = list(range(wl_level - 2, wl_level + 3))
            colors = spectrum_colors(levels)
            for l, c in zip(levels, colors):
                if l == wl_level:
                    continue
                bltmp = baseline_dt(y,
                                    level=l,
                                    max_iter=max_iteration_number,
                                    wavelet='qshift3')
                plt.plot(x, bltmp, color=c)
            plt.plot(x, y, 'r', x, baseline, 'k--', linewidth=2)
            plot_annotation = 'wavelet bl; black-- at level ' + str(wl_level)
            plt.text(0.5,
                     0.92,
                     plot_annotation,
                     horizontalalignment='center',
                     verticalalignment='center',
                     transform=plt.gca().transAxes)
            plt.show()
    return baseline
예제 #2
0
 def test_on_ints(self):
     """ Test spectrum_colors on an int """
     colors = spectrum_colors(10)
     self.assertEqual(len(list(colors)), 10)
예제 #3
0
 def test_on_length_1_iterable(self):
     """ Test that spectrum_colors is working on single-length iterables """
     self.assertSequenceEqual(list(spectrum_colors(1)),
                              list(spectrum_colors([0])))
예제 #4
0
 def test_on_unsized_iterable(self):
     """ Test spectrum_colors on unsized_iterable (e.g. generator) """
     colors = spectrum_colors(range(0, 10))
     self.assertEqual(len(list(colors)), 10)
예제 #5
0
 def test_on_sized_iterable(self):
     """ Test on iterable that has a __len__ attribute: list, tuple, etc. """
     colors = spectrum_colors([1, 2, 3, 4, 5])
     self.assertEqual(len(list(colors)), 5)
예제 #6
0
def pens_and_brushes(num):
    qcolors = tuple(map(lambda c: QtGui.QColor.fromRgbF(*c), spectrum_colors(num)))
    pens = list(map(mkPen, qcolors))
    brushes = list(map(mkBrush, qcolors))
    return pens, brushes
예제 #7
0
def test_spectrum_colors_on_ints():
    """ Test spectrum_colors on an int """
    colors = spectrum_colors(10)
    assert len(list(colors)) == 10
예제 #8
0
def test_spectrum_colorson_length_1_iterable():
    """ Test that spectrum_colors is working on single-length iterables """
    assert list(spectrum_colors(1)) == list(spectrum_colors([0]))
예제 #9
0
def test_spectrum_colorson_unsized_iterable():
    """ Test spectrum_colors on unsized_iterable (e.g. generator) """
    colors = spectrum_colors(range(0, 10))
    assert len(list(colors)) == 10
예제 #10
0
def test_spectrum_colorson_sized_iterable():
    """ Test on iterable that has a __len__ attribute: list, tuple, etc. """
    colors = spectrum_colors([1, 2, 3, 4, 5])
    assert len(list(colors)) == 5