Changeset 822f97e in sasview for park_integration
- Timestamp:
- Sep 26, 2008 9:45:56 AM (16 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:
- 925155f
- Parents:
- 6aa47df
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/test/test_fit_cylinder.py
r916a15f r822f97e 7 7 from sans.fit.AbstractFitEngine import Data, Model 8 8 import math 9 from sans.fit.Fitting import Fit 10 from DataLoader.loader import Loader 11 9 12 class testFitModule(unittest.TestCase): 10 13 """ test fitting """ 11 def test1(self): 12 """ Fit 1 data (cyl_testdata.txt)and 1 model(CylinderModel) """ 13 #load data 14 from sans.fit.Loader import Load 15 load = Load() 16 load.set_filename("cyl_testdata.txt") 17 load.set_values() 18 data1 = Data1D(x=[], y=[],dx=None, dy=None) 19 load.load_data(data1) 20 #Importing the Fit module 21 from sans.fit.Fitting import Fit 14 15 def test_scipy(self): 16 """ Simple cylinder model fit (scipy) """ 17 18 out=Loader().load("cyl_400_20.txt") 19 data1 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 20 22 21 fitter = Fit('scipy') 23 22 # Receives the type of model for the fitting 24 23 from sans.models.CylinderModel import CylinderModel 25 24 model1 = CylinderModel() 26 model1.setParam('contrast', 1)27 data = Data(sans_data=data1 25 model1.setParam('contrast', 1) 26 data = Data(sans_data=data1) 28 27 model = Model(model1) 29 28 30 29 pars1 =['length','radius','scale'] 31 30 fitter.set_data(data,1) 32 model.model.setParam('scale',1 0)31 model.model.setParam('scale',1e-10) 33 32 fitter.set_model(model,1,pars1) 34 33 result1 = fitter.fit() 35 print "test scipy result:",result1.stderr,result1.pvec,result1.fitness34 36 35 self.assert_(result1) 37 36 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) 38 37 self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0) 39 self.assertAlmostEquals( result1.pvec[0],0 ) 40 self.assertAlmostEquals( result1.pvec[1],3*math.pow(10,-6) ) 41 self.assertAlmostEquals( result1.pvec[2] , 1 ) 42 self.assertAlmostEquals( result1.pvec[3] , 1 ) 43 self.assertAlmostEquals( result1.pvec[4] , 400 ) 44 self.assertAlmostEquals( result1.pvec[5] , 20 ) 45 self.assertAlmostEquals ( result1.pvec[6] , 1 ) 46 self.assertTrue( result1.fitness/43 < 2 ) 38 39 self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) 40 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) 41 self.assertTrue( math.fabs(result1.pvec[2]-9.0e-12)/3.0 < result1.stderr[2] ) 42 self.assertTrue( result1.fitness < 1.0 ) 43 44 def test_park(self): 45 """ Simple cylinder model fit (park) """ 46 47 out=Loader().load("cyl_400_20.txt") 48 data1 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 49 50 fitter = Fit('park') 51 # Receives the type of model for the fitting 52 from sans.models.CylinderModel import CylinderModel 53 model1 = CylinderModel() 54 model1.setParam('contrast', 1) 55 data = Data(sans_data=data1) 56 model = Model(model1) 57 58 pars1 =['length','radius','scale'] 59 fitter.set_data(data,1) 60 model.model.setParam('scale',1e-10) 61 fitter.set_model(model,1,pars1) 62 result1 = fitter.fit() 63 64 self.assert_(result1) 65 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) 66 self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0) 67 68 print result1.pvec[0]-400.0, result1.pvec[0] 69 print math.fabs(result1.pvec[0]-400.0)/3.0 70 self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) 71 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) 72 self.assertTrue( math.fabs(result1.pvec[2]-9.0e-12)/3.0 < result1.stderr[2] ) 73 self.assertTrue( result1.fitness < 1.0 ) 74 75 def test_park2(self): 76 """ Simultaneous cylinder model fit (park) """ 77 78 out=Loader().load("cyl_400_20.txt") 79 data1 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 80 81 out2=Loader().load("cyl_400_40.txt") 82 data2 = Data1D(x=out2.x, y=out2.y, dx=out2.dx, dy=out2.y) 83 84 fitter = Fit('park') 85 # Receives the type of model for the fitting 86 from sans.models.CylinderModel import CylinderModel 87 cyl1 = CylinderModel() 88 cyl1.name = "C1" 89 cyl1.setParam('contrast', 1) 90 cyl1.setParam('scale', 1e-10) 91 data1 = Data(sans_data=data1) 92 model1 = Model(cyl1) 93 fitter.set_data(data1,1) 94 fitter.set_model(model1, 1, ['length','radius','scale']) 95 96 cyl2 = CylinderModel() 97 cyl2.name = "C2" 98 cyl2.setParam('contrast', 1) 99 cyl2.setParam('scale', 1e-10) 100 data2 = Data(sans_data=data2) 101 # This is wrong. We should not store string as 102 # parameter values 103 # Why not inherit our AbstracFitEngine.Model from Park.Model? 104 105 #cyl2.setParam('length', 'C1.length') 106 #print "read back:", cyl2.getParam('length') 107 108 model2 = Model(cyl2) 109 model2.set(length='C1.length') 110 111 fitter.set_data(data2,2) 112 fitter.set_model(model2, 2, ['radius','scale']) 113 114 result1 = fitter.fit() 115 116 self.assert_(result1) 117 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) 118 self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0) 119 120 for par in result1.parameters: 121 if par.name=='C1.length': 122 print par.name, par.value 123 self.assertTrue( math.fabs(par.value-400.0)/3.0 < par.stderr ) 124 elif par.name=='C1.radius': 125 print par.name, par.value 126 self.assertTrue( math.fabs(par.value-20.0)/3.0 < par.stderr ) 127 elif par.name=='C2.radius': 128 print par.name, par.value 129 self.assertTrue( math.fabs(par.value-40.0)/3.0 < par.stderr ) 130 elif par.name=='C1.scale': 131 print par.name, par.value 132 self.assertTrue( math.fabs(par.value-9.0e-12)/3.0 < par.stderr ) 133 elif par.name=='C2.scale': 134 print par.name, par.value 135 self.assertTrue( math.fabs(par.value-9.0e-12)/3.0 < par.stderr ) 136 47 137 48 138
Note: See TracChangeset
for help on using the changeset viewer.