Esempio n. 1
0
 def read(self):
     tbl = np.loadtxt(self.filename, ndmin=2)
     domvals = tbl.T[0]  # first column is attribute name
     from orangecontrib.infrared.preprocess import features_with_interpolation
     domain = Orange.data.Domain(features_with_interpolation(domvals), None)
     datavals = tbl.T[1:]
     return Orange.data.Table(domain, datavals)
Esempio n. 2
0
    def test_autointerpolate(self):
        d1 = Orange.data.Table("peach_juice.dpt")
        d2 = Orange.data.Table("collagen.csv")
        d3 = Orange.data.Table(d1.domain, d2)
        d1x = getx(d1)
        d2x = getx(d2)

        #have the correct number of non-nan elements
        validx = np.where(d1x >= min(d2x), d1x, np.nan)
        validx = np.where(d1x <= max(d2x), validx, np.nan)
        self.assertEqual(np.sum(~np.isnan(validx)),
                         np.sum(~np.isnan(d3.X[0])))

        #check roundtrip
        atts = features_with_interpolation(d2x)
        ndom = Orange.data.Domain(atts, None)
        dround = Orange.data.Table(ndom, d3)
        #edges are unknown, the rest roughly the same
        np.testing.assert_allclose(dround.X[:, 1:-1], d2.X[:, 1:-1], rtol=0.011)
Esempio n. 3
0
 def read(self):
     with open(self.filename, "rb") as f:
         # read first row separately because of two empty columns
         header = f.readline().decode("ascii").rstrip().split("\t")
         header = [a.strip() for a in header]
         assert header[0] == header[1] == ""
         dom_vals = [float(v) for v in header[2:]]
         from orangecontrib.infrared.preprocess import features_with_interpolation
         domain = Orange.data.Domain(features_with_interpolation(dom_vals),
                                     None)
         tbl = np.loadtxt(f, ndmin=2)
         data = Orange.data.Table(domain, tbl[:, 2:])
         metas = [
             ContinuousVariable.make('map_x'),
             ContinuousVariable.make('map_y')
         ]
         domain = Orange.data.Domain(domain.attributes, None, metas=metas)
         data = data.transform(domain)
         data[:, metas[0]] = tbl[:, 0].reshape(-1, 1)
         data[:, metas[1]] = tbl[:, 1].reshape(-1, 1)
         return data