- Timestamp:
- Dec 14, 2016 2:19:57 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:
- ab9984e
- Parents:
- 3a0ce4f
- Location:
- src/sas/qtgui
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/SlitSizeCalculator.py
r3a0ce4f rdebf5c3 3 3 from UI.SlitSizeCalculator import Ui_SlitSizeCalculator 4 4 from sas.sascalc.dataloader.loader import Loader 5 from sas.sasgui.guiframe.dataFitting import Data1D6 from sas.sasgui.guiframe.dataFitting import Data2D7 5 from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator 8 6 … … 11 9 12 10 class SlitSizeCalculator(QtGui.QDialog, Ui_SlitSizeCalculator): 11 """ 12 Provides the slit length calculator GUI. 13 """ 13 14 def __init__(self, parent=None): 14 15 super(SlitSizeCalculator, self).__init__() … … 31 32 def onHelp(self): 32 33 """ 33 Bring up the Kiessig fringecalculator Documentation whenever34 Bring up the Slit Size Calculator calculator Documentation whenever 34 35 the HELP button is clicked. 35 36 Calls DocumentationWindow with the path of the location within the … … 48 49 def onBrowse(self): 49 50 """ 50 Execute the computation of thickness51 Browse the file and calculate slit lenght upon loading 51 52 """ 52 53 path_str = self.chooseFile() … … 57 58 58 59 self.data_file.setText(os.path.basename(path_str)) 59 #We are loading data for one model only therefor index 060 60 self.calculateSlitSize(data) 61 61 … … 70 70 "SAXSess 1D data (*.txt *.TXT *.dat *.DAT)", None, 71 71 QtGui.QFileDialog.DontUseNativeDialog) 72 72 73 if path is None: 73 74 return … … 86 87 def calculateSlitSize(self, data=None): 87 88 """ 88 Complete the loading and compute the slit size89 Computes slit lenght from given 1D data 89 90 """ 90 91 … … 93 94 raise RuntimeError, msg 94 95 95 if isinstance(data, Data2D) ordata.__class__.__name__ == 'Data2D':96 if data.__class__.__name__ == 'Data2D': 96 97 msg = "Slit Length cannot be computed for 2D Data" 97 98 raise Exception, msg … … 101 102 x = data.x 102 103 y = data.y 103 if x == [] or 104 if x == [] or x is None or y == [] or y is None: 104 105 msg = "The current data is empty please check x and y" 105 106 raise ValueError, msg … … 113 114 slit_length_str = "{:.5f}".format(slit_length) 114 115 self.slit_length_out.setText(slit_length_str) 115 #Display unit 116 117 #Display unit, which most likely needs to be 1/Ang but needs to be confirmed 116 118 self.unit_out.setText("[Unknown]") 117 119 -
src/sas/qtgui/UnitTesting/SlitSizeCalculatorTest.py
r3a0ce4f rdebf5c3 38 38 self.widget.onHelp() 39 39 40 def testCalculateSlitSize(self):41 """ User entered compound calculations and subsequent reset"""42 43 filename = "beam_profile.DAT"44 loader = Loader()45 data = loader.load(filename)46 47 self.widget.calculateSlitSize(data)48 # The value "5.5858" was obtained by manual calculation.49 # It turns out our slit length is FWHM/250 self.assertAlmostEqual(float(self.widget.slit_length_out.text()), 5.5858/2, 3)51 52 def testCalculateSlitSize2D(self):53 """ User entered compound calculations and subsequent reset"""54 55 #TODO: Test for 2D and check if exception is being raised56 filename = "beam_profile.DAT"57 loader = Loader()58 data = loader.load(filename)59 60 self.widget.calculateSlitSize(data)61 # The value "5.5858" was obtained by manual calculation.62 # It turns out our slit length is FWHM/263 self.assertAlmostEqual(float(self.widget.slit_length_out.text()), 5.5858/2, 3)64 65 # def testDataEntryNumbers(self):66 # """ User entered compound calculations and subsequent reset"""67 #68 # self.widget.data_file.clear()69 # self.widget.data_file.insert("beam profile.DAT")70 # #71 # # Push Compute with the left mouse button72 # computeButton = self.widget.computeButton73 # QTest.mouseClick(computeButton, Qt.LeftButton)74 # self.assertEqual(self.widget.lengthscale_out.text(), '6.283')75 76 40 def testBrowseButton(self): 77 41 browseButton = self.widget.browseButton … … 100 64 QtGui.QFileDialog.getOpenFileName.assert_called_once() 101 65 102 # def testDataEntryNumbers(self): 103 # """ User entered compound calculations and subsequent reset""" 104 # 105 # self.widget.data_file.clear() 106 # self.widget.data_file.insert("beam profile.DAT") 107 # # 108 # # Push Compute with the left mouse button 109 # computeButton = self.widget.computeButton 110 # QTest.mouseClick(computeButton, Qt.LeftButton) 111 # self.assertEqual(self.widget.lengthscale_out.text(), '6.283') 112 # 113 # 114 # def testComplexEntryLetters(self): 115 # """ User entered compound calculations and subsequent reset""" 116 # 117 # self.widget.deltaq_in.insert("xyz") 118 # 119 # # Push Compute with the left mouse button 120 # computeButton = self.widget.computeButton 121 # QTest.mouseClick(computeButton, Qt.LeftButton) 122 # self.assertEqual(self.widget.lengthscale_out.text(), '') 66 67 def testCalculateSlitSize(self): 68 """ Test slit size calculated value """ 69 70 filename = "beam_profile.DAT" 71 loader = Loader() 72 data = loader.load(filename) 73 74 self.widget.calculateSlitSize(data) 75 # The value "5.5858" was obtained by manual calculation. 76 # It turns out our slit length is FWHM/2 77 self.assertAlmostEqual(float(self.widget.slit_length_out.text()), 5.5858/2, 3) 78 79 def testWrongInput(self): 80 """ Test on wrong input data """ 81 82 filename = "Dec07031.ASC" 83 loader = Loader() 84 data = loader.load(filename) 85 self.assertRaisesRegexp(Exception, 86 "Slit Length cannot be computed for 2D Data", 87 self.widget.calculateSlitSize, data) 88 89 filename = "empty_file.txt" 90 loader = Loader() 91 data = loader.load(filename) 92 self.assertRaisesRegexp(RuntimeError, 93 "ERROR: Data hasn't been loaded correctly", 94 self.widget.calculateSlitSize, data) 95 96 data = None 97 self.assertRaisesRegexp(RuntimeError, 98 "ERROR: Data hasn't been loaded correctly", 99 self.widget.calculateSlitSize, data) 100 123 101 124 102 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.