1 | """ |
---|
2 | Unit tests for fitting module |
---|
3 | """ |
---|
4 | import unittest |
---|
5 | from sans.guitools.plottables import Theory1D |
---|
6 | from sans.guitools.plottables import Data1D |
---|
7 | from sans.fit.AbstractFitEngine import Data,Model |
---|
8 | import math |
---|
9 | class testFitModule(unittest.TestCase): |
---|
10 | """ test fitting """ |
---|
11 | def test_cylinder_park(self): |
---|
12 | """ test fitting large model with park""" |
---|
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 | data11 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
19 | load.load_data(data11) |
---|
20 | data1=Data(sans_data=data11) |
---|
21 | |
---|
22 | |
---|
23 | #Importing the Fit module |
---|
24 | from sans.fit.Fitting import Fit |
---|
25 | fitter= Fit('park') |
---|
26 | |
---|
27 | # Receives the type of model for the fitting |
---|
28 | from sans.models.CylinderModel import CylinderModel |
---|
29 | model1 = CylinderModel() |
---|
30 | model =Model(model1) |
---|
31 | |
---|
32 | #Do the fit SCIPY |
---|
33 | |
---|
34 | import math |
---|
35 | #pars1=['background','contrast', 'length'] |
---|
36 | pars1=['background','contrast',\ |
---|
37 | 'cyl_phi','cyl_theta','length','radius','scale'] |
---|
38 | pars1.sort() |
---|
39 | fitter.set_model(model,"M1",1,pars1) |
---|
40 | fitter.set_data(data1,1) |
---|
41 | |
---|
42 | result=fitter.fit() |
---|
43 | print "park",result.fitness,result.cov, result.pvec |
---|
44 | self.assert_(result.fitness) |
---|
45 | |
---|
46 | |
---|
47 | def test_cylinder_scipy(self): |
---|
48 | """ test fitting large model with scipy""" |
---|
49 | #load data |
---|
50 | from sans.fit.Loader import Load |
---|
51 | load= Load() |
---|
52 | load.set_filename("cyl_testdata.txt") |
---|
53 | load.set_values() |
---|
54 | data11 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
55 | load.load_data(data11) |
---|
56 | data1=Data(sans_data=data11) |
---|
57 | |
---|
58 | |
---|
59 | #Importing the Fit module |
---|
60 | from sans.fit.Fitting import Fit |
---|
61 | fitter= Fit('scipy') |
---|
62 | |
---|
63 | # Receives the type of model for the fitting |
---|
64 | from sans.models.CylinderModel import CylinderModel |
---|
65 | model1 = CylinderModel() |
---|
66 | model =Model(model1) |
---|
67 | |
---|
68 | #Do the fit SCIPY |
---|
69 | fitter.set_data(data1,1) |
---|
70 | import math |
---|
71 | #pars1=['background','contrast', 'length'] |
---|
72 | pars1=['background','contrast',\ |
---|
73 | 'cyl_phi','cyl_theta','length','radius','scale'] |
---|
74 | pars1.sort() |
---|
75 | fitter.set_model(model,"M1",1,pars1) |
---|
76 | fitter.set_data(data1,1) |
---|
77 | |
---|
78 | result=fitter.fit() |
---|
79 | print "scipy",result.fitness,result.cov, result.pvec |
---|
80 | self.assert_(result.fitness) |
---|
81 | |
---|
82 | |
---|