Changeset 6fd4e36 in sasview for src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingUtilitiesTest.py
- Timestamp:
- Mar 28, 2017 8:53:29 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:
- 0268aed
- Parents:
- a9b568c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingUtilitiesTest.py
rb1e36a3 r6fd4e36 3 3 from PyQt4 import QtGui 4 4 5 from sas.sasgui.guiframe.dataFitting import Data1D 6 from sas.sasgui.guiframe.dataFitting import Data2D 7 5 8 from UnitTesting.TestUtils import WarningTestNotImplemented 6 #from sasmodels.sasview_model import load_standard_models 9 7 10 from sasmodels import generate 8 11 from sasmodels import modelinfo … … 180 183 self.assertEqual(model.item(1).child(0).child(0,1).text(), "40.0") 181 184 185 def testCalculate1DChi2(self): 186 """ 187 Test the chi2 calculator for Data1D 188 """ 189 reference_data = Data1D(x=[0.1, 0.2], y=[0.0, 0.0]) 190 191 # 1. identical data 192 current_data = Data1D(x=[0.1, 0.2], y=[0.0, 0.0]) 193 194 chi = FittingUtilities.calculateChi2(reference_data, current_data) 195 196 # Should be zero 197 self.assertAlmostEqual(chi, 0.0, 8) 198 199 # 2. far data 200 current_data = Data1D(x=[0.1, 0.2], y=[200.0, 150.0]) 201 202 chi = FittingUtilities.calculateChi2(reference_data, current_data) 203 204 # Should not be zero 205 self.assertAlmostEqual(chi, 31250.0, 8) 206 207 # 3. Wrong data 208 current_data = Data1D(x=[0.1, 0.2], y=[200.0, 150.0, 200.0]) 209 chi = FittingUtilities.calculateChi2(reference_data, current_data) 210 # Should be None 211 self.assertIsNone(chi) 212 213 def testCalculate2DChi2(self): 214 """ 215 Test the chi2 calculator for Data2D 216 """ 217 reference_data = Data2D(image=[1.0, 2.0, 3.0], 218 err_image=[0.01, 0.02, 0.03], 219 qx_data=[0.1, 0.2, 0.3], 220 qy_data=[0.1, 0.2, 0.3]) 221 222 # 1. identical data 223 current_data = Data2D(image=[1.0, 2.0, 3.0], 224 err_image=[0.01, 0.02, 0.03], 225 qx_data=[0.1, 0.2, 0.3], 226 qy_data=[0.1, 0.2, 0.3]) 227 228 chi = FittingUtilities.calculateChi2(reference_data, current_data) 229 230 # Should be zero 231 self.assertAlmostEqual(chi, 0.0, 8) 232 233 # 2. far data 234 current_data = Data2D(image=[100.0, 200.0, 300.0], 235 err_image=[1.01, 2.02, 3.03], 236 qx_data=[0.1, 0.2, 0.3], 237 qy_data=[100.0, 200., 300.]) 238 239 chi = FittingUtilities.calculateChi2(reference_data, current_data) 240 241 # Should not be zero 242 self.assertAlmostEqual(chi, 9607.88, 2) 243 244 # 3. Wrong data 245 current_data = Data2D(image=[1.0, 2.0, 3.0], 246 err_image=[0.01, 0.02], 247 qx_data=[0.1, 0.2], 248 qy_data=[0.1, 0.2, 0.3]) 249 # Should throw 250 with self.assertRaises(ValueError): 251 chi = FittingUtilities.calculateChi2(reference_data, current_data) 252 182 253 if __name__ == "__main__": 183 254 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.