예제 #1
0
 def __get_annotationparam(self, title, subtitle):
     param = AnnotationParam(_("Annotation"), icon="annotation.png")
     if title is not None:
         param.title = title
     if subtitle is not None:
         param.subtitle = subtitle
     return param
예제 #2
0
파일: builder.py 프로젝트: CaptainAL/Spyder
 def __get_annotationparam(self, title, subtitle):
     param = AnnotationParam(_("Annotation"), icon="annotation.png")
     if title is not None:
         param.title = title
     if subtitle is not None:
         param.subtitle = subtitle
     return param
예제 #3
0
 def deserialize(self, reader):
     """Deserialize object from HDF5 reader"""
     self.annotationparam = AnnotationParam(_("Annotation"),
                                            icon="annotation.png")
     reader.read('annotationparam', instance=self.annotationparam)
     self.annotationparam.update_annotation(self)
     self.shape.deserialize(reader)
     self.label.deserialize(reader)
예제 #4
0
    def loadData(self):
        self.trainingData = self.dataController.loadSampleData()
        import logic.dimreduce.paa as PAA

        p = PAA.paa()
        data = p.process(self.trainingData["PIR"][:], 100)

        r = np.array(range(len(data))).reshape(len(data), 1)
        s = np.array(data).reshape(len(data), 1)
        rs = np.hstack((s, s))
        print rs
        import logic.featurex.kmeans as km

        k = km.kmeans()
        labels = k.process(rs, 2)
        print labels
        self.plot.add_item(make.curve(range(0, len(data)), data))
        from guiqwt.styles import AnnotationParam

        i = 0
        i_beg = 0
        i_end = 0
        while i < len(labels):
            cur = labels[i_end]

            if i < len(labels) - 1:
                if labels[i_end + 1] != cur:
                    i_end = i
                    from guiqwt.annotations import AnnotatedRectangle

                    param = AnnotationParam()
                    param.title = str(labels[int(i_beg)])
                    param.show_computations = False

                    anno = AnnotatedRectangle(r[int(i_beg)], 0.5, r[int(i_end)], 0.2, param)  # TODO: y axis scaling
                    self.plot.add_item(anno)
                    i_beg = i_end
                    print "s1"
                else:
                    i_end = i
                    print "s2"
                print "s3"
            print "s4", i_end, len(labels)
            i += 1
        # param = AnnotationParam()
        # param.title = "alright"
        # param.show_computations = False

        ##anno = AnnotatedRectangle(0., 1., 1.5, 0.5, param)
        # anno.set_style("plot", "shape/drag")
        # anno.set_style("shape/drag/fill/color", "white")
        # self.plot.add_item(anno)
        # self.rangeSelection = make.range(-2, 2)
        # disp0 = make.range_info_label(self.rangeSelection, 'BR', u"x = %.1f +- %.1f cm",
        #                              title="Range infos")
        # self.plot.add_item(self.rangeSelection)
        # self.plot.add_item(disp0)
        self.plot.replot()
예제 #5
0
 def __init__(self, annotationparam=None):
     AbstractShape.__init__(self)
     assert self.LABEL_ANCHOR is not None
     self.shape = self.create_shape()
     self.label = self.create_label()
     self.area_computations_visible = True
     if annotationparam is None:
         self.annotationparam = AnnotationParam(_("Annotation"),
                                                icon="annotation.png")
     else:
         self.annotationparam = annotationparam
         self.annotationparam.update_annotation(self)
예제 #6
0
파일: annotations.py 프로젝트: HaMF/guiqwt
 def deserialize(self, reader):
     """Deserialize object from HDF5 reader"""
     self.annotationparam = AnnotationParam(_("Annotation"),
                                            icon="annotation.png")
     reader.read('annotationparam', instance=self.annotationparam)
     self.annotationparam.update_annotation(self)
     self.shape.deserialize(reader)
     self.label.deserialize(reader)
