def test_cut_both(self): d = self.collagen dcut = Cut(lowlim=0, highlim=2)(d) self.assertFalse(getx(dcut)) dcut = Cut(lowlim=1000, highlim=1100)(d) self.assertGreaterEqual(min(getx(dcut)), 1000) self.assertLessEqual(max(getx(dcut)), 1100)
def test_cut_single_inverse(self): d = self.collagen dcut = Cut(lowlim=1000, inverse=True)(d) self.assertLessEqual(max(getx(dcut)), 1000) self.assertEqual(min(getx(dcut)), min(getx(d))) dcut = Cut(highlim=1000, inverse=True)(d) self.assertGreaterEqual(min(getx(dcut)), 1000) self.assertEqual(max(getx(dcut)), max(getx(d)))
def test_cut_both_inverse(self): d = self.collagen # cutting out of x interval - need all dcut = Cut(lowlim=0, highlim=2, inverse=True)(d) np.testing.assert_equal(getx(dcut), getx(d)) # cutting in the middle - edged are the same dcut = Cut(lowlim=1000, highlim=1100, inverse=True)(d) dcutx = getx(dcut) self.assertEqual(min(dcutx), min(getx(d))) self.assertEqual(max(dcutx), max(getx(d))) self.assertLess(len(dcutx), len(getx(d))) np.testing.assert_equal(np.where(dcutx < 1100), np.where(dcutx < 1000)) np.testing.assert_equal(np.where(dcutx > 1100), np.where(dcutx > 1000))
def test_predict_different_domain_interpolation(self): train, test = separate_learn_test(self.collagen) aucorig = AUC(TestOnTestData()(train, test, [LogisticRegressionLearner()])) test = Interpolate(points=getx(test) - 1.)(test) # other test domain train = Interpolate(points=getx(train))(train) # make train capable of interpolation aucshift = AUC(TestOnTestData()(train, test, [LogisticRegressionLearner()])) self.assertAlmostEqual(aucorig, aucshift, delta=0.01) # shift can decrease AUC slightly test = Cut(1000, 1700)(test) auccut1 = AUC(TestOnTestData()(train, test, [LogisticRegressionLearner()])) test = Cut(1100, 1600)(test) auccut2 = AUC(TestOnTestData()(train, test, [LogisticRegressionLearner()])) test = Cut(1200, 1500)(test) auccut3 = AUC(TestOnTestData()(train, test, [LogisticRegressionLearner()])) # the more we cut the lower precision we get self.assertTrue(aucorig > auccut1 > auccut2 > auccut3)
orig_data.domain.metas + data.domain.attributes, ) data_anno = orig_data.transform(dom_anno) data_anno.metas[:, len(orig_data.domain.metas):] = data.X progress_interrupt(100) return data, data_fits, data_resid, data_anno def on_done(self, results): fit_params, fits, residuals, annotated_data = results self.Outputs.fit_params.send(fit_params) self.Outputs.fits.send(fits) self.Outputs.residuals.send(residuals) self.Outputs.annotated_data.send(annotated_data) def on_exception(self, ex): try: super().on_exception(ex) except ValueError: self.Error.applying(ex) self.Outputs.fit_params.send(None) self.Outputs.fits.send(None) self.Outputs.residuals.send(None) self.Outputs.annotated_data.send(None) if __name__ == "__main__": # pragma: no cover data = Cut(lowlim=1360, highlim=1700)(Table("collagen")[0:3]) WidgetPreview(OWPeakFit).run(data)
""" Rerturn appropriate test file for a preprocessor. Very slow preprocessors should get smaller files. """ if isinstance(preproc, ME_EMSC): return SMALLER_COLLAGEN return SMALL_COLLAGEN # 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(), LinearBaseline(), Normalize(method=Normalize.Vector), Normalize(method=Normalize.Area,
import numpy as np from Orange.widgets.data.utils.preprocess import DescriptionRole from Orange.widgets.tests.base import WidgetTest from orangewidget.tests.base import GuiTest from orangecontrib.spectroscopy.data import getx from orangecontrib.spectroscopy.preprocess import Cut, LinearBaseline from orangecontrib.spectroscopy.tests.spectral_preprocess import wait_for_preview from orangecontrib.spectroscopy.widgets.gui import MovableVline from orangecontrib.spectroscopy.widgets.owpeakfit import OWPeakFit, fit_peaks, PREPROCESSORS, \ create_model, prepare_params, unique_prefix, create_composite_model, pack_model_editor from orangecontrib.spectroscopy.widgets.peak_editors import ParamHintBox, VoigtModelEditor, \ PseudoVoigtModelEditor, ExponentialGaussianModelEditor, PolynomialModelEditor COLLAGEN = Orange.data.Table("collagen")[0:3] COLLAGEN_2 = LinearBaseline()(Cut(lowlim=1500, highlim=1700)(COLLAGEN)) COLLAGEN_1 = LinearBaseline()(Cut(lowlim=1600, highlim=1700)(COLLAGEN_2)) class TestOWPeakFit(WidgetTest): def setUp(self): self.widget = self.create_widget(OWPeakFit) self.data = COLLAGEN_1 def test_load_unload(self): self.send_signal("Data", Orange.data.Table("iris.tab")) self.send_signal("Data", None) def test_allint_indv(self): for p in PREPROCESSORS: with self.subTest(msg=f"Testing model {p.name}"):
self.info_preproc.setText( self._format_preproc_str( self.preprocessor).lstrip("\n")) else: # only allow readers with tile-by-tile support to run. reader = None return reader elif self.source == self.URL: url = self.url_combo.currentText().strip() if url: return UrlReader(url) if __name__ == "__main__": import sys from orangecontrib.spectroscopy.preprocess import Cut, LinearBaseline from Orange.preprocess.preprocess import PreprocessorList import orangecontrib.protospec #load readers a = QApplication(sys.argv) # preproc = PreprocessorList([Cut(lowlim=2000, highlim=2006), LinearBaseline()]) preproc = PreprocessorList( [LinearBaseline(), Cut(lowlim=2000, highlim=2006)]) # preproc = PreprocessorList([Cut(lowlim=2000, highlim=2006), Cut(lowlim=2002, highlim=2006)]) # Test 2nd Deriv superwide # from orangecontrib.spectroscopy.preprocess import Normalize, Integrate, integrate, SavitzkyGolayFiltering # preproc = PreprocessorList([Normalize(lower=1591.0484214631633, upper=1719.720747038586, int_method=integrate.IntegrateFeatureSimple), SavitzkyGolayFiltering(window=13, deriv=2), Integrate(methods=integrate.IntegrateFeatureAtPeak, limits=[[1625.0, 1.0], [1152.0, 1.0], [1575.0, 1.0], [1127.0, 1.0]])]) ow = OWTilefile() ow.update_preprocessor(preproc) ow.show() a.exec_() ow.saveSettings()