Exemplo n.º 1
0
    def testCountsCalculation(self):
        """Test result of count calculation"""
        x = numpy.arange(100.)
        y = numpy.arange(100.)

        # Add two curves
        self.plot.addCurve(x, y, legend="positive")
        self.plot.addCurve(-x, y, legend="negative")

        # Make sure there is an active curve and it is the positive one
        self.plot.setActiveCurve("positive")

        # Add two ROIs
        roi_neg = CurvesROIWidget.ROI(name='negative',
                                      fromdata=-20,
                                      todata=-10,
                                      type_='X')
        roi_pos = CurvesROIWidget.ROI(name='positive',
                                      fromdata=10,
                                      todata=20,
                                      type_='X')

        self.widget.roiWidget.setRois((roi_pos, roi_neg))

        posCurve = self.plot.getCurve('positive')
        negCurve = self.plot.getCurve('negative')

        self.assertEqual(roi_pos.computeRawAndNetCounts(posCurve),
                         (y[10:21].sum(), 0.0))
        self.assertEqual(roi_pos.computeRawAndNetCounts(negCurve), (0.0, 0.0))
        self.assertEqual(roi_neg.computeRawAndNetCounts(posCurve),
                         ((0.0), 0.0))
        self.assertEqual(roi_neg.computeRawAndNetCounts(negCurve),
                         (y[10:21].sum(), 0.0))
Exemplo n.º 2
0
    def testAreaCalculation(self):
        x = numpy.arange(100.)
        y = numpy.arange(100.)

        # Add two curves
        self.plot.addCurve(x, y, legend="positive")
        self.plot.addCurve(-x, y, legend="negative")

        # Make sure there is an active curve and it is the positive one
        self.plot.setActiveCurve("positive")

        # Add two ROIs
        roi_neg = CurvesROIWidget.ROI(name='negative', fromdata=-20,
                                      todata=-10, type_='X')
        roi_pos = CurvesROIWidget.ROI(name='positive', fromdata=10,
                                      todata=20, type_='X')

        self.widget.roiWidget.setRois((roi_pos, roi_neg))

        posCurve = self.plot.getCurve('positive')
        negCurve = self.plot.getCurve('negative')

        self.assertEqual(roi_pos.computeRawAndNetArea(posCurve),
                        (numpy.trapz(y=[10, 20], x=[10, 20]),
                        0.0))
        self.assertEqual(roi_pos.computeRawAndNetArea(negCurve),
                         (0.0, 0.0))
        self.assertEqual(roi_neg.computeRawAndNetArea(posCurve),
                         ((0.0), 0.0))
        self.assertEqual(roi_neg.computeRawAndNetArea(negCurve),
                         ((-150.0), 0.0))
Exemplo n.º 3
0
    def testShowAllROI(self):
        """Test the show allROI action"""
        x = numpy.arange(100.)
        y = numpy.arange(100.)
        self.plot.addCurve(x=x, y=y, legend="name", replace="True")

        roisDefsDict = {
            "range1": {
                "from": 20,
                "to": 200,
                "type": "energy"
            },
            "range2": {
                "from": 300,
                "to": 500,
                "type": "energy"
            }
        }

        roisDefsObj = (CurvesROIWidget.ROI(name='range3',
                                           fromdata=20,
                                           todata=200,
                                           type_='energy'),
                       CurvesROIWidget.ROI(name='range4',
                                           fromdata=300,
                                           todata=500,
                                           type_='energy'))
        self.widget.roiWidget.showAllMarkers(True)
        roiWidget = self.plot.getCurvesRoiDockWidget().roiWidget
        roiWidget.setRois(roisDefsDict)
        self.assertTrue(len(self.plot._getAllMarkers()) is 2 * 3)

        markersHandler = self.widget.roiWidget.roiTable._markersHandler
        roiWidget.showAllMarkers(True)
        ICRROI = markersHandler.getVisibleRois()
        self.assertTrue(len(ICRROI) is 2)

        roiWidget.showAllMarkers(False)
        ICRROI = markersHandler.getVisibleRois()
        self.assertTrue(len(ICRROI) is 1)

        roiWidget.setRois(roisDefsObj)
        self.qapp.processEvents()
        self.assertTrue(len(self.plot._getAllMarkers()) is 2 * 3)

        markersHandler = self.widget.roiWidget.roiTable._markersHandler
        roiWidget.showAllMarkers(True)
        ICRROI = markersHandler.getVisibleRois()
        self.assertTrue(len(ICRROI) is 2)

        roiWidget.showAllMarkers(False)
        ICRROI = markersHandler.getVisibleRois()
        self.assertTrue(len(ICRROI) is 1)
Exemplo n.º 4
0
    def testDummyAPI(self):
        """Simple test of the getRois and setRois API"""
        roi_neg = CurvesROIWidget.ROI(name='negative',
                                      fromdata=-20,
                                      todata=-10,
                                      type_='X')
        roi_pos = CurvesROIWidget.ROI(name='positive',
                                      fromdata=10,
                                      todata=20,
                                      type_='X')

        self.widget.roiWidget.setRois((roi_pos, roi_neg))

        rois_defs = self.widget.roiWidget.getRois()
        self.widget.roiWidget.setRois(rois=rois_defs)
