def test_peakat(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=Integrate.PeakAt, limits=[[0, 5]])(data)
     self.assertEqual(i[0][0], 1)
     np.testing.assert_equal(i.domain[0].compute_value.baseline(data)[1], 0)
     i = Integrate(methods=Integrate.PeakAt, limits=[[1.4, None]])(data)
     self.assertEqual(i[0][0], 2)
     i = Integrate(methods=Integrate.PeakAt, limits=[[1.6, None]])(data)
     self.assertEqual(i[0][0], 3)
Example #2
0
 def test_empty(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(method=Integrate.Simple, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], 0)
     i = Integrate(method=Integrate.Baseline, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], 0)
     i = Integrate(method=Integrate.PeakMax, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], np.nan)
     i = Integrate(method=Integrate.PeakBaseline, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], np.nan)
Example #3
0
 def test_names(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=[Integrate.Simple, Integrate.Baseline],
                   limits=[[0, 5], [0, 6]])(data)
     self.assertEqual(i.domain[0].name, "0 - 5")
     self.assertEqual(i.domain[1].name, "0 - 6")
     i = Integrate(methods=[Integrate.Simple, Integrate.Baseline],
                   limits=[[0, 5], [0, 6]], names=["simple", "baseline"])(data)
     self.assertEqual(i.domain[0].name, "simple")
     self.assertEqual(i.domain[1].name, "baseline")
Example #4
0
 def test_empty_interval(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=Integrate.Simple, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], 0)
     i = Integrate(methods=Integrate.Baseline, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], 0)
     i = Integrate(methods=Integrate.PeakMax, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], np.nan)
     i = Integrate(methods=Integrate.PeakBaseline, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], np.nan)
     i = Integrate(methods=Integrate.PeakAt, limits=[[10, 16]])(data)
     self.assertEqual(i[0][0], 1)  # get the rightmost one
Example #5
0
 def test_peakx(self):
     d1 = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     d2 = Orange.data.Table([[1, 2, 3, np.nan, 1, 1]])
     for data in d1, d2:
         i = Integrate(methods=Integrate.PeakX, limits=[[0, 5]])(data)
         self.assertEqual(i[0][0], 2)
         np.testing.assert_equal(i.domain[0].compute_value.baseline(data)[1], 0)
Example #6
0
 def test_different_integrals(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=[Integrate.Simple, Integrate.Baseline],
                   limits=[[0, 5], [0, 5]])(data)
     self.assertEqual(i[0][0], 8)
     np.testing.assert_equal(i.domain[0].compute_value.baseline(data)[1], 0)
     np.testing.assert_equal(i.domain[1].compute_value.baseline(data)[1], 1)
 def test_repeated(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=[Integrate.Simple, Integrate.Baseline],
                   limits=[[0, 5], [0, 6]],
                   names=["int", "int"])(data)
     self.assertEqual(i.domain[0].name, "int")
     self.assertEqual(i.domain[1].name, "int (2)")
Example #8
0
 def test_baseline(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1], [1, 2, 3, 1, np.nan, 1],
                               [1, 2, 3, 1, 1, np.nan]])
     i = Integrate(methods=Integrate.Baseline, limits=[[0, 5]])(data)
     self.assertEqual(i[0][0], 3)
     self.assertEqual(i[1][0], 3)
     self.assertEqual(i[2][0], 3)
     np.testing.assert_equal(i.domain[0].compute_value.baseline(data)[1], 1)
Example #9
0
 def test_repeated(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=[Integrate.Simple, Integrate.Baseline],
                   limits=[[0, 5], [0, 6]], names=["int", "int"])(data)
     self.assertEqual(i.domain[0].name, "int")
     # after Orange 3.6.0 get_next_name returned different results
     nn = get_next_name(["int"], "int")
     self.assertEqual(i.domain[1].name, nn)
Example #10
0
 def test_metas_output(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=[Integrate.Simple, Integrate.Baseline],
                   limits=[[0, 5], [0, 6]], metas=True)(data)
     metavars = [a.name for a in i.domain.metas]
     self.assertTrue("0 - 5" in metavars and "0 - 6" in metavars)
     self.assertEqual(i[0]["0 - 5"], 8)
     self.assertEqual(i[0]["0 - 6"], 3)
Example #11
0
 def test_area_norm(self):
     data = Orange.data.Table([[2, 1, 2, 2, 3]])
     p = Normalize(method=Normalize.Area, int_method=Integrate.PeakMax, lower=0, upper=4)(data)
     np.testing.assert_equal(p.X, data.X / 3)
     p = Normalize(method=Normalize.Area, int_method=Integrate.Simple, lower=0, upper=4)(data)
     np.testing.assert_equal(p.X, data.X / 7.5)
     p = Normalize(method=Normalize.Area, int_method=Integrate.Simple, lower=0, upper=2)(data)
     q = Integrate(methods=Integrate.Simple, limits=[[0, 2]])(p)
     np.testing.assert_equal(q.X, np.ones_like(q.X))
