Changeset 39551a68 in sasview for src/sas/qtgui
- Timestamp:
- Aug 1, 2016 7:47:16 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:
- 1af348e
- Parents:
- 28a84e9
- Location:
- src/sas/qtgui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/DataExplorer.py
r28a84e9 r39551a68 689 689 def quickDataPlot(self): 690 690 """ 691 """ 692 print "quickDataPlot" 693 pass 691 Frozen plot - display an image of the plot 692 """ 693 index = self.treeView.selectedIndexes()[0] 694 model_item = self.model.itemFromIndex(self.data_proxy.mapToSource(index)) 695 data = model_item.child(0).data().toPyObject() 696 697 dimension = 1 if isinstance(data, Data1D) else 2 698 699 # TODO: Replace this with the proper MaskPlotPanel from plottools 700 new_plot = Plotter(self) 701 new_plot.data(data) 702 new_plot.plot(marker='o', linestyle='') 703 704 # Update the global plot counter 705 title = "Plot " + data.name 706 new_plot.setWindowTitle(title) 707 708 # Show the plot 709 new_plot.show() 694 710 695 711 def quickData3DPlot(self): -
src/sas/qtgui/GuiUtils.py
r28a84e9 r39551a68 388 388 def retrieveData2d(data): 389 389 """ 390 Retrieve 1D data from file and construct its text390 Retrieve 2D data from file and construct its text 391 391 representation 392 392 """ 393 if not isinstance(data, Data2D): 394 msg = "Incorrect type passed to retrieveData2d" 395 raise AttributeError, msg 396 393 397 text = data.__str__() 394 398 text += 'Data Min Max:\n' … … 428 432 return text 429 433 430 def _onTXTSave(data, path):434 def onTXTSave(data, path): 431 435 """ 432 436 Save file as formatted txt … … 499 503 loader = Loader() 500 504 if os.path.splitext(filename)[1].lower() == ".txt": 501 _onTXTSave(data, filename)505 onTXTSave(data, filename) 502 506 if os.path.splitext(filename)[1].lower() == ".xml": 503 507 loader.save(filename, data, ".xml") -
src/sas/qtgui/Plotter.py
r8cb6cd6 r39551a68 78 78 self._ax = self.figure.add_subplot(self._current_plot) 79 79 80 def plot(self ):80 def plot(self, marker=None, linestyle=None): 81 81 """ 82 82 Plot self._data … … 85 85 ax = self._ax 86 86 87 if marker == None: 88 marker = '*' 89 90 if linestyle == None: 91 linestyle = '-' 92 87 93 # plot data with legend 88 ax.plot(self._data.x, self._data.y, '*-', label=self._title)94 ax.plot(self._data.x, self._data.y, marker=marker, linestyle=linestyle, label=self._title) 89 95 90 96 # Now add the legend with some customizations. -
src/sas/qtgui/UnitTesting/DataExplorerTest.py
r28a84e9 r39551a68 723 723 QFileDialog.getSaveFileName.assert_called_once() 724 724 725 def testQuickDataPlot(self): 726 """ 727 Quick data plot generation. 728 729 TODO: add content once plotting finalized 730 """ 731 pass 725 732 726 733 if __name__ == "__main__": -
src/sas/qtgui/UnitTesting/GuiUtilsTest.py
r28a84e9 r39551a68 10 10 from sas.sascalc.dataloader.loader import Loader 11 11 from sas.sasgui.guiframe.data_manager import DataManager 12 from sas.sasgui.guiframe.dataFitting import Data1D 13 from sas.sasgui.guiframe.dataFitting import Data2D 12 14 13 15 # Tested module 14 16 from GuiUtils import * 15 17 16 class FakeData(object): 17 '''Data1D/2D object for testing''' 18 def __init__(self): 19 self.x = [] 20 self.y = [] 18 app = QtGui.QApplication(sys.argv) 21 19 22 20 class GuiUtilsTest(unittest.TestCase): … … 198 196 """ 199 197 """ 200 self.assertRaises(retrieveData1d("BOOP")) 201 202 # data = FakeData() 203 pass 198 with self.assertRaises(AttributeError): 199 retrieveData1d("BOOP") 200 201 data = Data1D() 202 with self.assertRaises(ValueError): 203 retrieveData1d(data) 204 205 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0]) 206 207 text = retrieveData1d(data) 208 209 self.assertIn("Temperature:", text) 210 self.assertIn("Beam_size:", text) 211 self.assertIn("X_min = 1.0: X_max = 3.0", text) 212 self.assertIn("3.0 \t12.0 \t0.0 \t0.0", text) 204 213 205 214 def testRetrieveData2d(self): 206 215 """ 207 216 """ 208 pass 217 with self.assertRaises(AttributeError): 218 retrieveData2d("BOOP") 219 data = Data2D(image=[1.0, 2.0, 3.0], 220 err_image=[0.01, 0.02, 0.03], 221 qx_data=[0.1, 0.2, 0.3], 222 qy_data=[0.1, 0.2, 0.3]) 223 224 text = retrieveData2d(data) 225 226 self.assertIn("Type: Data2D", text) 227 self.assertIn("I_min = 1.0", text) 228 self.assertIn("I_max = 3.0", text) 229 self.assertIn("2 \t0.3 \t0.3 \t3.0 \t0.03 \t0.0 \t0.0", text) 209 230 210 231 def testOnTXTSave(self): 211 232 """ 212 """ 213 pass 233 Test the file writer for saving 1d/2d data 234 """ 235 path = "test123" 236 if os.path.isfile(path): 237 os.remove(path) 238 239 # Broken data 240 data = Data1D(x=[1.0, 2.0, 3.0], y=[]) 241 # Expect a raise 242 with self.assertRaises(IndexError): 243 onTXTSave(data, path) 244 245 # Good data - no dX/dY 246 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0]) 247 onTXTSave(data, path) 248 249 self.assertTrue(os.path.isfile(path)) 250 with open(path,'r') as out: 251 data_read = out.read() 252 self.assertEqual("<X> <Y>\n1 10\n2 11\n3 12\n", data_read) 253 254 if os.path.isfile(path): 255 os.remove(path) 256 257 # Good data - with dX/dY 258 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0], 259 dx=[0.1, 0.2, 0.3], dy=[0.1, 0.2, 0.3]) 260 261 onTXTSave(data, path) 262 with open(path,'r') as out: 263 data_read = out.read() 264 self.assertIn("<X> <Y> <dY> <dX>\n", data_read) 265 self.assertIn("1 10 0.1 0.1\n", data_read) 266 self.assertIn("2 11 0.2 0.2\n", data_read) 267 self.assertIn("3 12 0.3 0.3\n", data_read) 268 269 if os.path.isfile(path): 270 os.remove(path) 214 271 215 272 def testSaveData1D(self): 216 273 """ 217 """ 218 pass 274 Test the 1D file save method 275 """ 276 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0], 277 dx=[0.1, 0.2, 0.3], dy=[0.1, 0.2, 0.3]) 278 279 # Test the .txt format 280 file_name = "test123_out.txt" 281 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 282 data.filename = "test123.txt" 283 saveData1D(data) 284 self.assertTrue(os.path.isfile(file_name)) 285 os.remove(file_name) 286 287 # Test the .xml format 288 file_name = "test123_out.xml" 289 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 290 data.filename = "test123.xml" 291 saveData1D(data) 292 self.assertTrue(os.path.isfile(file_name)) 293 os.remove(file_name) 294 295 # Test the wrong format 296 file_name = "test123_out.mp3" 297 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 298 data.filename = "test123.mp3" 299 saveData1D(data) 300 self.assertFalse(os.path.isfile(file_name)) 219 301 220 302 def testSaveData2D(self): 221 303 """ 222 """ 223 pass 304 Test the 1D file save method 305 """ 306 data = Data2D(image=[1.0, 2.0, 3.0], 307 err_image=[0.01, 0.02, 0.03], 308 qx_data=[0.1, 0.2, 0.3], 309 qy_data=[0.1, 0.2, 0.3]) 310 311 # Test the .txt format 312 file_name = "test123_out.dat" 313 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 314 data.filename = "test123.dat" 315 saveData2D(data) 316 self.assertTrue(os.path.isfile(file_name)) 317 os.remove(file_name) 318 319 # Test the wrong format 320 file_name = "test123_out.mp3" 321 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 322 data.filename = "test123.mp3" 323 saveData2D(data) 324 self.assertFalse(os.path.isfile(file_name)) 325 224 326 225 327 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.