class ModeView(qt.QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.hist = Plot1D(self) self.stack = StackView(self) self.stack.setColormap({'name': 'viridis', 'autoscale': True}) self.setLayout(qt.QHBoxLayout()) splitter = qt.QSplitter() splitter.addWidget(self.hist) splitter.addWidget(self.stack) self.layout().addWidget(splitter) def set_data(self, probes, psize): ampl, nplist = ortho(probes) edges = list(range(len(ampl))) self.hist.addHistogram(ampl, edges, legend='data', fill=True, color='b') self.hist.setGraphXLabel('Mode #') self.hist.setGraphYLabel('Relative power $\\beta$') self.stack.setStack(np.abs(np.array(nplist))**2) zeta = leastsq(func=residuals, x0=.5, args=(ampl, ))[0][0] self.hist.addCurve(edges, model(zeta, ampl), color='r', linewidth=2) self.hist.setGraphYLimits(0, 1) self.hist.setGraphTitle('$\\zeta$=%.2f (fit)' % zeta)
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 __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.hist = Plot1D(self) self.stack = StackView(self) self.stack.setColormap({'name': 'viridis', 'autoscale': True}) self.setLayout(qt.QHBoxLayout()) splitter = qt.QSplitter() splitter.addWidget(self.hist) splitter.addWidget(self.stack) self.layout().addWidget(splitter)
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 testProfile2D(self): """Test that the profile plot associated to a stack view is either a Plot1D or a plot 2D instance.""" self.plot = StackView() self.plot.show() self.qWaitForWindowExposed(self.plot) self.plot.setStack(numpy.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]])) toolBar = self.plot.getProfileToolbar() manager = toolBar.getProfileManager() roiManager = manager.getRoiManager() roi = rois.ProfileImageStackHorizontalLineROI() roi.setPosition(0.5) roi.setProfileType("2D") roiManager.addRoi(roi) roiManager.setCurrentRoi(roi) for _ in range(20): self.qWait(200) if not manager.hasPendingOperations(): break profileWindow = roi.getProfileWindow() self.assertIsInstance(roi.getProfileWindow(), qt.QMainWindow) self.assertIsInstance(profileWindow.getCurrentPlotWidget(), Plot2D) roi.setProfileType("1D") for _ in range(20): self.qWait(200) if not manager.hasPendingOperations(): break profileWindow = roi.getProfileWindow() self.assertIsInstance(roi.getProfileWindow(), qt.QMainWindow) self.assertIsInstance(profileWindow.getCurrentPlotWidget(), Plot1D)
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
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]]) ))
class TestGetProfilePlot(TestCaseQt): def setUp(self): self.plot = None super(TestGetProfilePlot, self).setUp() def tearDown(self): if self.plot is not None: manager = self.plot.getProfileToolbar().getProfileManager() manager.clearProfile() manager = None self.plot.setAttribute(qt.Qt.WA_DeleteOnClose) self.plot.close() self.plot = None super(TestGetProfilePlot, self).tearDown() def testProfile1D(self): self.plot = Plot2D() self.plot.show() self.qWaitForWindowExposed(self.plot) self.plot.addImage([[0, 1], [2, 3]]) toolBar = self.plot.getProfileToolbar() manager = toolBar.getProfileManager() roiManager = manager.getRoiManager() roi = rois.ProfileImageHorizontalLineROI() roi.setPosition(0.5) roiManager.addRoi(roi) roiManager.setCurrentRoi(roi) for _ in range(20): self.qWait(200) if not manager.hasPendingOperations(): break profileWindow = roi.getProfileWindow() self.assertIsInstance(roi.getProfileWindow(), qt.QMainWindow) self.assertIsInstance(profileWindow.getCurrentPlotWidget(), Plot1D) def testProfile2D(self): """Test that the profile plot associated to a stack view is either a Plot1D or a plot 2D instance.""" self.plot = StackView() self.plot.show() self.qWaitForWindowExposed(self.plot) self.plot.setStack(numpy.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]])) toolBar = self.plot.getProfileToolbar() manager = toolBar.getProfileManager() roiManager = manager.getRoiManager() roi = rois.ProfileImageStackHorizontalLineROI() roi.setPosition(0.5) roi.setProfileType("2D") roiManager.addRoi(roi) roiManager.setCurrentRoi(roi) for _ in range(20): self.qWait(200) if not manager.hasPendingOperations(): break profileWindow = roi.getProfileWindow() self.assertIsInstance(roi.getProfileWindow(), qt.QMainWindow) self.assertIsInstance(profileWindow.getCurrentPlotWidget(), Plot2D) roi.setProfileType("1D") for _ in range(20): self.qWait(200) if not manager.hasPendingOperations(): break profileWindow = roi.getProfileWindow() self.assertIsInstance(roi.getProfileWindow(), qt.QMainWindow) self.assertIsInstance(profileWindow.getCurrentPlotWidget(), Plot1D)
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)