def testVerticalProfile(self): """Test ScatterProfileToolBar vertical profile""" nPoints = 8 self.profile.setNPoints(nPoints) self.assertEqual(self.profile.getNPoints(), nPoints) # Add a scatter plot self.plot.addScatter(x=(0., 1., 1., 0.), y=(0., 0., 1., 1.), value=(0., 1., 2., 3.)) self.plot.resetZoom(dataMargins=(.1, .1, .1, .1)) self.qapp.processEvents() # Activate vertical profile vlineAction = self.profile.actions()[1] vlineAction.trigger() self.qapp.processEvents() # Set a ROI profile roi = roi_items.VerticalLineROI() roi.setPosition(0.5) self.profile._getRoiManager().addRoi(roi) # Wait for async interpolator init for _ in range(10): self.qWait(200) if not self.profile.hasPendingOperations(): break self.assertIsNotNone(self.profile.getProfileValues()) points = self.profile.getProfilePoints() self.assertEqual(len(points), nPoints) # Check that profile has same limits than Plot yLimits = self.plot.getYAxis().getLimits() self.assertEqual(points[0, 1], yLimits[0]) self.assertEqual(points[-1, 1], yLimits[1]) # Check that profile limits are updated when changing limits self.plot.getYAxis().setLimits(yLimits[0] + 1, yLimits[1] + 10) self.qapp.processEvents() yLimits = self.plot.getYAxis().getLimits() points = self.profile.getProfilePoints() self.assertEqual(points[0, 1], yLimits[0]) self.assertEqual(points[-1, 1], yLimits[1]) # Clear the plot self.plot.clear() self.qapp.processEvents() self.assertIsNone(self.profile.getProfileValues()) self.assertIsNone(self.profile.getProfilePoints())
def testRoiDisplay(self): rois = [] # Line item = roi_items.LineROI() startPoint = numpy.array([1, 2]) endPoint = numpy.array([3, 4]) item.setEndPoints(startPoint, endPoint) rois.append(item) # Horizontal line item = roi_items.HorizontalLineROI() item.setPosition(15) rois.append(item) # Vertical line item = roi_items.VerticalLineROI() item.setPosition(15) rois.append(item) # Point item = roi_items.PointROI() point = numpy.array([1, 2]) item.setPosition(point) rois.append(item) # Rectangle item = roi_items.RectangleROI() origin = numpy.array([0, 0]) size = numpy.array([10, 20]) item.setGeometry(origin=origin, size=size) rois.append(item) # Polygon item = roi_items.PolygonROI() points = numpy.array([[10, 10], [12, 10], [50, 1]]) item.setPoints(points) rois.append(item) # Degenerated polygon: No points item = roi_items.PolygonROI() points = numpy.empty((0, 2)) item.setPoints(points) rois.append(item) # Degenerated polygon: A single point item = roi_items.PolygonROI() points = numpy.array([[5, 10]]) item.setPoints(points) rois.append(item) # Degenerated arc: it's a point item = roi_items.ArcROI() center = numpy.array([10, 20]) innerRadius, outerRadius, startAngle, endAngle = 0, 0, 0, 0 item.setGeometry(center, innerRadius, outerRadius, startAngle, endAngle) rois.append(item) # Degenerated arc: it's a line item = roi_items.ArcROI() center = numpy.array([10, 20]) innerRadius, outerRadius, startAngle, endAngle = 0, 100, numpy.pi, numpy.pi item.setGeometry(center, innerRadius, outerRadius, startAngle, endAngle) rois.append(item) # Special arc: it's a donut item = roi_items.ArcROI() center = numpy.array([10, 20]) innerRadius, outerRadius, startAngle, endAngle = 1, 100, numpy.pi, 3 * numpy.pi item.setGeometry(center, innerRadius, outerRadius, startAngle, endAngle) rois.append(item) # Arc item = roi_items.ArcROI() center = numpy.array([10, 20]) innerRadius, outerRadius, startAngle, endAngle = 1, 100, numpy.pi * 0.5, numpy.pi item.setGeometry(center, innerRadius, outerRadius, startAngle, endAngle) rois.append(item) # Horizontal Range item = roi_items.HorizontalRangeROI() item.setRange(-1, 3) rois.append(item) manager = roi.RegionOfInterestManager(self.plot) self.roiTableWidget.setRegionOfInterestManager(manager) for item in rois: with self.subTest(roi=str(item)): manager.addRoi(item) self.qapp.processEvents() item.setEditable(True) self.qapp.processEvents() item.setEditable(False) self.qapp.processEvents() manager.removeRoi(item) self.qapp.processEvents()
def testVLine_geometry(self): item = roi_items.VerticalLineROI() item.setPosition(15) self.assertEqual(item.getPosition(), 15)
def testPoint_geometry(self): point = numpy.array([1, 2]) item = roi_items.VerticalLineROI() item.setPosition(point) numpy.testing.assert_allclose(item.getPosition(), point)