def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) layout = QFormLayout() self.setLayout(layout) minf, maxf = -sys.float_info.max, sys.float_info.max self.__values = {} self.__editors = {} self.__lines = {} for name, longname in self.integrator.parameters(): v = 0. self.__values[name] = v e = SetXDoubleSpinBox(decimals=4, minimum=minf, maximum=maxf, singleStep=0.5, value=v) e.focusIn = self.activateOptions e.editingFinished.connect(self.edited) def cf(x, name=name): return self.set_value(name, x) e.valueChanged[float].connect(cf) self.__editors[name] = e layout.addRow(name, e) l = MovableVlineWD(position=v, label=name, setvalfn=cf, confirmfn=self.edited) self.__lines[name] = l self.focusIn = self.activateOptions self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) self.user_changed = False
def __init__(self): super().__init__() dbox = gui.widgetBox(self.controlArea, "Image values") rbox = gui.radioButtons( dbox, self, "value_type", callback=self._change_integration) gui.appendRadioButton(rbox, "From spectra") self.box_values_spectra = gui.indentedBox(rbox) gui.comboBox( self.box_values_spectra, self, "integration_method", valueType=int, items=(a.name for a in self.integration_methods), callback=self._change_integral_type) gui.rubber(self.controlArea) gui.appendRadioButton(rbox, "Use feature") self.box_values_feature = gui.indentedBox(rbox) self.feature_value_model = DomainModel(DomainModel.METAS | DomainModel.CLASSES, valid_types=DomainModel.PRIMITIVE) self.feature_value = gui.comboBox( self.box_values_feature, self, "attr_value", callback=self.update_feature_value, model=self.feature_value_model, sendSelectedValue=True, valueType=str) splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) self.imageplot = ImagePlot(self, select_fn=self.image_selection_changed) self.curveplot = CurvePlotHyper(self, select=SELECTONE) self.curveplot.plot.vb.x_padding = 0.005 # pad view so that lines are not hidden splitter.addWidget(self.imageplot) splitter.addWidget(self.curveplot) self.mainArea.layout().addWidget(splitter) self.line1 = MovableVlineWD(position=self.lowlim, label="", setvalfn=self.set_lowlim, confirmfn=self.changed_integral_range, report=self.curveplot) self.line2 = MovableVlineWD(position=self.highlim, label="", setvalfn=self.set_highlim, confirmfn=self.changed_integral_range, report=self.curveplot) self.line3 = MovableVlineWD(position=self.choose, label="", setvalfn=self.set_choose, confirmfn=self.changed_integral_range, report=self.curveplot) self.curveplot.add_marking(self.line1) self.curveplot.add_marking(self.line2) self.curveplot.add_marking(self.line3) self.line1.hide() self.line2.hide() self.line3.hide() self.data = None self.disable_integral_range = False self.resize(900, 700) self.graph_name = "imageplot.plotview" self._update_integration_type() # prepare interface according to the new context self.contextAboutToBeOpened.connect(lambda x: self.init_interface_data(x[0]))
def __init__(self): super().__init__() dbox = gui.widgetBox(self.controlArea, "Integration") rbox = gui.radioButtons(dbox, self, "integration_method", callback=self._change_integration) gui.appendRadioButton(rbox, "Integrate from 0") gui.appendRadioButton(rbox, "Integrate from baseline") gui.appendRadioButton(rbox, "Peak from 0") gui.appendRadioButton(rbox, "Peak from baseline") gui.rubber(self.controlArea) splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) self.imageplot = ImagePlot(self) self.curveplot = CurvePlot(self, select=SELECTONE) splitter.addWidget(self.imageplot) splitter.addWidget(self.curveplot) self.mainArea.layout().addWidget(splitter) self.line1 = MovableVlineWD(position=self.lowlim, label="", setvalfn=self.set_lowlim, confirmfn=self.edited, report=self.curveplot) self.line2 = MovableVlineWD(position=self.highlim, label="", setvalfn=self.set_highlim, confirmfn=self.edited, report=self.curveplot) self.curveplot.add_marking(self.line1) self.curveplot.add_marking(self.line2) self.resize(900, 700) self.graph_name = "imageplot.plotview"
class OWHyper(OWWidget): name = "Hyperspectra" inputs = [("Data", Orange.data.Table, 'set_data', Default)] outputs = [("Selection", Orange.data.Table), ("Data", Orange.data.Table)] icon = "icons/hyper.svg" settings_version = 2 settingsHandler = DomainContextHandler(metas_in_res=True) imageplot = SettingProvider(ImagePlot) curveplot = SettingProvider(CurvePlotHyper) integration_method = Setting(0) integration_methods = [Integrate.Simple, Integrate.Baseline, Integrate.PeakMax, Integrate.PeakBaseline, Integrate.PeakAt] value_type = Setting(0) attr_value = ContextSetting(None) lowlim = Setting(None) highlim = Setting(None) choose = Setting(None) class Warning(OWWidget.Warning): threshold_error = Msg("Low slider should be less than High") class Error(OWWidget.Warning): image_too_big = Msg("Image for chosen features is too big ({} x {}).") @classmethod def migrate_settings(cls, settings_, version): if version < 2: # delete the saved attr_value to prevent crashes try: del settings_["context_settings"][0].values["attr_value"] except: pass def __init__(self): super().__init__() dbox = gui.widgetBox(self.controlArea, "Image values") rbox = gui.radioButtons( dbox, self, "value_type", callback=self._change_integration) gui.appendRadioButton(rbox, "From spectra") self.box_values_spectra = gui.indentedBox(rbox) gui.comboBox( self.box_values_spectra, self, "integration_method", valueType=int, items=(a.name for a in self.integration_methods), callback=self._change_integral_type) gui.rubber(self.controlArea) gui.appendRadioButton(rbox, "Use feature") self.box_values_feature = gui.indentedBox(rbox) self.feature_value_model = DomainModel(DomainModel.METAS | DomainModel.CLASSES, valid_types=DomainModel.PRIMITIVE) self.feature_value = gui.comboBox( self.box_values_feature, self, "attr_value", callback=self.update_feature_value, model=self.feature_value_model, sendSelectedValue=True, valueType=str) splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) self.imageplot = ImagePlot(self, self.image_selection_changed) self.curveplot = CurvePlotHyper(self, select=SELECTONE) self.curveplot.plot.vb.x_padding = 0.005 # pad view so that lines are not hidden splitter.addWidget(self.imageplot) splitter.addWidget(self.curveplot) self.mainArea.layout().addWidget(splitter) self.line1 = MovableVlineWD(position=self.lowlim, label="", setvalfn=self.set_lowlim, confirmfn=self.edited, report=self.curveplot) self.line2 = MovableVlineWD(position=self.highlim, label="", setvalfn=self.set_highlim, confirmfn=self.edited, report=self.curveplot) self.line3 = MovableVlineWD(position=self.choose, label="", setvalfn=self.set_choose, confirmfn=self.edited, report=self.curveplot) self.curveplot.add_marking(self.line1) self.curveplot.add_marking(self.line2) self.curveplot.add_marking(self.line3) self.line1.hide() self.line2.hide() self.line3.hide() self.data = None self.resize(900, 700) self.graph_name = "imageplot.plotview" self._update_integration_type() def image_selection_changed(self, indices): annotated = create_annotated_table(self.data, indices) self.send("Data", annotated) if self.data: selected = self.data[indices] self.send("Selection", selected if selected else None) if selected: self.curveplot.set_data(selected) else: self.curveplot.set_data(self.data) else: self.send("Selection", None) self.curveplot.set_data(None) self.curveplot.update_view() def selection_changed(self): self.redraw_data() def init_attr_values(self): domain = self.data.domain if self.data is not None else None self.feature_value_model.set_domain(domain) self.attr_value = self.feature_value_model[0] if self.feature_value_model else None def set_lowlim(self, v): self.lowlim = v def set_highlim(self, v): self.highlim = v def set_choose(self, v): self.choose = v def redraw_data(self): self.imageplot.set_integral_limits() def update_feature_value(self): self.redraw_data() def _update_integration_type(self): self.line1.hide() self.line2.hide() self.line3.hide() if self.value_type == 0: self.box_values_spectra.setDisabled(False) self.box_values_feature.setDisabled(True) if self.integration_methods[self.integration_method] != Integrate.PeakAt: self.line1.show() self.line2.show() else: self.line3.show() elif self.value_type == 1: self.box_values_spectra.setDisabled(True) self.box_values_feature.setDisabled(False) QTest.qWait(1) # first update the interface def _change_integration(self): # change what to show on the image self._update_integration_type() self.redraw_data() def edited(self): self.redraw_data() def _change_integral_type(self): self._change_integration() def set_data(self, data): self.closeContext() self.curveplot.set_data(data) if data is not None: same_domain = (self.data and data.domain.checksum() == self.data.domain.checksum()) self.data = data if not same_domain: self.init_attr_values() else: self.data = None if self.curveplot.data_x is not None and len(self.curveplot.data_x): minx = self.curveplot.data_x[0] maxx = self.curveplot.data_x[-1] if self.lowlim is None or not minx <= self.lowlim <= maxx: self.lowlim = minx self.line1.setValue(self.lowlim) if self.highlim is None or not minx <= self.highlim <= maxx: self.highlim = maxx self.line2.setValue(self.highlim) if self.choose is None: self.choose = (minx + maxx)/2 elif self.choose < minx: self.choose = minx elif self.choose > maxx: self.choose = maxx self.line3.setValue(self.choose) self.imageplot.set_data(data) self.openContext(data) self.curveplot.update_view() self.imageplot.update_view() # store selection as a list due to a bug in checking if numpy settings changed def storeSpecificSettings(self): selection = self.imageplot.selection if selection is not None: selection = list(selection) self.current_context.selection = selection def retrieveSpecificSettings(self): selection = getattr(self.current_context, "selection", None) if selection is not None: selection = np.array(selection, dtype="bool") self.imageplot.selection = selection
class OWHyper(OWWidget): name = "Hyperspectra" inputs = [("Data", Orange.data.Table, 'set_data', Default), ("Data subset", Orange.data.Table, 'set_subset', Default)] outputs = [("Selection", Orange.data.Table)] icon = "icons/unknown.svg" settingsHandler = DomainContextHandler() imageplot = SettingProvider(ImagePlot) curveplot = SettingProvider(CurvePlot) integration_method = Setting(0) integration_methods = [ Integrate.Simple, Integrate.Baseline, Integrate.PeakMax, Integrate.PeakBaseline ] lowlim = Setting(None) highlim = Setting(None) class Warning(OWWidget.Warning): threshold_error = Msg("Low slider should be less than High") def __init__(self): super().__init__() dbox = gui.widgetBox(self.controlArea, "Integration") rbox = gui.radioButtons(dbox, self, "integration_method", callback=self._change_integration) gui.appendRadioButton(rbox, "Integrate from 0") gui.appendRadioButton(rbox, "Integrate from baseline") gui.appendRadioButton(rbox, "Peak from 0") gui.appendRadioButton(rbox, "Peak from baseline") gui.rubber(self.controlArea) splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) self.imageplot = ImagePlot(self) self.curveplot = CurvePlot(self, select=SELECTONE) splitter.addWidget(self.imageplot) splitter.addWidget(self.curveplot) self.mainArea.layout().addWidget(splitter) self.line1 = MovableVlineWD(position=self.lowlim, label="", setvalfn=self.set_lowlim, confirmfn=self.edited, report=self.curveplot) self.line2 = MovableVlineWD(position=self.highlim, label="", setvalfn=self.set_highlim, confirmfn=self.edited, report=self.curveplot) self.curveplot.add_marking(self.line1) self.curveplot.add_marking(self.line2) self.resize(900, 700) self.graph_name = "imageplot.plotview" def edited(self): self.imageplot.set_integral_limits() def set_lowlim(self, v): self.lowlim = v def set_highlim(self, v): self.highlim = v def selection_changed(self): self.imageplot.set_integral_limits() def _change_integration(self): self.imageplot.set_integral_limits() def set_data(self, data): self.closeContext() self.curveplot.set_data(data) if self.curveplot.data_x is not None: minx = self.curveplot.data_x[0] maxx = self.curveplot.data_x[-1] if self.lowlim is None or not minx <= self.lowlim <= maxx: self.lowlim = min(self.curveplot.data_x) self.line1.setValue(self.lowlim) if self.highlim is None or not minx <= self.highlim <= maxx: self.highlim = max(self.curveplot.data_x) self.line2.setValue(self.highlim) self.imageplot.set_data(data) self.openContext(data) def set_subset(self, data): pass