def testProfile2D(self):
        """Test that the profile plot associated to a stack view is either a
        Plot1D or a plot 2D instance."""
        plot = StackView()
        plot.show()
        self.qWaitForWindowExposed(plot)

        plot.setStack(numpy.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]))

        self.assertIsInstance(plot.getProfileToolbar().getProfileMainWindow(),
                              qt.QMainWindow)

        self.assertIsInstance(plot.getProfileToolbar().getProfilePlot(),
                              Plot2D)
        plot.getProfileToolbar().profile3dAction.computeProfileIn1D()
        self.assertIsInstance(plot.getProfileToolbar().getProfilePlot(),
                              Plot1D)

        plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        plot.close()
        del plot
Ejemplo n.º 2
0
    def testProfile2D(self):
        """Test that the profile plot associated to a stack view is either a
        Plot1D or a plot 2D instance."""
        plot = StackView()
        plot.show()
        self.qWaitForWindowExposed(plot)

        plot.setStack(numpy.array([[[0, 1], [2, 3]],
                                   [[4, 5], [6, 7]]]))

        self.assertIsInstance(plot.getProfileToolbar().getProfileMainWindow(),
                              qt.QMainWindow)

        self.assertIsInstance(plot.getProfileToolbar().getProfilePlot(),
                              Plot2D)
        plot.getProfileToolbar().profile3dAction.computeProfileIn1D()
        self.assertIsInstance(plot.getProfileToolbar().getProfilePlot(),
                              Plot1D)

        plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        plot.close()
        del plot
Ejemplo n.º 3
0
class TestProfile3DToolBar(TestCaseQt):
    """Tests for Profile3DToolBar widget.
    """
    def setUp(self):
        super(TestProfile3DToolBar, self).setUp()
        self.plot = StackView()
        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        self.plot.setStack(numpy.array([
            [[0, 1, 2], [3, 4, 5]],
            [[6, 7, 8], [9, 10, 11]],
            [[12, 13, 14], [15, 16, 17]]
        ]))

    def tearDown(self):
        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.plot.close()
        self.plot = None

        super(TestProfile3DToolBar, self).tearDown()

    def testMethodProfile1DAnd2D(self):
        """Test that the profile can have a different method if we want to
        compute then in 1D or in 2D"""

        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('mean')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'mean')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.5
        self.mouseClick(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[1, 4], [7, 10], [13, 16]])
        ))

        # check 1D 'sum' profile
        _2DProfileToolbar = _2DProfilePlot.getProfileToolbar()
        _2DProfileToolbar.setProfileMethod('sum')
        self.assertTrue(_2DProfileToolbar.getProfileMethod() == 'sum')
        _1DProfilePlot = _2DProfileToolbar.getProfilePlot()

        _2DProfileToolbar.lineWidthSpinBox.setValue(3)
        toolButton = getQToolButtonFromAction(_2DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot1D = _2DProfilePlot.getWidgetHandle()
        pos1 = plot1D.width() * 0.5, plot1D.height() * 0.5
        self.mouseClick(plot1D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _1DProfilePlot.getAllCurves()[0].getData()[1],
            numpy.array([5, 17, 29])
        ))

    def testMethodSumLine(self):
        """Simple interaction test to make sure the sum is correctly computed
        """
        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('sum')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'sum')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.lineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.2
        pos2 = plot2D.width() * 0.5, plot2D.height() * 0.8

        self.mouseMove(plot2D, pos=pos1)
        self.mousePress(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.mouseMove(plot2D, pos=pos2)
        self.mouseRelease(plot2D, qt.Qt.LeftButton, pos=pos2)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[3, 12], [21, 30], [39, 48]])
        ))