Example #12
0
    def show_data(self):
        self.img.clear()
        if self.data:
            xat = self.data.domain[self.attr_x]
            yat = self.data.domain[self.attr_y]

            ndom = Orange.data.Domain([xat, yat])
            datam = Orange.data.Table(ndom, self.data)
            coorx = datam.X[:, 0]
            coory = datam.X[:, 1]
            lsx = values_to_linspace(coorx)
            lsy = values_to_linspace(coory)

            l1, l2 = self.parent.lowlim, self.parent.highlim

            gx = getx(self.data)

            if l1 is None:
                l1 = min(gx) - 1
            if l2 is None:
                l2 = max(gx) + 1

            l1, l2 = min(l1, l2), max(l1, l2)

            imethod = self.parent.integration_methods[
                self.parent.integration_method]
            datai = Integrate(method=imethod, limits=[[l1, l2]])(self.data)

            di = {}
            if self.parent.curveplot.selected_indices:
                ind = list(self.parent.curveplot.selected_indices)[0]
                di = datai.domain.attributes[0].compute_value.draw_info(
                    self.data[ind:ind + 1])
            self.refresh_markings(di)

            d = datai.X[:, 0]

            # set data
            imdata = np.ones((lsy[2], lsx[2])) * float("nan")
            xindex = index_values(coorx, lsx)
            yindex = index_values(coory, lsy)
            imdata[yindex, xindex] = d

            levels = get_levels(imdata)
            self.update_color_schema()

            self.img.setImage(imdata, levels=levels)

            # shift centres of the pixels so that the axes are useful
            shiftx = (lsx[1] - lsx[0]) / (2 * (lsx[2] - 1))
            shifty = (lsy[1] - lsy[0]) / (2 * (lsy[2] - 1))
            left = lsx[0] - shiftx
            bottom = lsy[0] - shifty
            width = (lsx[1] - lsx[0]) + 2 * shiftx
            height = (lsy[1] - lsy[0]) + 2 * shifty
            self.img.setRect(QRectF(left, bottom, width, height))
Example #13
0
import Orange
from orangecontrib.infrared.preprocess import Absorbance, Transmittance, \
    Integrate, Interpolate, Cut, SavitzkyGolayFiltering, \
    GaussianSmoothing, PCADenoising, RubberbandBaseline, \
    Normalize

# Preprocessors that work per sample and should return the same
# result for a sample independent of the other samples
PREPROCESSORS_INDEPENDENT_SAMPLES = [
    Interpolate(np.linspace(1000, 1800, 100)),
    SavitzkyGolayFiltering(window=9, polyorder=2, deriv=2),
    Cut(lowlim=1000, highlim=1800),
    GaussianSmoothing(sd=3.),
    Absorbance(),
    Transmittance(),
    Integrate(limits=[[900, 100], [1100, 1200], [1200, 1300]]),
    RubberbandBaseline(),
    Normalize(method=Normalize.Vector),
]

# Preprocessors that use groups of input samples to infer
# internal parameters.
PREPROCESSORS_GROUPS_OF_SAMPLES = [
    PCADenoising(components=2),
]

PREPROCESSORS = PREPROCESSORS_INDEPENDENT_SAMPLES + PREPROCESSORS_GROUPS_OF_SAMPLES


class TestTransmittance(unittest.TestCase):
    def test_domain_conversion(self):
