Changeset 64f1e93 in sasview
- Timestamp:
- Dec 7, 2016 5:47:22 AM (8 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 416fa8f
- Parents:
- 55d89f8
- Location:
- src/sas/qtgui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/GUITests.py
r0fc37fea r64f1e93 9 9 from UnitTesting import MainWindowTest 10 10 from UnitTesting import TestUtilsTest 11 from UnitTesting import PlotHelperTest 12 from UnitTesting import PlotterTest 13 from UnitTesting import Plotter2DTest 14 from UnitTesting import SasviewLoggerTest 15 from UnitTesting import ScalePropertiesTest 16 from UnitTesting import KiessigCalculatorTest 17 from UnitTesting import DensityCalculatorTest 11 18 12 19 def suite(): 13 20 suites = ( 14 unittest.makeSuite(AboutBoxTest.AboutBoxTest, 'test'),15 unittest.makeSuite(DataExplorerTest.DataExplorerTest, 'test'),16 unittest.makeSuite(WelcomePanelTest.WelcomePanelTest, 'test'),21 unittest.makeSuite(AboutBoxTest.AboutBoxTest, 'test'), 22 unittest.makeSuite(DataExplorerTest.DataExplorerTest, 'test'), 23 unittest.makeSuite(WelcomePanelTest.WelcomePanelTest, 'test'), 17 24 unittest.makeSuite(DroppableDataLoadWidgetTest.DroppableDataLoadWidgetTest, 'test'), 18 unittest.makeSuite(GuiManagerTest.GuiManagerTest, 'test'), 19 unittest.makeSuite(GuiUtilsTest.GuiUtilsTest, 'test'), 20 unittest.makeSuite(MainWindowTest.MainWindowTest, 'test'), 21 unittest.makeSuite(TestUtilsTest.TestUtilsTest, 'test'), 25 unittest.makeSuite(GuiManagerTest.GuiManagerTest, 'test'), 26 unittest.makeSuite(GuiUtilsTest.GuiUtilsTest, 'test'), 27 unittest.makeSuite(MainWindowTest.MainWindowTest, 'test'), 28 unittest.makeSuite(TestUtilsTest.TestUtilsTest, 'test'), 29 unittest.makeSuite(PlotHelperTest.PlotHelperTest, 'test'), 30 unittest.makeSuite(PlotterTest.PlotterTest, 'test'), 31 unittest.makeSuite(Plotter2DTest.Plotter2DTest, 'test'), 32 unittest.makeSuite(SasviewLoggerTest.SasviewLoggerTest, 'test'), 33 unittest.makeSuite(ScalePropertiesTest.ScalePropertiesTest, 'test'), 34 unittest.makeSuite(KiessigCalculatorTest.KiessigCalculatorTest, 'test'), 35 unittest.makeSuite(DensityCalculatorTest.DensityCalculatorTest, 'test'), 22 36 ) 23 37 return unittest.TestSuite(suites) -
src/sas/qtgui/Plotter2D.py
r55d89f8 r64f1e93 9 9 import sas.qtgui.PlotUtilities as PlotUtilities 10 10 from sas.qtgui.PlotterBase import PlotterBase 11 from mpl_toolkits.mplot3d import Axes3D 11 12 12 13 class Plotter2D(PlotterBase): … … 40 41 Plot 2D self._data 41 42 """ 42 # create an axis object43 # Toggle the scale 43 44 zmin_2D_temp = self.zmin 44 45 zmax_2D_temp = self.zmax … … 60 61 zmax_2D_temp = numpy.log10(self.zmax) 61 62 62 self.image(data=self.data.data, qx_data=self.qx_data, 63 qy_data=self.qy_data, xmin=self.xmin, 64 xmax=self.xmax, 65 ymin=self.ymin, ymax=self.ymax, 66 cmap=self.cmap, zmin=zmin_2D_temp, 67 zmax=zmax_2D_temp) 63 # Prepare and show the plot 64 self.showPlot(data=self.data.data, 65 qx_data=self.qx_data, 66 qy_data=self.qy_data, 67 xmin=self.xmin, 68 xmax=self.xmax, 69 ymin=self.ymin, ymax=self.ymax, 70 cmap=self.cmap, zmin=zmin_2D_temp, 71 zmax=zmax_2D_temp) 68 72 69 73 def contextMenuQuickPlot(self): … … 96 100 self.plot() 97 101 98 def image(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax,99 zmin, zmax, color=0, symbol=0, markersize=0,100 label='data2D', cmap=DEFAULT_CMAP):102 def showPlot(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax, 103 zmin, zmax, color=0, symbol=0, markersize=0, 104 label='data2D', cmap=DEFAULT_CMAP): 101 105 """ 102 Render the current data106 Render and show the current data 103 107 """ 104 108 self.qx_data = qx_data … … 152 156 else: 153 157 # clear the previous 2D from memory 154 # mpl is not clf, so we do155 158 self.figure.clear() 156 159 … … 161 164 X, Y = numpy.meshgrid(X, Y) 162 165 163 try: 164 # mpl >= 1.0.0 165 ax = self.figure.gca(projection='3d') 166 cbax = self.figure.add_axes([0.84, 0.1, 0.02, 0.8]) 167 if len(X) > 60: 168 ax.disable_mouse_rotation() 169 except: 170 # mpl < 1.0.0 171 try: 172 from mpl_toolkits.mplot3d import Axes3D 173 except: 174 logging.error("PlotPanel could not import Axes3D") 175 self.figure.clear() 176 ax = Axes3D(self.figure) 177 if len(X) > 60: 178 ax.cla() 179 cbax = None 166 ax = Axes3D(self.figure) 167 cbax = self.figure.add_axes([0.84, 0.1, 0.02, 0.8]) 168 # Disable rotation for large sets. 169 # TODO: Define "large" for a dataset 170 SET_TOO_LARGE = 500 171 if len(X) > SET_TOO_LARGE: 172 ax.disable_mouse_rotation() 173 180 174 self.figure.canvas.resizing = False 181 175 im = ax.plot_surface(X, Y, output, rstride=1, cstride=1, cmap=cmap, … … 190 184 cb.update_bruteforce(im) 191 185 cb.set_label('$' + self.scale + '$') 186 192 187 if self.dimension != 3: 193 188 self.figure.canvas.draw_idle() -
src/sas/qtgui/PlotterBase.py
r55d89f8 r64f1e93 90 90 self._title = title 91 91 92 #def id(self, id=""):93 # """ id setter """94 # self.id = id95 96 92 @property 97 93 def xLabel(self, xlabel=""): -
src/sas/qtgui/UnitTesting/GuiManagerTest.py
r31c5b58 r64f1e93 119 119 Test that the custom exit method is called on shutdown 120 120 """ 121 self.manager._workspace.show() 122 121 123 # Must mask sys.exit, otherwise the whole testing process stops. 122 124 sys.exit = MagicMock() -
src/sas/qtgui/UnitTesting/Plotter2DTest.py
r55d89f8 r64f1e93 6 6 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 7 7 from mock import MagicMock 8 from mpl_toolkits.mplot3d import Axes3D 8 9 9 10 ####### TEMP … … 54 55 self.plotter.data = self.data 55 56 self.plotter.show() 56 FigureCanvas.draw = MagicMock()57 FigureCanvas.draw_idle = MagicMock() 57 58 58 59 self.plotter.plot() 59 60 60 #self.assertTrue(FigureCanvas.draw.called) 61 self.assertTrue(FigureCanvas.draw_idle.called) 62 63 def testOnToggleScale(self): 64 """ Respond to the event by replotting """ 65 self.plotter.data = self.data 66 self.plotter.show() 67 FigureCanvas.draw_idle = MagicMock() 68 69 self.plotter.onToggleScale(None) 70 71 self.assertTrue(FigureCanvas.draw_idle.called) 61 72 62 73 def testContextMenuQuickPlot(self): … … 99 110 # Trigger Change Scale and make sure the method is called 100 111 self.assertEqual(actions[6].text(), "Toggle Linear/Log Scale") 112 FigureCanvas.draw_idle = MagicMock() 113 actions[6].trigger() 114 self.assertTrue(FigureCanvas.draw_idle.called) 115 116 def testShowNoPlot(self): 117 """ Test the plot rendering and generation """ 118 119 FigureCanvas.draw_idle = MagicMock() 101 120 FigureCanvas.draw = MagicMock() 102 actions[6].trigger() 103 #self.assertTrue(FigureCanvas.draw.called) 121 122 # Test early return on no data 123 self.plotter.showPlot(data=None, 124 qx_data=self.data.qx_data, 125 qy_data=self.data.qy_data, 126 xmin=self.data.xmin, 127 xmax=self.data.xmax, 128 ymin=self.data.ymin, ymax=self.data.ymax, 129 cmap=None, zmin=None, 130 zmax=None) 131 132 self.assertFalse(FigureCanvas.draw_idle.called) 133 self.assertFalse(FigureCanvas.draw.called) 134 135 def testShow3DPlot(self): 136 """ Test the 3Dplot rendering and generation """ 137 # Test 3D printout 138 FigureCanvas.draw = MagicMock() 139 Axes3D.plot_surface = MagicMock() 140 self.plotter.figure.colorbar = MagicMock() 141 142 self.plotter.dimension = 3 143 self.plotter.data = self.data 144 self.plotter.showPlot(data=self.plotter.data.data, 145 qx_data=self.data.qx_data, 146 qy_data=self.data.qy_data, 147 xmin=self.data.xmin, 148 xmax=self.data.xmax, 149 ymin=self.data.ymin, ymax=self.data.ymax, 150 cmap=None, zmin=None, 151 zmax=None) 152 self.assertTrue(Axes3D.plot_surface.called) 153 self.assertTrue(FigureCanvas.draw.called) 154 155 def testShow2DPlot(self): 156 """ Test the 2Dplot rendering and generation """ 157 # Test 2D printout 158 FigureCanvas.draw_idle = MagicMock() 159 self.plotter.figure.colorbar = MagicMock() 160 161 self.plotter.dimension = 2 162 self.plotter.data = self.data 163 self.plotter.showPlot(data=self.plotter.data.data, 164 qx_data=self.data.qx_data, 165 qy_data=self.data.qy_data, 166 xmin=self.data.xmin, 167 xmax=self.data.xmax, 168 ymin=self.data.ymin, ymax=self.data.ymax, 169 cmap=None, zmin=None, 170 zmax=None) 171 self.assertTrue(FigureCanvas.draw_idle.called) 104 172 105 173 -
src/sas/qtgui/UnitTesting/PlotterTest.py
r6d05e1d r64f1e93 100 100 self.plotter.data = self.data 101 101 102 self.plotter.xyTransform(xLabel="ln(x)", yLabel="ln(y)") 103 self.assertEqual(self.plotter.ax.get_xlabel(), "$\\ln{()}()$") 102 self.plotter.xyTransform(xLabel="x", yLabel="y") 103 self.assertEqual(self.plotter.ax.get_xlabel(), "$()$") 104 self.assertEqual(self.plotter.ax.get_ylabel(), "$()$") 105 106 self.plotter.xyTransform(xLabel="x^(2)", yLabel="1/y") 107 self.assertEqual(self.plotter.ax.get_xlabel(), "$^{2}(()^{2})$") 108 self.assertEqual(self.plotter.ax.get_ylabel(), "$1/(()^{-1})$") 109 110 self.plotter.xyTransform(xLabel="x^(4)", yLabel="ln(y)") 111 self.assertEqual(self.plotter.ax.get_xlabel(), "$^{4}(()^{4})$") 104 112 self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{()}()$") 105 113 106 self.plotter.xyTransform(xLabel="ln(x)", yLabel=" ln(y)")114 self.plotter.xyTransform(xLabel="ln(x)", yLabel="y^(2)") 107 115 self.assertEqual(self.plotter.ax.get_xlabel(), "$\\ln{()}()$") 108 self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ln{()}()$")116 self.assertEqual(self.plotter.ax.get_ylabel(), "$^{2}(()^{2})$") 109 117 110 self.plotter.xyTransform(xLabel="x^(2)", yLabel="1/sqrt(y)") 111 self.assertEqual(self.plotter.ax.get_xlabel(), "$^{2}(()^{2})$") 118 self.plotter.xyTransform(xLabel="log10(x)", yLabel="y*x^(2)") 119 self.assertEqual(self.plotter.ax.get_xlabel(), "$()$") 120 self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{2}(()^{2})$") 121 122 self.plotter.xyTransform(xLabel="log10(x^(4))", yLabel="y*x^(4)") 123 self.assertEqual(self.plotter.ax.get_xlabel(), "$^{4}(()^{4})$") 124 self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{4}(()^{16})$") 125 126 self.plotter.xyTransform(xLabel="x", yLabel="1/sqrt(y)") 112 127 self.assertEqual(self.plotter.ax.get_ylabel(), "$1/\\sqrt{}(()^{-0.5})$") 128 129 self.plotter.xyTransform(xLabel="x", yLabel="log10(y)") 130 self.assertEqual(self.plotter.ax.get_ylabel(), "$()$") 131 132 self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x)") 133 self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{( \\ \\ )}()$") 134 135 self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x^(2))") 136 self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln ( \\ \\ ^{2})(()^{2})$") 137 138 self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x^(4))") 139 self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln ( \\ \\ ^{4})(()^{4})$") 140 141 self.plotter.xyTransform(xLabel="x", yLabel="log10(y*x^(4))") 142 self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{4}(()^{4})$") 113 143 114 144 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.