Beispiel #1
0
    def draw(self,
             p,
             time_projection,
             y_projection,
             draw_line=True,
             draw_triangle=False,
             **kwargs):

        from PyQt4 import QtCore as qc
        from PyQt4 import QtGui as qg
        from pyrocko import gui_util

        if self.selected or self.alerted or not self.nslc_ids:

            color = self.select_color(self.color_b)
            pen = qg.QPen(qg.QColor(*color))
            pen.setWidth(2)
            linepen = qg.QPen(pen)
            if self.selected or self.alerted:
                linepen.setStyle(qc.Qt.CustomDashLine)
                pat = [5., 3.]
                linepen.setDashPattern(pat)
                if self.alerted and not self.selected:
                    linepen.setColor(qg.QColor(150, 150, 150))

            s = 9.
            utriangle = gui_util.make_QPolygonF([-0.577 * s, 0., 0.577 * s],
                                                [0., 1. * s, 0.])
            ltriangle = gui_util.make_QPolygonF([-0.577 * s, 0., 0.577 * s],
                                                [0., -1. * s, 0.])

            def drawline(t):
                u = time_projection(t)
                v0, v1 = y_projection.get_out_range()
                line = qc.QLineF(u, v0, u, v1)
                p.drawLine(line)

            def drawtriangles(t):
                u = time_projection(t)
                v0, v1 = y_projection.get_out_range()
                t = qg.QPolygonF(utriangle)
                t.translate(u, v0)
                p.drawConvexPolygon(t)
                t = qg.QPolygonF(ltriangle)
                t.translate(u, v1)
                p.drawConvexPolygon(t)

            if draw_line or self.selected or self.alerted:
                p.setPen(linepen)
                drawline(self.tmin)
                drawline(self.tmax)

            if draw_triangle:
                pen.setStyle(qc.Qt.SolidLine)
                pen.setJoinStyle(qc.Qt.MiterJoin)
                pen.setWidth(2)
                p.setPen(pen)
                p.setBrush(qg.QColor(*color))
                drawtriangles(self.tmin)
Beispiel #2
0
    def drawit(self, p):
        '''Draw beachball into painter.'''

        h = self.height()
        w = self.width()

        s = min(h, w)*0.9

        xproj = Projection()
        xproj.set_in_range(-1., 1.)
        xproj.set_out_range((w-s)/2., w-(w-s)/2.)

        yproj = Projection()
        yproj.set_in_range(-1., 1.)
        yproj.set_out_range(h-(h-s)/2., (h-s)/2.)

        # m = mtm.symmat6(*(num.random.random(6)*2.-1.))
        # mtm.MomentTensor(m=m)

        mt = self._mt

        mt_devi = mt.deviatoric()
        eig = mt_devi.eigensystem()

        group_to_color = {
            'P': plot.graph_colors[0],
            'T': plot.graph_colors[1]}

        for (group, patches, patches_lower, patches_upper,
                lines, lines_lower, lines_upper) in beachball.eig2gx(eig):

            color = group_to_color[group]
            brush = qg.QBrush(qg.QColor(*color))
            p.setBrush(brush)

            pen = qg.QPen(qg.QColor(*color))
            pen.setWidth(1)
            p.setPen(pen)

            for poly in patches_lower:
                px, py, pz = poly.T
                points = make_QPolygonF(xproj(px), yproj(py))
                p.drawPolygon(points)

            color = (0, 0, 0)
            pen = qg.QPen(qg.QColor(*color))
            pen.setWidth(2)
            p.setPen(pen)

            for poly in lines_lower:
                px, py, pz = poly.T
                points = make_QPolygonF(xproj(px), yproj(py))
                p.drawPolyline(points)
    def drawit(self, p):
        '''Draw beachball into painter.'''

        h = self.height()
        w = self.width()

        s = min(h, w) * 0.9

        xproj = Projection()
        xproj.set_in_range(-1., 1.)
        xproj.set_out_range((w - s) / 2., w - (w - s) / 2.)

        yproj = Projection()
        yproj.set_in_range(-1., 1.)
        yproj.set_out_range(h - (h - s) / 2., (h - s) / 2.)

        #m = mtm.symmat6(*(num.random.random(6)*2.-1.))
        #mtm.MomentTensor(m=m)

        mt = self._mt

        mt_devi = mt.deviatoric()
        eig = mt_devi.eigensystem()

        group_to_color = {'P': plot.graph_colors[0], 'T': plot.graph_colors[1]}

        for (group, patches, patches_lower, patches_upper, lines, lines_lower,
             lines_upper) in beachball.eig2gx(eig):

            color = group_to_color[group]
            brush = QBrush(QColor(*color))
            p.setBrush(brush)

            pen = QPen(QColor(*color))
            pen.setWidth(1)
            p.setPen(pen)

            for poly in patches_lower:
                px, py, pz = poly.T
                points = make_QPolygonF(xproj(px), yproj(py))
                p.drawPolygon(points)

            color = (0, 0, 0)
            pen = QPen(QColor(*color))
            pen.setWidth(2)
            p.setPen(pen)

            for poly in lines_lower:
                px, py, pz = poly.T
                points = make_QPolygonF(xproj(px), yproj(py))
                p.drawPolyline(points)
