예제 #1
0
def test_array_to_polygonf():
    x = np.stack((np.arange(10), np.arange(10)), axis=1)
    poly = array_to_polygonf(x)
    assert poly.size() == 10
    for i in range(poly.size()):
        assert poly[i].x() == i
        assert poly[i].y() == i
예제 #2
0
파일: drift.py 프로젝트: djdt/pewpew
    def drawDrift(self, x: np.ndarray, y: np.ndarray):
        if np.any(np.isnan(y)):
            nanstart = np.argmax(np.isnan(y))
            nanend = y.size - np.argmax(np.isnan(y[::-1]))

            points1 = np.stack((x[:nanstart], y[:nanstart]), axis=1)
            points2 = np.stack((x[nanend:], y[nanend:]), axis=1)

            poly1 = array_to_polygonf(points1)
            poly2 = array_to_polygonf(points2)

            self.drift1.replace(poly1)
            self.drift2.replace(poly2)
        else:
            points = np.stack((x, y), axis=1)
            poly = array_to_polygonf(points)

            self.drift1.replace(poly)
            self.drift2.clear()

        self.xaxis.setRange(0, x[-1])
        self.yaxis.setRange(np.nanmin(y), np.nanmax(y))
예제 #3
0
    def setPoints(self, points: np.ndarray) -> None:
        if not (points.ndim == 2 and points.shape[1] == 2):  # pragma: no cover
            raise ValueError("points must have shape (n, 2).")

        xmin, xmax = np.amin(points[:, 0]), np.amax(points[:, 0])
        ymin, ymax = np.amin(points[:, 1]), np.amax(points[:, 1])

        self.xaxis.setRange(xmin, xmax)
        self.yaxis.setRange(ymin, ymax)

        poly = array_to_polygonf(points)
        self.series.replace(poly)

        self.xaxis.applyNiceNumbers()
        self.yaxis.applyNiceNumbers()
예제 #4
0
    def createSlicePoly(self) -> QtGui.QPolygonF:
        def connect_nd(ends):
            d = np.diff(ends, axis=0)[0]
            j = np.argmax(np.abs(d))
            D = d[j]
            aD = np.abs(D)
            return ends[0] + (np.outer(np.arange(aD + 1), d) + (aD >> 1)) // aD

        p1 = self.image.mapToData(self.line.p1())
        p2 = self.image.mapToData(self.line.p2())

        if self.line.dx() < 0.0:
            p1, p2 = p2, p1

        view = next(iter(self.scene().views()))
        height = view.mapToScene(QtCore.QRect(0, 0, 1, 100)).boundingRect().height()

        points = connect_nd([[p1.x(), p1.y()], [p2.x(), p2.y()]])
        if points.size > 3:
            self.sliced = self.image_data[points[:, 1], points[:, 0]]

            xs = np.linspace(0.0, self.line.length(), self.sliced.size)
            try:
                ys = -1.0 * normalise(self.sliced, 0.0, height)
            except ValueError:
                self.sliced = None
                self.poly.clear()
                return

            poly = array_to_polygonf(np.stack((xs, ys), axis=1))

            angle = self.line.angle()
            if 90 < angle < 270:
                angle -= 180

            transform = QtGui.QTransform()
            if self.line.dx() < 0.0:
                transform.translate(self.line.p2().x(), self.line.p2().y())
            else:
                transform.translate(self.line.p1().x(), self.line.p1().y())
            transform.rotate(-angle)

            self.poly = transform.map(poly)
예제 #5
0
파일: drift.py 프로젝트: djdt/pewpew
    def drawFit(self, x: np.ndarray, y: np.ndarray):
        points = np.stack((x, y), axis=1)
        poly = array_to_polygonf(points)

        self.fit.replace(poly)
예제 #6
0
파일: colocal.py 프로젝트: djdt/pewpew
 def drawPoints(self, x: np.ndarray, y: np.ndarray) -> None:
     """Plot scatter of 'x' and 'y'."""
     points = np.stack([x.flat, y.flat], axis=1)
     poly = array_to_polygonf(points)
     self.scatter.replace(poly)
예제 #7
0
파일: signal.py 프로젝트: djdt/pewpew
 def setSeries(self, name: str, ys: np.ndarray, xs: np.ndarray = None) -> None:
     if xs is None:
         xs = np.arange(ys.size)
     data = np.stack((xs, ys), axis=1)
     poly = array_to_polygonf(data)
     self.series[name].replace(poly)