예제 #7
0
 def setup_widget(self, title):
     self.plot = plt.CurvePlot(self, title=title,
                               xunit='Hz', yunit='dB')
     self.curve_item = make.curve([], [])
     # set color to magenta
     color = QtGui.QColor(QtCore.Qt.magenta)
     color.setAlpha(150)
     self.curve_item.setPen(QtGui.QPen(color))
     self.curve_item.setBrush(QtGui.QBrush(color))
     self.plot.add_item(self.curve_item)
     a_param = AnnotationParam()
     a_param.title = 'Peak Value'
     self.peak_item = AnnotatedPoint(annotationparam=a_param)
     self.plot.add_item(self.peak_item)
     self.plot.set_antialiasing(True)
     self.plot.setCanvasBackground(QtCore.Qt.darkBlue)
     vlayout = QtWidgets.QVBoxLayout()
     vlayout.addWidget(self.plot)
     self.setLayout(vlayout)
     self.update_curve()
예제 #8
0
파일: annotations.py 프로젝트: HaMF/guiqwt
 def __init__(self, annotationparam=None):
     AbstractShape.__init__(self)
     assert self.LABEL_ANCHOR is not None
     self.shape = self.create_shape()
     self.label = self.create_label()
     self.area_computations_visible = True
     if annotationparam is None:
         self.annotationparam = AnnotationParam(_("Annotation"),
                                                icon="annotation.png")
     else:
         self.annotationparam = annotationparam
         self.annotationparam.update_annotation(self)