Beispiel #4
0
 def paintEvent(self, e):
     center = e.rect().center()
     painter = qg.QPainter(self)
     painter.save()
     try:
         data = mt2beachball(self.moment_tensor, size=self.height()/2.2,
                             position=(center.x(), center.y()))
         for pdata in data:
             paths, fill, edges, thickness = pdata
             brush, pen = self.brushs_pens[fill]
             polygon = qg.QPolygonF()
             polygon = make_QPolygonF(*paths.T)
             painter.setRenderHint(qg.QPainter.Antialiasing)
             painter.setBrush(brush)
             painter.setPen(pen)
             painter.drawPolygon(polygon)
     except BeachballError as e:
         logger.exception(e)
     finally:
         painter.restore()
Beispiel #5
0
 def paintEvent(self, e):
     center = e.rect().center()
     painter = qg.QPainter(self)
     painter.save()
     try:
         data = mt2beachball(self.moment_tensor,
                             size=self.height() / 2.2,
                             position=(center.x(), center.y()))
         for pdata in data:
             paths, fill, edges, thickness = pdata
             brush, pen = self.brushs_pens[fill]
             polygon = qg.QPolygonF()
             polygon = make_QPolygonF(*paths.T)
             painter.setRenderHint(qg.QPainter.Antialiasing)
             painter.setBrush(brush)
             painter.setPen(pen)
             painter.drawPolygon(polygon)
     except BeachballError as e:
         logger.exception(e)
     finally:
         painter.restore()
Beispiel #6
0
    def draw_trace(self,
                   viewer,
                   p,
                   tr,
                   time_projection,
                   track_projection,
                   gain,
                   outline_label=False):

        from PyQt4 import QtCore as qc
        from PyQt4 import QtGui as qg
        from pyrocko import gui_util

        if self.nslc_ids and not self.match_nslc(tr.nslc_id):
            return

        color = self.select_color(self.color_b)
        pen = qg.QPen(qg.QColor(*color))
        pen.setWidth(2)
        p.setPen(pen)
        p.setBrush(qc.Qt.NoBrush)

        def drawpoint(t, y):
            u = time_projection(t)
            v = track_projection(y)
            rect = qc.QRectF(u - 2, v - 2, 4, 4)
            p.drawRect(rect)

        def drawline(t):
            u = time_projection(t)
            v0, v1 = track_projection.get_out_range()
            line = qc.QLineF(u, v0, u, v1)
            p.drawLine(line)

        try:
            snippet = tr.chop(self.tmin,
                              self.tmax,
                              inplace=False,
                              include_last=True,
                              snap=(math.ceil, math.floor))

            vdata = track_projection(gain * snippet.get_ydata())
            udata_min = float(time_projection(snippet.tmin))
            udata_max = float(
                time_projection(snippet.tmin + snippet.deltat *
                                (vdata.size - 1)))
            udata = num.linspace(udata_min, udata_max, vdata.size)
            qpoints = gui_util.make_QPolygonF(udata, vdata)
            pen.setWidth(1)
            p.setPen(pen)
            p.drawPolyline(qpoints)
            pen.setWidth(2)
            p.setPen(pen)
            drawpoint(*tr(self.tmin, clip=True, snap=math.ceil))
            drawpoint(*tr(self.tmax, clip=True, snap=math.floor))

        except trace.NoData:
            pass

        color = self.select_color(self.color_b)
        pen = qg.QPen(qg.QColor(*color))
        pen.setWidth(2)
        p.setPen(pen)

        drawline(self.tmin)
        drawline(self.tmax)

        label = self.get_label()
        if label:
            label_bg = qg.QBrush(qg.QColor(255, 255, 255))

            u = time_projection(self.tmin)
            v0, v1 = track_projection.get_out_range()
            if outline_label:
                du = -7
            else:
                du = -5
            gui_util.draw_label(p,
                                u + du,
                                v0,
                                label,
                                label_bg,
                                'TR',
                                outline=outline_label)

        if self.tmin == self.tmax:
            try:
                drawpoint(self.tmin, tr.interpolate(self.tmin))

            except IndexError:
                pass