Exemplo n.º 5
0
    def testRoiEdition(self):
        """Make sure if the ROI object is edited the ROITable will be updated
        """
        roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
        self.widget.roiWidget.setRois((roi, ))

        x = (0, 1, 1, 2, 2, 3)
        y = (1, 1, 2, 2, 1, 1)
        self.plot.addCurve(x=x, y=y, legend='linearCurve')
        self.plot.setActiveCurve(legend='linearCurve')
        self.widget.calculateROIs()

        roiTable = self.widget.roiWidget.roiTable
        indexesColumns = CurvesROIWidget.ROITable.COLUMNS_INDEX
        itemRawCounts = roiTable.item(0, indexesColumns['Raw Counts'])
        itemNetCounts = roiTable.item(0, indexesColumns['Net Counts'])

        self.assertTrue(itemRawCounts.text() == '8.0')
        self.assertTrue(itemNetCounts.text() == '2.0')

        itemRawArea = roiTable.item(0, indexesColumns['Raw Area'])
        itemNetArea = roiTable.item(0, indexesColumns['Net Area'])

        self.assertTrue(itemRawArea.text() == '4.0')
        self.assertTrue(itemNetArea.text() == '1.0')

        roi.setTo(2)
        itemRawArea = roiTable.item(0, indexesColumns['Raw Area'])
        self.assertTrue(itemRawArea.text() == '3.0')
        roi.setFrom(1)
        itemRawArea = roiTable.item(0, indexesColumns['Raw Area'])
        self.assertTrue(itemRawArea.text() == '2.0')
Exemplo n.º 6
0
 def testSetActiveCurve(self):
     """Test sigRoiSignal when set an active curve"""
     roi1 = CurvesROIWidget.ROI(name='linear', fromdata=2, todata=5)
     self.curves_roi_widget.roiTable.setActiveRoi(roi1)
     self.listener.clear()
     self.plot.setActiveCurve('curve0')
     self.assertEqual(self.listener.callCount(), 0)
Exemplo n.º 7
0
    def testRemoveActiveROI(self):
        roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
        self.widget.roiWidget.setRois((roi,))

        self.widget.roiWidget.roiTable.setActiveRoi(None)
        self.assertTrue(len(self.widget.roiWidget.roiTable.selectedItems()) is 0)
        self.widget.roiWidget.setRois((roi,))
        self.plot.setActiveCurve(legend='linearCurve')
        self.widget.calculateROIs()
Exemplo n.º 8
0
    def testSigROISignalAddRmRois(self):
        """Test SigROISignal when adding and removing ROIS"""
        print(self.listener.callCount())
        self.assertEqual(self.listener.callCount(), 1)
        self.listener.clear()

        roi1 = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
        self.curves_roi_widget.roiTable.addRoi(roi1)
        self.assertEqual(self.listener.callCount(), 1)
        self.assertTrue(self.listener.arguments()[0][0]['current'] == 'linear')
        self.listener.clear()

        roi2 = CurvesROIWidget.ROI(name='linear2', fromdata=0, todata=5)
        self.curves_roi_widget.roiTable.addRoi(roi2)
        self.assertEqual(self.listener.callCount(), 1)
        self.assertTrue(
            self.listener.arguments()[0][0]['current'] == 'linear2')
        self.listener.clear()

        self.curves_roi_widget.roiTable.removeROI(roi2)
        self.assertEqual(self.listener.callCount(), 1)
        self.assertTrue(self.curves_roi_widget.roiTable.activeRoi == roi1)
        self.assertTrue(self.listener.arguments()[0][0]['current'] == 'linear')
        self.listener.clear()

        self.curves_roi_widget.roiTable.deleteActiveRoi()
        self.assertEqual(self.listener.callCount(), 1)
        self.assertTrue(self.curves_roi_widget.roiTable.activeRoi is None)
        self.assertTrue(self.listener.arguments()[0][0]['current'] is None)
        self.listener.clear()

        self.curves_roi_widget.roiTable.addRoi(roi1)
        self.assertEqual(self.listener.callCount(), 1)
        self.assertTrue(self.listener.arguments()[0][0]['current'] == 'linear')
        self.assertTrue(self.curves_roi_widget.roiTable.activeRoi == roi1)
        self.listener.clear()
        self.qapp.processEvents()

        self.curves_roi_widget.roiTable.removeROI(roi1)
        self.qapp.processEvents()
        self.assertEqual(self.listener.callCount(), 1)
        self.assertTrue(self.listener.arguments()[0][0]['current'] == 'ICR')
        self.listener.clear()
Exemplo n.º 9
0
    def setUp(self):
        super(TestCurvesROIWidget, self).setUp()
        self.plot = PlotWindow()
        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        self.widget = CurvesROIWidget.CurvesROIDockWidget(plot=self.plot,
                                                          name='TEST')
        self.widget.show()
        self.qWaitForWindowExposed(self.widget)