예제 #9
0
class AnnotatedShape(AbstractShape):
    """
    Construct an annotated shape with properties set with
    *annotationparam* (see :py:class:`guiqwt.styles.AnnotationParam`)
    """
    __implements__ = (IBasePlotItem, ISerializableType)
    SHAPE_CLASS = None
    LABEL_ANCHOR = None

    def __init__(self, annotationparam=None):
        AbstractShape.__init__(self)
        assert self.LABEL_ANCHOR is not None
        self.shape = self.create_shape()
        self.label = self.create_label()
        self.area_computations_visible = True
        if annotationparam is None:
            self.annotationparam = AnnotationParam(_("Annotation"),
                                                   icon="annotation.png")
        else:
            self.annotationparam = annotationparam
            self.annotationparam.update_annotation(self)

    def types(self):
        return (IShapeItemType, ISerializableType)

    def __reduce__(self):
        self.annotationparam.update_param(self)
        state = (self.shape, self.label, self.annotationparam)
        return (self.__class__, (), state)

    def __setstate__(self, state):
        shape, label, param = state
        self.shape = shape
        self.label = label
        self.annotationparam = param
        self.annotationparam.update_annotation(self)

    def serialize(self, writer):
        """Serialize object to HDF5 writer"""
        writer.write(self.annotationparam, group_name='annotationparam')
        self.shape.serialize(writer)
        self.label.serialize(writer)

    def deserialize(self, reader):
        """Deserialize object from HDF5 reader"""
        self.annotationparam = AnnotationParam(_("Annotation"),
                                               icon="annotation.png")
        reader.read('annotationparam', instance=self.annotationparam)
        self.annotationparam.update_annotation(self)
        self.shape.deserialize(reader)
        self.label.deserialize(reader)

    def set_style(self, section, option):
        self.shape.set_style(section, option)

    #----QwtPlotItem API--------------------------------------------------------
    def draw(self, painter, xMap, yMap, canvasRect):
        self.shape.draw(painter, xMap, yMap, canvasRect)
        if self.label.isVisible():
            self.label.draw(painter, xMap, yMap, canvasRect)

    #----Public API-------------------------------------------------------------
    def create_shape(self):
        """Return the shape object associated to this annotated shape object"""
        shape = self.SHAPE_CLASS(0, 0, 1, 1)
        return shape

    def create_label(self):
        """Return the label object associated to this annotated shape object"""
        label_param = LabelParam(_("Label"), icon='label.png')
        label_param.read_config(CONF, "plot", "shape/label")
        label_param.anchor = self.LABEL_ANCHOR
        return DataInfoLabel(label_param, [self])

    def is_label_visible(self):
        """Return True if associated label is visible"""
        return self.label.isVisible()

    def set_label_visible(self, state):
        """Set the annotated shape's label visibility"""
        self.label.setVisible(state)

    def update_label(self):
        """Update the annotated shape's label contents"""
        self.label.update_text()

    def get_text(self):
        """
        Return text associated to current shape
        (see :py:class:`guiqwt.label.ObjectInfo`)
        """
        text = ""
        title = self.title().text()
        if title:
            text += "<b>%s</b>" % title
        subtitle = self.annotationparam.subtitle
        if subtitle:
            if text:
                text += "<br>"
            text += "<i>%s</i>" % subtitle
        if self.area_computations_visible:
            infos = self.get_infos()
            if infos:
                if text:
                    text += "<br>"
                text += infos
        return text

    def x_to_str(self, x):
        """Convert x (float) to a string
        (with associated unit and uncertainty)"""
        param = self.annotationparam
        if self.plot() is None:
            return ''
        else:
            xunit = self.plot().get_axis_unit(self.xAxis())
            fmt = param.format
            if param.uncertainty:
                fmt += " ± " + (fmt % (x * param.uncertainty))
            if xunit is not None:
                return (fmt + " " + xunit) % x
            else:
                return (fmt) % x

    def y_to_str(self, y):
        """Convert y (float) to a string
        (with associated unit and uncertainty)"""
        param = self.annotationparam
        if self.plot() is None:
            return ''
        else:
            yunit = self.plot().get_axis_unit(self.yAxis())
            fmt = param.format
            if param.uncertainty:
                fmt += " ± " + (fmt % (y * param.uncertainty))
            if yunit is not None:
                return (fmt + " " + yunit) % y
            else:
                return (fmt) % y

    def get_center(self):
        """Return shape center coordinates: (xc, yc)"""
        return self.shape.get_center()

    def get_tr_center(self):
        """Return shape center coordinates after applying transform matrix"""
        raise NotImplementedError

    def get_tr_center_str(self):
        """Return center coordinates as a string (with units)"""
        xc, yc = self.get_tr_center()
        return "( %s ; %s )" % (self.x_to_str(xc), self.y_to_str(yc))

    def get_tr_size(self):
        """Return shape size after applying transform matrix"""
        raise NotImplementedError

    def get_tr_size_str(self):
        """Return size as a string (with units)"""
        xs, ys = self.get_tr_size()
        return "%s x %s" % (self.x_to_str(xs), self.y_to_str(ys))

    def get_infos(self):
        """Return formatted string with informations on current shape"""
        pass

    def set_label_position(self):
        """Set label position, for instance based on shape position"""
        raise NotImplementedError

    def apply_transform_matrix(self, x, y):
        V = np.array([x, y, 1.])
        W = np.dot(V, self.annotationparam.transform_matrix)
        return W[0], W[1]

    def get_transformed_coords(self, handle1, handle2):
        x1, y1 = self.apply_transform_matrix(*self.shape.points[handle1])
        x2, y2 = self.apply_transform_matrix(*self.shape.points[handle2])
        return x1, y1, x2, y2

    #----IBasePlotItem API------------------------------------------------------
    def hit_test(self, pos):
        return self.shape.poly_hit_test(self.plot(), self.xAxis(),
                                        self.yAxis(), pos)

    def move_point_to(self, handle, pos, ctrl=None):
        self.shape.move_point_to(handle, pos, ctrl)
        self.set_label_position()
        if self.plot():
            self.plot().SIG_ANNOTATION_CHANGED.emit(self)

    def move_shape(self, old_pos, new_pos):
        self.shape.move_shape(old_pos, new_pos)
        self.label.move_local_shape(old_pos, new_pos)

    def move_local_shape(self, old_pos, new_pos):
        old_pt = canvas_to_axes(self, old_pos)
        new_pt = canvas_to_axes(self, new_pos)
        self.shape.move_shape(old_pt, new_pt)
        self.set_label_position()
        if self.plot():
            self.plot().SIG_ITEM_MOVED.emit(self, *(old_pt + new_pt))
            self.plot().SIG_ANNOTATION_CHANGED.emit(self)

    def move_with_selection(self, delta_x, delta_y):
        """
        Translate the shape together with other selected items
        delta_x, delta_y: translation in plot coordinates
        """
        self.shape.move_with_selection(delta_x, delta_y)
        self.label.move_with_selection(delta_x, delta_y)
        self.plot.SIG_ANNOTATION_CHANGED.emit(self)

    def select(self):
        """Select item"""
        AbstractShape.select(self)
        self.shape.select()

    def unselect(self):
        """Unselect item"""
        AbstractShape.unselect(self)
        self.shape.unselect()

    def get_item_parameters(self, itemparams):
        self.shape.get_item_parameters(itemparams)
        self.label.get_item_parameters(itemparams)
        self.annotationparam.update_param(self)
        itemparams.add("AnnotationParam", self, self.annotationparam)

    def set_item_parameters(self, itemparams):
        self.shape.set_item_parameters(itemparams)
        self.label.set_item_parameters(itemparams)
        update_dataset(self.annotationparam,
                       itemparams.get("AnnotationParam"),
                       visible_only=True)
        self.annotationparam.update_annotation(self)
