Changeset 1584fff in sasview for sansmodels/src
- Timestamp:
- Feb 28, 2011 1:42:26 PM (14 years ago)
- Branches:
- master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 6bbeacd4
- Parents:
- 04eb1a4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/test/utest_smearing.py
rdfe820b r1584fff 10 10 #from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection 11 11 from sans.models.qsmearing import SlitSmearer, QSmearer, smear_selection 12 from sans.models.SphereModel import SphereModel 12 13 import os.path 13 14 from time import time 14 15 class smear_tests(unittest.TestCase): 15 16 … … 91 92 self.assertAlmostEqual(answer[i], output[i], 2) 92 93 93 94 class smear_test_1Dpinhole(unittest.TestCase): 95 96 def setUp(self): 97 # NIST sample data 98 self.data = Loader().load("CMSphere5.txt") 99 # NIST smeared sphere w/ param values below 100 self.answer = Loader().load("CMSphere5smearsphere.txt") 101 # call spheremodel 102 self.model = SphereModel() 103 # setparams consistent with Igor default 104 self.model.setParam('scale', 1.0) 105 self.model.setParam('background', 0.01) 106 self.model.setParam('radius', 60.0) 107 self.model.setParam('sldSolv', 6.3e-06) 108 self.model.setParam('sldSph', 1.0e-06) 109 110 def test_q(self): 111 """ 112 Compare Pinhole resolution smearing with NIST 113 """ 114 # x values 115 input = numpy.zeros(len(self.data.x)) 116 # set time 117 st1 = time() 118 # cal I w/o smear 119 input = self.model.evalDistribution(self.data.x) 120 # Cal_smear (first call) 121 for i in range(1000): 122 s = QSmearer(self.data, self.model) 123 # stop and record time taken 124 first_call_time = time()-st1 125 # set new time 126 st = time() 127 # cal I w/o smear (this is not neccessary to call but just to be fare 128 input = self.model.evalDistribution(self.data.x) 129 # smear cal (after first call done above) 130 for i in range(1000): 131 output = s(input) 132 # record time taken 133 last_call_time = time()-st 134 # compare the ratio of ((NIST_answer-SsanView_answer)/NIST_answer) 135 # If the ratio less than 1%, pass the test 136 for i in range(len(self.data.x)): 137 ratio = math.fabs((self.answer.y[i]-output[i])/self.answer.y[i]) 138 if ratio > 0.006: 139 ratio = 0.006 140 self.assertEqual(math.fabs((self.answer.y[i]-output[i])/ \ 141 self.answer.y[i]), ratio) 142 # print 143 print "\n NIST_time = 10sec:" 144 print "Cal_time(1000 times of first_calls; ) = ", first_call_time 145 print "Cal_time(1000 times of calls) = ", last_call_time 146 94 147 if __name__ == '__main__': 95 148 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.