예제 #1
0
 def test_setConfiguration(self, qtbot):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     truthConfig = CentroidPlotConfig()
     truthConfig.numHistogramBins = 50
     cspw.setConfiguration(truthConfig)
     cspw.numBins == truthConfig.numHistogramBins
예제 #2
0
 def test_updateData(self, qtbot):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     arraySize = 3
     cspw.setup(arraySize)
     truthAlpha = [127, 191, 255]
     alpha = [x.color().alpha() for x in cspw.brushes]
     assert alpha == truthAlpha
     valuesX = [254.43, 254.86, 253.91, 254.21]
     valuesY = [355.25, 355.10, 354.89, 355.57]
     cspw.updateData(valuesX[0], valuesY[0])
     assert cspw.xData.tolist() == [valuesX[0]]
     assert cspw.yData.tolist() == [valuesY[0]]
     assert cspw.dataCounter == 1
     cspw.updateData(valuesX[1], valuesY[1])
     cspw.updateData(valuesX[2], valuesY[2])
     assert cspw.xData.tolist() == valuesX[:-1]
     assert cspw.yData.tolist() == valuesY[:-1]
     assert cspw.dataCounter == arraySize
     assert cspw.rollArray is True
     cspw.updateData(valuesX[3], valuesY[3])
     assert cspw.xData.tolist() == valuesX[1:]
     assert cspw.yData.tolist() == valuesY[1:]
     assert cspw.dataCounter == arraySize
     assert cspw.rollArray is True
    def test_setPlotConfiguration(self, qtbot, mocker):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)
        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)
        mockXSetConfiguration = mocker.patch.object(p1cc.x1dPlot,
                                                    'setConfiguration')
        mockYSetConfiguration = mocker.patch.object(p1cc.y1dPlot,
                                                    'setConfiguration')
        mockScatterSetConfiguration = mocker.patch.object(
            p1cc.scatterPlot, 'setConfiguration')

        truthConfig = {
            'xCentroid': {
                'autoscale': False,
                'minimum': 10,
                'maximum': 1000
            },
            'yCentroid': {
                'autoscale': True,
                'minimum': None,
                'maximum': None
            },
            'scatterPlot': {
                'numHistogramBins': 50
            }
        }
        p1cc.setPlotConfiguration(truthConfig)
        assert mockXSetConfiguration.call_count == 1
        assert mockYSetConfiguration.call_count == 1
        assert mockScatterSetConfiguration.call_count == 1
 def test_getPlotConfiguration(self, qtbot):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     p1cc = PlotCentroidController(cxp, cyp, csp)
     currentConfig = p1cc.getPlotConfiguration()
     assert currentConfig == self.truthConfig
예제 #5
0
 def test_parametersAfterSetup(self, qtbot):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     arraySize = 1000
     cspw.setup(arraySize)
     assert cspw.scatterPlot is not None
     assert cspw.dataSize == arraySize
     assert cspw.xData is not None
     assert cspw.yData is not None
     assert cspw.xHistogramItem is not None
     assert cspw.yHistogramItem is not None
     assert cspw.rollArray is False
     assert cspw.dataCounter == 0
     assert cspw.brushes is not None
     assert len(cspw.brushes) == arraySize
     assert cspw.brushes[0].color().alpha() == 127
     assert cspw.brushes[200].color().alpha() == 152
     assert cspw.brushes[400].color().alpha() == 178
     assert cspw.brushes[600].color().alpha() == 203
     assert cspw.brushes[800].color().alpha() == 229
     assert cspw.brushes[-1].color().alpha() == 255
예제 #6
0
 def test_clearPlot(self, qtbot, mocker):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     arraySize = 3
     cspw.setup(arraySize)
     valuesX = [254.43, 254.86, 253.91, 254.21]
     valuesY = [355.25, 355.10, 354.89, 355.57]
     for x, y in zip(valuesX, valuesY):
         cspw.updateData(x, y)
     cspw.clearPlot()
     assert cspw.rollArray is False
     assert cspw.dataCounter == 0
     assert len(cspw.xData) == 0
     assert len(cspw.yData) == 0
    def test_parametersAfterConstruction(self, qtbot):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)

        p1cc = PlotCentroidController(cxp, cyp, csp)
        assert p1cc.x1dPlot is not None
        assert p1cc.y1dPlot is not None
        assert p1cc.scatterPlot is not None
        assert p1cc.config is not None
 def test_updateRoiFps(self, qtbot, mocker):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     p1cc = PlotCentroidController(cxp, cyp, csp)
     mockXSetRoiFps = mocker.patch.object(p1cc.x1dPlot, 'setRoiFps')
     mockYSetRoiFps = mocker.patch.object(p1cc.y1dPlot, 'setRoiFps')
     p1cc.setup(self.bufferSize, self.roiFps)
     p1cc.updateRoiFps(20)
     assert mockXSetRoiFps.call_count == 1
     assert mockYSetRoiFps.call_count == 1
    def test_parametersAfterSetup(self, qtbot):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)

        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)

        assert p1cc.x1dPlot.dataSize == self.bufferSize
        assert p1cc.y1dPlot.dataSize == self.bufferSize
        assert p1cc.scatterPlot.dataSize == self.bufferSize