Ejemplo n.º 4
0
class TestProfile3DToolBar(TestCaseQt):
    """Tests for Profile3DToolBar widget.
    """
    def setUp(self):
        super(TestProfile3DToolBar, self).setUp()
        self.plot = StackView()
        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        self.plot.setStack(numpy.array([
            [[0, 1, 2], [3, 4, 5]],
            [[6, 7, 8], [9, 10, 11]],
            [[12, 13, 14], [15, 16, 17]]
        ]))

    def tearDown(self):
        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.plot.close()
        self.plot = None

        super(TestProfile3DToolBar, self).tearDown()

    def testMethodProfile1DAnd2D(self):
        """Test that the profile can have a different method if we want to
        compute then in 1D or in 2D"""

        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('mean')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'mean')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.5
        self.mouseClick(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[1, 4], [7, 10], [13, 16]])
        ))

        # check 1D 'sum' profile
        _2DProfileToolbar = _2DProfilePlot.getProfileToolbar()
        _2DProfileToolbar.setProfileMethod('sum')
        self.assertTrue(_2DProfileToolbar.getProfileMethod() == 'sum')
        _1DProfilePlot = _2DProfileToolbar.getProfilePlot()

        _2DProfileToolbar.lineWidthSpinBox.setValue(3)
        toolButton = getQToolButtonFromAction(_2DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot1D = _2DProfilePlot.getWidgetHandle()
        pos1 = plot1D.width() * 0.5, plot1D.height() * 0.5
        self.mouseClick(plot1D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _1DProfilePlot.getAllCurves()[0].getData()[1],
            numpy.array([5, 17, 29])
        ))

    def testMethodSumLine(self):
        """Simple interaction test to make sure the sum is correctly computed
        """
        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('sum')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'sum')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.lineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.2
        pos2 = plot2D.width() * 0.5, plot2D.height() * 0.8

        self.mouseMove(plot2D, pos=pos1)
        self.mousePress(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.mouseMove(plot2D, pos=pos2)
        self.mouseRelease(plot2D, qt.Qt.LeftButton, pos=pos2)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[3, 12], [21, 30], [39, 48]])
        ))
Ejemplo n.º 5
0
class TestProfile3DToolBar(TestCaseQt):
    """Tests for Profile3DToolBar widget.
    """
    def setUp(self):
        super(TestProfile3DToolBar, self).setUp()
        self.plot = StackView()
        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        self.plot.setStack(
            numpy.array([[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]],
                         [[12, 13, 14], [15, 16, 17]]]))
        deprecation.FORCE = True

    def tearDown(self):
        deprecation.FORCE = False
        profileManager = self.plot.getProfileToolbar().getProfileManager()
        profileManager.clearProfile()
        profileManager = None
        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.plot.close()
        self.plot = None

        super(TestProfile3DToolBar, self).tearDown()

    @testutils.test_logging(deprecation.depreclog.name, warning=2)
    def testMethodProfile2D(self):
        """Test that the profile can have a different method if we want to
        compute then in 1D or in 2D"""

        toolBar = self.plot.getProfileToolbar()

        toolBar.vLineAction.trigger()
        plot2D = self.plot.getPlotWidget().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.5
        self.mouseClick(plot2D, qt.Qt.LeftButton, pos=pos1)

        manager = toolBar.getProfileManager()
        roi = manager.getCurrentRoi()
        roi.setProfileMethod("mean")
        roi.setProfileType("2D")
        roi.setProfileLineWidth(3)

        for _ in range(20):
            self.qWait(200)
            if not manager.hasPendingOperations():
                break

        # check 2D 'mean' profile
        profilePlot = toolBar.getProfilePlot()
        data = profilePlot.getAllImages()[0].getData()
        expected = numpy.array([[1, 4], [7, 10], [13, 16]])
        numpy.testing.assert_almost_equal(data, expected)

    @testutils.test_logging(deprecation.depreclog.name, warning=2)
    def testMethodSumLine(self):
        """Simple interaction test to make sure the sum is correctly computed
        """
        toolBar = self.plot.getProfileToolbar()

        toolBar.lineAction.trigger()
        plot2D = self.plot.getPlotWidget().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.2
        pos2 = plot2D.width() * 0.5, plot2D.height() * 0.8

        self.mouseMove(plot2D, pos=pos1)
        self.mousePress(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.mouseMove(plot2D, pos=pos2)
        self.mouseRelease(plot2D, qt.Qt.LeftButton, pos=pos2)

        manager = toolBar.getProfileManager()
        roi = manager.getCurrentRoi()
        roi.setProfileMethod("sum")
        roi.setProfileType("2D")
        roi.setProfileLineWidth(3)

        for _ in range(20):
            self.qWait(200)
            if not manager.hasPendingOperations():
                break

        # check 2D 'sum' profile
        profilePlot = toolBar.getProfilePlot()
        data = profilePlot.getAllImages()[0].getData()
        expected = numpy.array([[3, 12], [21, 30], [39, 48]])
        numpy.testing.assert_almost_equal(data, expected)