예제 #10
0
파일: annotations.py 프로젝트: HaMF/guiqwt
class AnnotatedShape(AbstractShape):
    """
    Construct an annotated shape with properties set with
    *annotationparam* (see :py:class:`guiqwt.styles.AnnotationParam`)
    """
    __implements__ = (IBasePlotItem, ISerializableType)
    SHAPE_CLASS = None
    LABEL_ANCHOR = None
    def __init__(self, annotationparam=None):
        AbstractShape.__init__(self)
        assert self.LABEL_ANCHOR is not None
        self.shape = self.create_shape()
        self.label = self.create_label()
        self.area_computations_visible = True
        if annotationparam is None:
            self.annotationparam = AnnotationParam(_("Annotation"),
                                                   icon="annotation.png")
        else:
            self.annotationparam = annotationparam
            self.annotationparam.update_annotation(self)
        
    def types(self):
        return (IShapeItemType, ISerializableType)
    
    def __reduce__(self):
        self.annotationparam.update_param(self)
        state = (self.shape, self.label, self.annotationparam)
        return (self.__class__, (), state)

    def __setstate__(self, state):
        shape, label, param = state
        self.shape = shape
        self.label = label
        self.annotationparam = param
        self.annotationparam.update_annotation(self)

    def serialize(self, writer):
        """Serialize object to HDF5 writer"""
        writer.write(self.annotationparam, group_name='annotationparam')
        self.shape.serialize(writer)
        self.label.serialize(writer)
    
    def deserialize(self, reader):
        """Deserialize object from HDF5 reader"""
        self.annotationparam = AnnotationParam(_("Annotation"),
                                               icon="annotation.png")
        reader.read('annotationparam', instance=self.annotationparam)
        self.annotationparam.update_annotation(self)
        self.shape.deserialize(reader)
        self.label.deserialize(reader)
    
    def set_style(self, section, option):
        self.shape.set_style(section, option)
        
    #----QwtPlotItem API--------------------------------------------------------
    def draw(self, painter, xMap, yMap, canvasRect):
        self.shape.draw(painter, xMap, yMap, canvasRect)
        if self.label.isVisible():
            self.label.draw(painter, xMap, yMap, canvasRect)
        
    #----Public API-------------------------------------------------------------
    def create_shape(self):
        """Return the shape object associated to this annotated shape object"""
        shape = self.SHAPE_CLASS(0, 0, 1, 1)
        return shape
        
    def create_label(self):
        """Return the label object associated to this annotated shape object"""
        label_param = LabelParam(_("Label"), icon='label.png')
        label_param.read_config(CONF, "plot", "shape/label")
        label_param.anchor = self.LABEL_ANCHOR
        return DataInfoLabel(label_param, [self])
        
    def is_label_visible(self):
        """Return True if associated label is visible"""
        return self.label.isVisible()
        
    def set_label_visible(self, state):
        """Set the annotated shape's label visibility"""
        self.label.setVisible(state)
        
    def update_label(self):
        """Update the annotated shape's label contents"""
        self.label.update_text()

    def get_text(self):
        """
        Return text associated to current shape
        (see :py:class:`guiqwt.label.ObjectInfo`)
        """
        text = ""
        title = self.title().text()
        if title:
            text += "<b>%s</b>" % title
        subtitle = self.annotationparam.subtitle
        if subtitle:
            if text:
                text += "<br>"
            text += "<i>%s</i>" % subtitle
        if self.area_computations_visible:
            infos = self.get_infos()
            if infos:
                if text:
                    text += "<br>"
                text += infos
        return text

    def x_to_str(self, x):
        """Convert x (float) to a string
        (with associated unit and uncertainty)"""
        param = self.annotationparam
        if self.plot() is None:
            return ''
        else:
            xunit = self.plot().get_axis_unit(self.xAxis())
            fmt = param.format
            if param.uncertainty:
                fmt += " ± " + (fmt % (x*param.uncertainty))
            if xunit is not None:
                return (fmt+" "+xunit) % x
            else:
                return (fmt) % x    

    def y_to_str(self, y):
        """Convert y (float) to a string
        (with associated unit and uncertainty)"""
        param = self.annotationparam
        if self.plot() is None:
            return ''
        else:
            yunit = self.plot().get_axis_unit(self.yAxis())
            fmt = param.format
            if param.uncertainty:
                fmt += " ± " + (fmt % (y*param.uncertainty))
            if yunit is not None:
                return (fmt+" "+yunit) % y
            else:
                return (fmt) % y
                
    def get_center(self):
        """Return shape center coordinates: (xc, yc)"""
        return self.shape.get_center()
        
    def get_tr_center(self):
        """Return shape center coordinates after applying transform matrix"""
        raise NotImplementedError
        
    def get_tr_center_str(self):
        """Return center coordinates as a string (with units)"""
        xc, yc = self.get_tr_center()
        return "( %s ; %s )" % (self.x_to_str(xc), self.y_to_str(yc))
        
    def get_tr_size(self):
        """Return shape size after applying transform matrix"""
        raise NotImplementedError
        
    def get_tr_size_str(self):
        """Return size as a string (with units)"""
        xs, ys = self.get_tr_size()
        return "%s x %s" % (self.x_to_str(xs), self.y_to_str(ys))
        
    def get_infos(self):
        """Return formatted string with informations on current shape"""
        pass
        
    def set_label_position(self):
        """Set label position, for instance based on shape position"""
        raise NotImplementedError
    
    def apply_transform_matrix(self, x, y):
        V = np.array([x, y, 1.])
        W = np.dot(V, self.annotationparam.transform_matrix)
        return W[0], W[1]
    
    def get_transformed_coords(self, handle1, handle2):
        x1, y1 = self.apply_transform_matrix(*self.shape.points[handle1])
        x2, y2 = self.apply_transform_matrix(*self.shape.points[handle2])
        return x1, y1, x2, y2

    #----IBasePlotItem API------------------------------------------------------
    def hit_test(self, pos):
        return self.shape.poly_hit_test(self.plot(),
                                        self.xAxis(), self.yAxis(), pos)
            
    def move_point_to(self, handle, pos, ctrl=None):
        self.shape.move_point_to(handle, pos, ctrl)
        self.set_label_position()
        if self.plot():
            self.plot().emit(SIG_ANNOTATION_CHANGED, self)

    def move_shape(self, old_pos, new_pos):
        self.shape.move_shape(old_pos, new_pos)
        self.label.move_local_shape(old_pos, new_pos)
        
    def move_local_shape(self, old_pos, new_pos):
        old_pt = canvas_to_axes(self, old_pos)
        new_pt = canvas_to_axes(self, new_pos)
        self.shape.move_shape(old_pt, new_pt)
        self.set_label_position()
        if self.plot():
            self.plot().emit(SIG_ITEM_MOVED, self, *(old_pt+new_pt))
            self.plot().emit(SIG_ANNOTATION_CHANGED, self)
            
    def move_with_selection(self, delta_x, delta_y):
        """
        Translate the shape together with other selected items
        delta_x, delta_y: translation in plot coordinates
        """
        self.shape.move_with_selection(delta_x, delta_y)
        self.label.move_with_selection(delta_x, delta_y)
        self.plot().emit(SIG_ANNOTATION_CHANGED, self)

    def select(self):
        """Select item"""
        AbstractShape.select(self)
        self.shape.select()
    
    def unselect(self):
        """Unselect item"""
        AbstractShape.unselect(self)
        self.shape.unselect()

    def get_item_parameters(self, itemparams):
        self.shape.get_item_parameters(itemparams)
        self.label.get_item_parameters(itemparams)
        self.annotationparam.update_param(self)
        itemparams.add("AnnotationParam", self, self.annotationparam)
    
    def set_item_parameters(self, itemparams):
        self.shape.set_item_parameters(itemparams)
        self.label.set_item_parameters(itemparams)
        update_dataset(self.annotationparam, itemparams.get("AnnotationParam"),
                       visible_only=True)
        self.annotationparam.update_annotation(self)
