def __call__(self, data): if data.domain != self.domain: data = data.from_table(self.domain, data) xs, xsind, mon, X = _transform_to_sorted_features(data) x = xs[xsind] newd = np.zeros_like(data.X) for rowi, row in enumerate(X): # remove NaNs which ConvexHull can not handle source = np.column_stack((x, row)) source = source[~np.isnan(source).any(axis=1)] try: v = ConvexHull(source).vertices except QhullError: # FIXME notify user baseline = np.zeros_like(row) else: if self.peak_dir == RubberbandBaseline.PeakPositive: v = np.roll(v, -v.argmin()) v = v[:v.argmax() + 1] elif self.peak_dir == RubberbandBaseline.PeakNegative: v = np.roll(v, -v.argmax()) v = v[:v.argmin() + 1] # If there are NaN values at the edges of data then convex hull # does not include the endpoints. Because the same values are also # NaN in the current row, we can fill them with NaN (bounds_error # achieves this). baseline = interp1d(source[v, 0], source[v, 1], bounds_error=False)(x) finally: if self.sub == 0: newd[rowi] = row - baseline else: newd[rowi] = baseline return _transform_back_to_features(xsind, mon, newd)
def transformed(self, X, x): newd = np.zeros_like(X) for rowi, row in enumerate(X): # remove NaNs which ConvexHull can not handle source = np.column_stack((x, row)) source = source[~np.isnan(source).any(axis=1)] try: v = ConvexHull(source).vertices except (QhullError, ValueError): # FIXME notify user baseline = np.zeros_like(row) else: if self.peak_dir == RubberbandBaseline.PeakPositive: v = np.roll(v, -v.argmin()) v = v[:v.argmax() + 1] elif self.peak_dir == RubberbandBaseline.PeakNegative: v = np.roll(v, -v.argmax()) v = v[:v.argmin() + 1] # If there are NaN values at the edges of data then convex hull # does not include the endpoints. Because the same values are also # NaN in the current row, we can fill them with NaN (bounds_error # achieves this). baseline = interp1d(source[v, 0], source[v, 1], bounds_error=False)(x) finally: if self.sub == 0: newd[rowi] = row - baseline else: newd[rowi] = baseline return newd
def transformed(self, X, x): newd = np.zeros_like(X) for rowi, row in enumerate(X): # remove NaNs which ConvexHull can not handle source = np.column_stack((x, row)) source = source[~np.isnan(source).any(axis=1)] try: v = ConvexHull(source).vertices except QhullError: # FIXME notify user baseline = np.zeros_like(row) else: if self.peak_dir == RubberbandBaseline.PeakPositive: v = np.roll(v, -v.argmin()) v = v[:v.argmax() + 1] elif self.peak_dir == RubberbandBaseline.PeakNegative: v = np.roll(v, -v.argmax()) v = v[:v.argmin() + 1] # If there are NaN values at the edges of data then convex hull # does not include the endpoints. Because the same values are also # NaN in the current row, we can fill them with NaN (bounds_error # achieves this). baseline = interp1d(source[v, 0], source[v, 1], bounds_error=False)(x) finally: if self.sub == 0: newd[rowi] = row - baseline else: newd[rowi] = baseline return newd