Exemplo n.º 10
0
    def testRemoveActiveROI(self):
        """Test widget behavior when removing the active ROI"""
        roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
        self.widget.roiWidget.setRois((roi, ))

        self.widget.roiWidget.roiTable.setActiveRoi(None)
        self.assertEqual(len(self.widget.roiWidget.roiTable.selectedItems()),
                         0)
        self.widget.roiWidget.setRois((roi, ))
        self.plot.setActiveCurve(legend='linearCurve')
        self.widget.calculateROIs()
Exemplo n.º 11
0
 def testEmitCurrentROI(self):
     """Test behavior of the CurvesROIWidget.sigROISignal"""
     roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
     self.widget.roiWidget.setRois((roi, ))
     signalListener = SignalListener()
     self.widget.roiWidget.sigROISignal.connect(signalListener.partial())
     self.widget.show()
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 0)
     self.assertTrue(self.widget.roiWidget.roiTable.activeRoi is roi)
     roi.setFrom(0.0)
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 0)
     roi.setFrom(0.3)
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 1)
Exemplo n.º 12
0
    def testSigROISignalModifyROI(self):
        """Test SigROISignal when modifying it"""
        self.curves_roi_widget.roiTable.setMiddleROIMarkerFlag(True)
        roi1 = CurvesROIWidget.ROI(name='linear', fromdata=2, todata=5)
        self.curves_roi_widget.roiTable.addRoi(roi1)
        self.curves_roi_widget.roiTable.setActiveRoi(roi1)

        # test modify the roi2 object
        self.listener.clear()
        roi1.setFrom(0.56)
        self.assertEqual(self.listener.callCount(), 1)
        self.listener.clear()
        roi1.setTo(2.56)
        self.assertEqual(self.listener.callCount(), 1)
        self.listener.clear()
        roi1.setName('linear2')
        self.assertEqual(self.listener.callCount(), 1)
        self.listener.clear()
        roi1.setType('new type')
        self.assertEqual(self.listener.callCount(), 1)

        widget = self.plot.getWidgetHandle()
        widget.setFocus(qt.Qt.OtherFocusReason)
        self.plot.raise_()
        self.qapp.processEvents()

        # modify roi limits (from the gui)
        roi_marker_handler = self.curves_roi_widget.roiTable._markersHandler.getMarkerHandler(
            roi1.getID())
        for marker_type in ('min', 'max', 'middle'):
            with self.subTest(marker_type=marker_type):
                self.listener.clear()
                marker = roi_marker_handler.getMarker(marker_type)
                x_pix, y_pix = self.plot.dataToPixel(marker.getXPosition(),
                                                     marker.getYPosition())
                self.mouseMove(widget, pos=(x_pix, y_pix))
                self.qWait(100)
                self.mousePress(widget, qt.Qt.LeftButton, pos=(x_pix, y_pix))
                self.mouseMove(widget, pos=(x_pix + 20, y_pix))
                self.qWait(100)
                self.mouseRelease(widget,
                                  qt.Qt.LeftButton,
                                  pos=(x_pix + 20, y_pix))
                self.qWait(100)
                self.mouseMove(widget, pos=(x_pix, y_pix))
                self.qapp.processEvents()
                self.assertEqual(self.listener.callCount(), 1)
Exemplo n.º 13
0
    def testSigROISignalModifyROI(self):
        """Test SigROISignal when modifying it"""
        self.curves_roi_widget.roiTable.setMiddleROIMarkerFlag(True)
        roi1 = CurvesROIWidget.ROI(name='linear', fromdata=2, todata=5)
        self.curves_roi_widget.roiTable.addRoi(roi1)
        self.curves_roi_widget.roiTable.setActiveRoi(roi1)

        # test modify the roi2 object
        self.listener.clear()
        roi1.setFrom(0.56)
        self.assertEqual(self.listener.callCount(), 1)
        self.listener.clear()
        roi1.setTo(2.56)
        self.assertEqual(self.listener.callCount(), 1)
        self.listener.clear()
        roi1.setName('linear2')
        self.assertEqual(self.listener.callCount(), 1)
        self.listener.clear()
        roi1.setType('new type')
        self.assertEqual(self.listener.callCount(), 1)

        # modify roi limits (from the gui)
        roi_marker_handler = self.curves_roi_widget.roiTable._markersHandler.getMarkerHandler(
            roi1.getID())
        for marker_type in ('min', 'max', 'middle'):
            with self.subTest(marker_type=marker_type):
                self.listener.clear()
                marker = roi_marker_handler.getMarker(marker_type)
                self.qapp.processEvents()
                items_interaction = ItemsInteraction(plot=self.plot)
                x_pix, y_pix = self.plot.dataToPixel(marker.getXPosition(), 1)
                items_interaction.beginDrag(x_pix, y_pix)
                self.qapp.processEvents()
                items_interaction.endDrag(x_pix + 10, y_pix)
                self.qapp.processEvents()
                self.assertEqual(self.listener.callCount(), 1)