예제 #11
0
    def process(self):
        params = {}
        for i in range(self.tableWidget.rowCount()):
            a = self.tableWidget.item(i, 0)
            b = self.tableWidget.item(i, 1)
            params[str(a.text())] = int(b.text())
        print "params", params
        outpN = self.tableWidget.item(0, 0)
        #params = {"none": "none", "output_length": outpN}


        r = np.array(range(len(self.dc.dimrecprocData))).reshape(len(self.dc.dimrecprocData), 1)
        s = np.array(self.dc.dimrecprocData).reshape(len(self.dc.dimrecprocData), 1)
        rs = np.hstack((s, s))

        labels = self.fec.extractFeature(rs, params)
        print labels
        self.plot.del_all_items()
        self.plot.replot()
        self.plot.add_item(
            make.curve(range(0, len(self.dc.dimrecprocData)), self.dc.dimrecprocData))

        from guiqwt.styles import AnnotationParam

        i = 0
        i_beg = 0
        i_end = 0
        while i < len(labels):
            cur = labels[i_end]

            if i < len(labels) - 1:
                if labels[i_end + 1] != cur:
                    i_end = i
                    from guiqwt.annotations import AnnotatedRectangle

                    param = AnnotationParam()
                    param.title = str(labels[int(i_beg)])
                    param.show_computations = False

                    anno = AnnotatedRectangle(r[int(i_beg)], self.dc.dimrecprocData[int(i_beg)], int(i_end), self.dc.dimrecprocData[r[int(i_end)]], param) #TODO: y axis scaling
                    self.plot.add_item(anno)
                    i_beg = i_end
                    print "s1"
                else:
                    i_end = i
                    print "s2"
                print "s3"
            print "s4", i_end, len(labels)
            i += 1

        self.rangeSelection = make.range(-2, 2)
        disp0 = make.range_info_label(self.rangeSelection, 'BR', u"x = %.1f +- %.1f cm",
                                      title="Range infos")
        #self.plot.add_item(self.rangeSelection)
        #self.plot.add_item(disp0)
        #self.dc.setCurrentDataFlowObject(self.flowData)
        self.dc.featureexData = self.flowData
        self.dc.setCurrentLabels(labels)
        print(self.dc.setCurrentLabels)
        #ToDo: Check that following line, make property in data controller
        self.dc.dimrecprocData = rs
        self.plot.replot()
        self.currentdata = np.reshape(labels, (-1, 1))