예제 #10
0
 def test_updateArraySize(self, qtbot):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     arraySize = 3
     cspw.setup(arraySize)
     cspw.rollArray = True
     newArraySize = 20
     cspw.setArraySize(newArraySize)
     assert cspw.dataSize == newArraySize
     assert cspw.xData.shape[0] == 0
     assert cspw.yData.shape[0] == 0
     assert len(cspw.brushes) == newArraySize
     assert cspw.rollArray is False
예제 #11
0
 def test_showPlot(self, qtbot, mocker):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     arraySize = 3
     cspw.setup(arraySize)
     # Add some data so plot doesn't fail
     valuesX = [254.43, 254.86, 253.91, 254.21]
     valuesY = [355.25, 355.10, 354.89, 355.57]
     for x, y in zip(valuesX, valuesY):
         cspw.updateData(x, y)
     mockScatterSetData = mocker.patch.object(cspw.scatterPlotItem,
                                              'setData')
     mockXHistSetData = mocker.patch.object(cspw.xHistogramItem, 'setData')
     mockYHistSetData = mocker.patch.object(cspw.yHistogramItem, 'setData')
     cspw.showPlot()
     assert mockScatterSetData.call_count == 1
     assert mockXHistSetData.call_count == 1
     assert mockYHistSetData.call_count == 1
 def test_handleAcquireRoiStateChange(self, qtbot, mocker):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     p1cc = PlotCentroidController(cxp, cyp, csp)
     p1cc.setup(self.bufferSize, self.roiFps)
     mockXClearPlot = mocker.patch.object(p1cc.x1dPlot, 'clearPlot')
     mockYClearPlot = mocker.patch.object(p1cc.y1dPlot, 'clearPlot')
     mockScatterClearPlot = mocker.patch.object(p1cc.scatterPlot,
                                                'clearPlot')
     p1cc.handleAcquireRoiStateChange(Qt.Unchecked)
     assert mockXClearPlot.call_count == 1
     assert mockYClearPlot.call_count == 1
     assert mockScatterClearPlot.call_count == 1
 def test_showScatterPlots(self, qtbot, mocker):
     cxp = Centroid1dPlotWidget()
     cyp = Centroid1dPlotWidget()
     csp = CentroidScatterPlotWidget()
     qtbot.addWidget(cxp)
     qtbot.addWidget(cyp)
     qtbot.addWidget(csp)
     mocker.patch('spot_motion_monitor.views.centroid_scatter_plot_widget.'
                  'CentroidScatterPlotWidget.showPlot')
     p1cc = PlotCentroidController(cxp, cyp, csp)
     p1cc.setup(self.bufferSize, self.roiFps)
     centroidX = 253.543
     centroidY = 313.683
     p1cc.update(centroidX, centroidY)
     p1cc.showScatterPlots(False)
     assert p1cc.scatterPlot.showPlot.call_count == 0
     p1cc.showScatterPlots(True)
     assert p1cc.scatterPlot.showPlot.call_count == 1
    def test_update(self, qtbot):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)

        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)
        centroidX = 253.543
        centroidY = 313.683
        p1cc.update(centroidX, centroidY)

        assert p1cc.x1dPlot.data[0] == centroidX
        assert p1cc.y1dPlot.data[0] == centroidY
        assert p1cc.scatterPlot.xData[0] == centroidX
        assert p1cc.scatterPlot.yData[0] == centroidY
    def test_badCentroidsUpdate(self, qtbot, mocker):
        cxp = Centroid1dPlotWidget()
        cyp = Centroid1dPlotWidget()
        csp = CentroidScatterPlotWidget()
        qtbot.addWidget(cxp)
        qtbot.addWidget(cyp)
        qtbot.addWidget(csp)
        mocker.patch(
            'spot_motion_monitor.views.centroid_1d_plot_widget.Centroid1dPlotWidget.updatePlot'
        )
        mocker.patch('spot_motion_monitor.views.centroid_scatter_plot_widget.'
                     'CentroidScatterPlotWidget.updateData')

        p1cc = PlotCentroidController(cxp, cyp, csp)
        p1cc.setup(self.bufferSize, self.roiFps)
        p1cc.update(None, None)
        assert p1cc.x1dPlot.updatePlot.call_count == 0
        assert p1cc.y1dPlot.updatePlot.call_count == 0
        assert p1cc.scatterPlot.updateData.call_count == 0
예제 #16
0
 def test_parametersAfterConstruction(self, qtbot):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     assert cspw.scatterPlot is not None
     assert cspw.dataSize is None
     assert cspw.xData is None
     assert cspw.yData is None
     assert cspw.xHistogramItem is None
     assert cspw.yHistogramItem is None
     assert cspw.numBins == 40
     assert cspw.rollArray is False
     assert cspw.dataCounter == 0
     assert cspw.brushes is None
     color = (159, 159, 159)
     assert cspw.brushColor == color
     assert cspw.maxAlpha == 255
     assert cspw.minAlpha == 127
     hFillBrush = self.makeColorTuple(cspw.histogramFillBrush)
     assert hFillBrush == color
     pBrush = self.makeColorTuple(cspw.pointBrush)
     assert pBrush == color
예제 #17
0
 def test_getConfiguration(self, qtbot):
     cspw = CentroidScatterPlotWidget()
     qtbot.addWidget(cspw)
     truthNumHistoBins = 40
     numHistoBins = cspw.getConfiguration()
     assert numHistoBins == truthNumHistoBins