Changeset 76f132a in sasview for test/park_integration
- Timestamp:
- May 8, 2014 4:19:29 PM (11 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:
- e3efa6b3
- Parents:
- 8d074d9
- Location:
- test/park_integration/test
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
test/park_integration/test/utest_fit_line.py
r95d58d3 r76f132a 30 30 except ValueError,exc: 31 31 #print "ValueError was correctly raised: "+str(msg) 32 assert str(exc).startswith(' wrong parameter')32 assert str(exc).startswith('parameter param1') 33 33 else: 34 34 raise AssertionError("No error raised for scipy fitting with wrong parameters name to fit") … … 54 54 # The target values were generated from the following statements 55 55 p,s,fx = result1.pvec, result1.stderr, result1.fitness 56 #print "p0,p1,s0,s1,fx _= %g, %g, %g, %g, %g"%(p[0],p[1],s[0],s[1],fx)56 #print "p0,p1,s0,s1,fx = %g, %g, %g, %g, %g"%(p[0],p[1],s[0],s[1],fx) 57 57 p0,p1,s0,s1,fx_ = 3.68353, 2.61004, 0.336186, 0.105244, 1.20189 58 58 … … 65 65 self.assertTrue( abs(p[0]-p0) <= 1e-5 ) 66 66 self.assertTrue( abs(p[1]-p1) <= 1e-5 ) 67 self.assertTrue( abs(fx-fx_) <= 1e- 2)67 self.assertTrue( abs(fx-fx_) <= 1e-5 ) 68 68 69 69 def fit_bumps(self, alg, **opts): -
test/park_integration/test/utest_fit_smeared.py
r6c00702 r76f132a 21 21 out=Loader().load("cyl_400_20.txt") 22 22 # This data file has not error, add them 23 out.dy = out.y23 #out.dy = out.y 24 24 25 25 fitter = Fit('scipy') … … 28 28 # Receives the type of model for the fitting 29 29 model1 = CylinderModel() 30 model1.setParam('sldCyl', 3.0e-6) 31 model1.setParam('sldSolv', 0.0) 30 model1.setParam("scale", 1.0) 31 model1.setParam("radius",18) 32 model1.setParam("length", 397) 33 model1.setParam("sldCyl",3e-006 ) 34 model1.setParam("sldSolv",0.0 ) 35 model1.setParam("background", 0.0) 32 36 model = Model(model1) 33 model.set(scale=1e-10)34 37 pars1 =['length','radius','scale'] 35 38 fitter.set_model(model,1,pars1) … … 38 41 fitter.select_problem_for_fit(id=1,value=1) 39 42 result1, = fitter.fit() 40 43 #print "result1",result1 44 41 45 self.assert_(result1) 42 self.assertTrue(len(result1.pvec) >0 or len(result1.pvec)==0)43 self.assertTrue(len(result1.stderr) > 0 or len(result1.stderr)==0)46 self.assertTrue(len(result1.pvec) > 0) 47 self.assertTrue(len(result1.stderr) > 0) 44 48 45 49 self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) 46 50 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) 47 self.assertTrue( math.fabs(result1.pvec[2]- 9.0e-12)/3.0 < result1.stderr[2] )51 self.assertTrue( math.fabs(result1.pvec[2]-1)/3.0 < result1.stderr[2] ) 48 52 self.assertTrue( result1.fitness < 1.0 ) 49 53 54 def test_park_dispersion(self): 55 """ 56 Cylinder fit with dispersion 57 """ 58 self._dispersion(fitter = Fit('park')) 59 60 def test_bumps_dispersion(self): 61 """ 62 Cylinder fit with dispersion 63 """ 64 alg = 'amoeba' 65 from bumps import fitters 66 fitters.FIT_DEFAULT = alg 67 #fitters.FIT_OPTIONS[alg].options.update(opts) 68 fitters.FIT_OPTIONS[alg].options.update(monitors=[]) 69 self._dispersion(fitter = Fit('bumps')) 70 50 71 def test_scipy_dispersion(self): 51 72 """ 52 73 Cylinder fit with dispersion 53 74 """ 75 self._dispersion(fitter = Fit('scipy')) 76 77 def _dispersion(self, fitter): 54 78 # Load data 55 79 # This data is for a cylinder with … … 60 84 out.dy[i] = math.sqrt(out.y[i]) 61 85 62 # Set up the fit63 fitter = Fit('scipy')64 86 # Receives the type of model for the fitting 65 87 model1 = CylinderModel() 66 model1.setParam('sldCyl', 3.0e-6) 67 model1.setParam('sldSolv', 0.0) 88 model1.setParam("scale", 10.0) 89 model1.setParam("radius",18) 90 model1.setParam("length", 397) 91 model1.setParam("sldCyl",3e-006 ) 92 model1.setParam("sldSolv",0.0 ) 93 model1.setParam("background", 0.0) 68 94 69 95 # Dispersion parameters 70 model1.dispersion['radius']['width'] = 0. 00171 model1.dispersion['radius']['npts'] = 50 72 96 model1.dispersion['radius']['width'] = 0.25 97 model1.dispersion['radius']['npts'] = 50 98 73 99 model = Model(model1) 74 100 75 101 pars1 =['length','radius','scale','radius.width'] 76 102 fitter.set_data(out,1) 77 model.set(scale=1e-10)78 103 fitter.set_model(model,1,pars1) 79 104 fitter.select_problem_for_fit(id=1,value=1) … … 81 106 82 107 self.assert_(result1) 83 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0)84 self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0)85 86 self.assertTrue( math.fabs(result1.pvec[0]- 400.0)/3.0 < result1.stderr[0] )87 self.assertTrue( math.fabs(result1.pvec[1]- 20.0)/3.0 < result1.stderr[1] )88 self.assertTrue( math.fabs(result1.pvec[2]-1 .0e-10)/3.0 < result1.stderr[2] )89 self.assertTrue( math.fabs(result1.pvec[3]- 5.0)/3.0 < result1.stderr[3] )108 self.assertTrue(len(result1.pvec)>0) 109 self.assertTrue(len(result1.stderr)>0) 110 111 self.assertTrue( math.fabs(result1.pvec[0]-399.8)/3.0 < result1.stderr[0] ) 112 self.assertTrue( math.fabs(result1.pvec[1]-17.5)/3.0 < result1.stderr[1] ) 113 self.assertTrue( math.fabs(result1.pvec[2]-11.1)/3.0 < result1.stderr[2] ) 114 self.assertTrue( math.fabs(result1.pvec[3]-0.276)/3.0 < result1.stderr[3] ) 90 115 self.assertTrue( result1.fitness < 1.0 ) 91 116 … … 98 123 """ 99 124 def setUp(self): 100 print "TEST DONE WITHOUT PROPER OUTPUT CHECK:"101 print " ---> TEST NEEDS TO BE COMPLETED"102 125 data = Loader().load("latex_smeared.xml") 103 126 self.data_res = data[0] … … 105 128 106 129 self.sphere = SphereModel() 130 self.sphere.setParam('background', 0) 107 131 self.sphere.setParam('radius', 5000.0) 108 self.sphere.setParam('scale', 1.0e-13) 109 self.sphere.setParam('radius.npts', 30) 110 self.sphere.setParam('radius.width',500) 111 132 self.sphere.setParam('scale', 0.4) 133 self.sphere.setParam('sldSolv',0) 134 self.sphere.setParam('sldSph',1e-6) 135 #self.sphere.setParam('radius.npts', 30) 136 #self.sphere.setParam('radius.width',50) 137 112 138 def test_reso(self): 113 139 … … 125 151 fitter.set_data(self.data_res,1) 126 152 fitter._engine.fit_arrange_dict[1].data_list[0].smearer = smear 127 print "smear ",smear 153 128 154 # Model: maybe there's a better way to do this. 129 155 # Ideally we should have to create a new model from our sans model. 130 fitter.set_model(Model(self.sphere),1, ['radius','scale' ])156 fitter.set_model(Model(self.sphere),1, ['radius','scale', 'background']) 131 157 132 158 # Why do we have to do this...? 133 159 fitter.select_problem_for_fit(id=1,value=1) 134 160 135 161 # Perform the fit (might take a while) 136 162 result1, = fitter.fit() 137 163 138 # Replace this with proper test once we know what the 139 # result should be 140 print result1.pvec 141 print result1.stderr 142 164 #print "v",result1.pvec 165 #print "dv",result1.stderr 166 #print "chisq(v)",result1.fitness 167 168 self.assertTrue( math.fabs(result1.pvec[0]-5000) < 20 ) 169 self.assertTrue( math.fabs(result1.pvec[1]-0.48) < 0.02 ) 170 self.assertTrue( math.fabs(result1.pvec[2]-0.060) < 0.002 ) 171 172 143 173 def test_slit(self): 144 174 smear = smear_selection(self.data_slit) 145 175 self.assertEqual(smear.__class__.__name__, 'SlitSmearer') 146 176 147 # Fit148 177 fitter = Fit('scipy') 149 178 … … 161 190 result1, = fitter.fit() 162 191 163 # Replace this with proper test once we know what the164 # result should be165 print result1.pvec166 print result1.stderr167 168 169 192 #print "v",result1.pvec 193 #print "dv",result1.stderr 194 #print "chisq(v)",result1.fitness 195 196 self.assertTrue( math.fabs(result1.pvec[0]-2340) < 20 ) 197 self.assertTrue( math.fabs(result1.pvec[1]-0.010) < 0.002 ) 198 170 199 if __name__ == '__main__': 171 200 unittest.main() -
test/park_integration/test/utest_small_test.py
r4de1fed r76f132a 27 27 fitter.select_problem_for_fit(id=1,value=1) 28 28 result1, = fitter.fit() 29 29 #print result1 30 #print result1.__dict__ 31 30 32 self.assert_(result1) 31 33 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 )
Note: See TracChangeset
for help on using the changeset viewer.