Example #14
0
 def test_simple(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(method=Integrate.Simple, limits=[[0, 5]])(data)
     self.assertEqual(i[0][0], 8)
     np.testing.assert_equal(i.domain[0].compute_value.baseline(data)[1],
                             [[0, 0, 0, 0, 0, 0]])
Example #15
0
 def test_peakxbaseline(self):
     data = Orange.data.Table([[1, 2, 3, 1, 1, 1]])
     i = Integrate(methods=Integrate.PeakXBaseline, limits=[[0, 5]])(data)
     self.assertEqual(i[0][0], 2)
     np.testing.assert_equal(i.domain[0].compute_value.baseline(data)[1],
                             [[1, 1, 1, 1, 1, 1]])
Example #16
0
 def createinstance(cls, params):
     params = dict(params)
     values = []
     for ind, (name, _) in enumerate(cls.integrator.parameters()):
         values.append(params.get(name, 0.))
     return Integrate(methods=cls.integrator, limits=[values], metas=True)
Example #17
0
    def update_view(self):
        self.img.clear()
        self.img.setSelection(None)
        self.lsx = None
        self.lsy = None
        self.data_points = None
        self.data_values = None
        self.data_imagepixels = None
        if self.data and self.attr_x and self.attr_y:
            xat = self.data.domain[self.attr_x]
            yat = self.data.domain[self.attr_y]

            ndom = Orange.data.Domain([xat, yat])
            datam = Orange.data.Table(ndom, self.data)
            coorx = datam.X[:, 0]
            coory = datam.X[:, 1]
            self.data_points = datam.X
            self.lsx = lsx = values_to_linspace(coorx)
            self.lsy = lsy = values_to_linspace(coory)
            if lsx[-1] * lsy[-1] > IMAGE_TOO_BIG:
                self.parent.Error.image_too_big(lsx[-1], lsy[-1])
                return
            else:
                self.parent.Error.image_too_big.clear()

            di = {}
            if self.parent.value_type == 0:  # integrals
                imethod = self.parent.integration_methods[self.parent.integration_method]

                l1, l2, l3 = self.parent.lowlim, self.parent.highlim, self.parent.choose

                gx = getx(self.data)

                if l1 is None:
                    l1 = min(gx) - 1
                if l2 is None:
                    l2 = max(gx) + 1

                l1, l2 = min(l1, l2), max(l1, l2)

                if l3 is None:
                    l3 = (l1 + l2)/2

                if imethod != Integrate.PeakAt:
                    datai = Integrate(methods=imethod, limits=[[l1, l2]])(self.data)
                else:
                    datai = Integrate(methods=imethod, limits=[[l3, l3]])(self.data)

                if self.parent.curveplot.selected_indices:
                    # curveplot can have a subset of curves on the input> match IDs
                    ind = list(self.parent.curveplot.selected_indices)[0]
                    dind = self.data_ids[self.parent.curveplot.data[ind].id]
                    di = datai.domain.attributes[0].compute_value.draw_info(self.data[dind:dind+1])
                d = datai.X[:, 0]
            else:
                dat = self.data.domain[self.parent.attr_value]
                ndom = Orange.data.Domain([dat])
                d = Orange.data.Table(ndom, self.data).X[:, 0]
            self.refresh_markings(di)

            # set data
            imdata = np.ones((lsy[2], lsx[2])) * float("nan")

            # if previous or saved selection is valid for this data set keep it
            if self.selection is None or len(self.selection) != len(self.data):
                self.selection = np.zeros(len(self.data), dtype="bool")

            xindex = index_values(coorx, lsx)
            yindex = index_values(coory, lsy)
            imdata[yindex, xindex] = d
            self.data_values = d
            self.data_imagepixels = np.vstack((yindex, xindex)).T

            levels = get_levels(imdata)
            self.update_color_schema()

            self.img.setImage(imdata, levels=levels)

            # shift centres of the pixels so that the axes are useful
            shiftx = _shift(lsx)
            shifty = _shift(lsy)
            left = lsx[0] - shiftx
            bottom = lsy[0] - shifty
            width = (lsx[1]-lsx[0]) + 2*shiftx
            height = (lsy[1]-lsy[0]) + 2*shifty
            self.img.setRect(QRectF(left, bottom, width, height))

            self.send_selection()
            self.refresh_img_selection()
Example #18
0
from orangecontrib.infrared.preprocess import Absorbance, Transmittance, \
    Integrate, Interpolate, Cut, SavitzkyGolayFiltering, \
    GaussianSmoothing, PCADenoising, RubberbandBaseline, \
    Normalize


# Preprocessors that work per sample and should return the same
# result for a sample independent of the other samples
PREPROCESSORS_INDEPENDENT_SAMPLES = [
    Interpolate(np.linspace(1000, 1700, 100)),
    SavitzkyGolayFiltering(window=9, polyorder=2, deriv=2),
    Cut(lowlim=1000, highlim=1800),
    GaussianSmoothing(sd=3.),
    Absorbance(),
    Transmittance(),
    Integrate(limits=[[900, 100], [1100, 1200], [1200, 1300]]),
    Integrate(methods=Integrate.Simple, limits=[[1100, 1200]]),
    Integrate(methods=Integrate.Baseline, limits=[[1100, 1200]]),
    Integrate(methods=Integrate.PeakMax, limits=[[1100, 1200]]),
    Integrate(methods=Integrate.PeakBaseline, limits=[[1100, 1200]]),
    Integrate(methods=Integrate.PeakAt, limits=[[1100]]),
    Integrate(methods=Integrate.PeakX, limits=[[1100, 1200]]),
    Integrate(methods=Integrate.PeakXBaseline, limits=[[1100, 1200]]),
    RubberbandBaseline(),
    Normalize(method=Normalize.Vector),
    Normalize(method=Normalize.Area, int_method=Integrate.PeakMax, lower=0, upper=10000),
]

# Preprocessors that use groups of input samples to infer
# internal parameters.
PREPROCESSORS_GROUPS_OF_SAMPLES = [