Changeset 1e3169c in sasview for park_integration/test
- Timestamp:
- Oct 27, 2009 11:56:39 AM (15 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:
- b37f72f
- Parents:
- cc1500d
- Location:
- park_integration/test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/test/small_test.py
r1ea3488 r1e3169c 3 3 """ 4 4 import unittest 5 from danse.common.plottools.plottables import Theory1D 6 from danse.common.plottools.plottables import Data1D 7 from sans.fit.AbstractFitEngine import Model,FitData1D 5 from sans.fit.AbstractFitEngine import Model 8 6 import math 9 7 from sans.fit.Fitting import Fit … … 13 11 """ test fitting """ 14 12 def test_park(self): 15 """ Simple cylinder model fit ( park) """13 """ Simple cylinder model fit (scipy) """ 16 14 17 out=Loader().load("cyl_400_20.txt") 18 data1 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 19 15 out= Loader().load("cyl_400_20.txt") 16 20 17 fitter = Fit('scipy') 21 18 # Receives the type of model for the fitting … … 23 20 model1 = CylinderModel() 24 21 model1.setParam('contrast', 1) 25 data1.smearer = None26 data = FitData1D(data1)27 22 model = Model(model1) 28 23 29 24 pars1 =['length','radius','scale'] 30 fitter.set_data( data,1)25 fitter.set_data(out,1) 31 26 model.set( scale=1e-10 ) 32 27 fitter.set_model(model,1,pars1) -
park_integration/test/test_fit_cylinder.py
reb575b0 r1e3169c 5 5 import unittest 6 6 7 from danse.common.plottools.plottables import Data1D,Theory1D 8 from sans.fit.AbstractFitEngine import Model,FitData1D 7 from sans.fit.AbstractFitEngine import Model 9 8 import math 10 9 from sans.fit.Fitting import Fit … … 15 14 def setUp(self): 16 15 """ initialize data""" 17 out = Loader().load("cyl_400_20.txt") 18 #Create data that fitting engine understands 19 data1 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.dy) 20 self.data = FitData1D(data1) 16 self.data = Loader().load("cyl_400_20.txt") 21 17 # Create model that fitting engine understands 22 18 from sans.models.CylinderModel import CylinderModel … … 77 73 """ initialize data""" 78 74 79 out=Loader().load("cyl_400_20.txt") 80 data1 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.dy) 81 self.data1 = FitData1D(data1) 82 83 out2=Loader().load("cyl_400_40.txt") 84 data2 = Data1D(x=out2.x, y=out2.y, dx=out2.dx, dy=out2.dy) 85 self.data2 = FitData1D(data2) 75 self.data1=Loader().load("cyl_400_20.txt") 76 self.data2=Loader().load("cyl_400_40.txt") 86 77 87 78 # Receives the type of model for the fitting -
park_integration/test/test_fit_line.py
r2eaaf1a r1e3169c 5 5 import unittest 6 6 7 from danse.common.plottools.plottables import Data1D,Theory1D 8 from sans.fit.AbstractFitEngine import Model,FitData1D 7 from sans.fit.AbstractFitEngine import Model 9 8 import math 10 9 class testFitModule(unittest.TestCase): … … 15 14 #load data 16 15 from DataLoader.loader import Loader 17 data 1= Loader().load("testdata_line.txt")16 data = Loader().load("testdata_line.txt") 18 17 #Importing the Fit module 19 18 from sans.fit.Fitting import Fit … … 23 22 model1 = LineModel() 24 23 model1.name = "M1" 25 #data = Data(sans_data=data1 )26 #data1.smearer=None27 data = FitData1D(data1 )28 24 model = Model(model1) 29 25 #fit with scipy test … … 71 67 from DataLoader.loader import Loader 72 68 l = Loader() 73 out=l.load("testdata_line.txt")74 data11 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y)75 out=l.load("testdata_line1.txt")76 data22 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y)69 data1=l.load("testdata_line.txt") 70 71 data2=l.load("testdata_line1.txt") 72 77 73 #Importing the Fit module 78 74 from sans.fit.Fitting import Fit … … 84 80 model22 = LineModel() 85 81 model11.name= "M2" 86 data11.smearer=None 87 data22.smearer=None 88 data1 = FitData1D(data11 ) 89 data2 = FitData1D(data22 ) 90 82 91 83 model1 = Model(model11) 92 84 model2 = Model(model22) … … 124 116 self.assertTrue( math.fabs(result2.pvec[0]-4)/3 <= result2.stderr[0] ) 125 117 self.assertTrue( math.fabs(result2.pvec[1]-2.5)/3 <= result2.stderr[1] ) 126 self.assertTrue( result2.fitness/ len(data2.x) < 2)118 self.assertTrue( result2.fitness/(len(data1.x)+len(data2.x)) < 2) 127 119 128 120 … … 132 124 from DataLoader.loader import Loader 133 125 l = Loader() 134 out=l.load("testdata_line.txt") 135 data11 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 136 out=l.load("testdata_cst.txt") 137 data22 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 138 #Importing the Fit module 139 from sans.fit.Fitting import Fit 140 fitter = Fit('park') 141 # Receives the type of model for the fitting 142 from sans.models.LineModel import LineModel 143 from sans.models.Constant import Constant 126 data1= l.load("testdata_line.txt") 127 data2= l.load("testdata_cst.txt") 128 129 # Receives the type of model for the fitting 130 from sans.models.LineModel import LineModel 144 131 model11 = LineModel() 145 132 model11.name= "line" … … 147 134 model11.setParam("B",1.0) 148 135 136 from sans.models.Constant import Constant 149 137 model22 = Constant() 150 138 model22.name= "cst" 151 139 model22.setParam("value", 1.0) 152 140 153 # Constrain the constant value to be equal to parameter B (the real value is 2.5)154 155 data11.smearer= None156 data22.smearer= None157 data1 = FitData1D(data11 )158 data2 = FitData1D(data22 )159 141 model1 = Model(model11) 160 142 model2 = Model(model22) 161 143 model1.set(A=4) 162 144 model1.set(B=3) 145 # Constraint the constant value to be equal to parameter B (the real value is 2.5) 163 146 model2.set(value='line.B') 164 147 #fit with scipy test … … 166 149 pars2= ['value'] 167 150 151 #Importing the Fit module 152 from sans.fit.Fitting import Fit 153 fitter = Fit('park') 168 154 fitter.set_data(data1,1) 169 155 fitter.set_model(model1,1,pars1) … … 177 163 self.assertTrue( math.fabs(result2.pvec[0]-4.0)/3. <= result2.stderr[0]) 178 164 self.assertTrue( math.fabs(result2.pvec[1]-2.5)/3. <= result2.stderr[1]) 179 self.assertTrue( result2.fitness/ len(data2.x) < 2)165 self.assertTrue( result2.fitness/(len(data1.x)+len(data2.x)) < 2) 180 166 181 167 … … 185 171 from DataLoader.loader import Loader 186 172 l = Loader() 187 out=l.load("testdata_line.txt") 188 data11 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 189 out=l.load("testdata_line1.txt") 190 data22 = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.y) 191 #Importing the Fit module 192 from sans.fit.Fitting import Fit 193 fitter = Fit('scipy') 173 data1 = l.load("testdata_line.txt") 174 data2 = l.load("testdata_line1.txt") 175 176 194 177 # Receives the type of model for the fitting 195 178 from sans.models.LineModel import LineModel … … 199 182 model1.setParam("B",1.0) 200 183 model = Model(model1) 201 202 data11.smearer= None 203 data22.smearer= None 204 data1 = FitData1D(data11 ) 205 data2 = FitData1D(data22 ) 206 207 #fit with scipy test 208 pars1= ['A','B'] 184 185 #fit with scipy test 186 pars1= ['A','B'] 187 #Importing the Fit module 188 from sans.fit.Fitting import Fit 189 fitter = Fit('scipy') 209 190 fitter.set_data(data1,1,qmin=0, qmax=7) 210 191 fitter.set_model(model,1,pars1) … … 236 217 self.assertAlmostEquals( result1.stderr[0],result2.stderr[0] ) 237 218 self.assertAlmostEquals( result1.stderr[1],result2.stderr[1] ) 238 #self.assertAlmostEquals( result1.fitness,result2.fitness ) 239 self.assertTrue( result1.fitness/len(data1.x) < 2 ) 240 self.assertTrue( result2.fitness/len(data2.x) < 2 ) 219 self.assertTrue( result2.fitness/(len(data2.x)+len(data1.x)) < 2 ) 241 220 242 221
Note: See TracChangeset
for help on using the changeset viewer.