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 | |
---|
12 | def testfit_1Data_1Model(self): |
---|
13 | """ test fitting for one data and one model park vs scipy""" |
---|
14 | #load data |
---|
15 | from sans.fit.Loader import Load |
---|
16 | load= Load() |
---|
17 | load.set_filename("testdata_line.txt") |
---|
18 | load.set_values() |
---|
19 | data11 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
20 | load.load_data(data11) |
---|
21 | |
---|
22 | #Importing the Fit module |
---|
23 | from sans.fit.Fitting import Fit |
---|
24 | fitter= Fit('park') |
---|
25 | |
---|
26 | # Receives the type of model for the fitting |
---|
27 | from sans.guitools.LineModel import LineModel |
---|
28 | model1 = LineModel() |
---|
29 | data1=Data(sans_data=data11) |
---|
30 | model =Model(model1) |
---|
31 | #Do the fit SCIPY |
---|
32 | |
---|
33 | fitter.set_data(data1,1) |
---|
34 | fitter.set_model(model,"M1",1,['A','B']) |
---|
35 | |
---|
36 | result=fitter.fit() |
---|
37 | print "park",result.pvec, |
---|
38 | |
---|
39 | self.assert_(result) |
---|
40 | |
---|
41 | def test_cylinder_scipy(self): |
---|
42 | """ test fitting large model with scipy""" |
---|
43 | #load data |
---|
44 | from sans.fit.Loader import Load |
---|
45 | load= Load() |
---|
46 | load.set_filename("cyl_testdata.txt") |
---|
47 | load.set_values() |
---|
48 | data11 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
49 | load.load_data(data11) |
---|
50 | data1=Data(sans_data=data11) |
---|
51 | |
---|
52 | |
---|
53 | #Importing the Fit module |
---|
54 | from sans.fit.Fitting import Fit |
---|
55 | fitter= Fit('park') |
---|
56 | |
---|
57 | # Receives the type of model for the fitting |
---|
58 | from sans.models.CylinderModel import CylinderModel |
---|
59 | model1 = CylinderModel() |
---|
60 | model =Model(model1) |
---|
61 | |
---|
62 | #Do the fit SCIPY |
---|
63 | fitter.set_data(data1,1) |
---|
64 | import math |
---|
65 | pars1=['background','contrast', 'length'] |
---|
66 | #pars1=['background','contrast',\ |
---|
67 | # 'cyl_phi','cyl_theta','length','radius','scale'] |
---|
68 | pars1.sort() |
---|
69 | fitter.set_model(model,"M1",1,pars1) |
---|
70 | fitter.set_data(data1,1) |
---|
71 | |
---|
72 | result=fitter.fit() |
---|
73 | print "park",result.fitness,result.cov, result.pvec |
---|
74 | self.assert_(result.fitness) |
---|
75 | |
---|
76 | |
---|
77 | |
---|